-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparams.py
43 lines (38 loc) · 1.26 KB
/
params.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from sys import argv
import sys, re
progName = "()"
if len(argv):
progName = argv[0]
del argv[0]
switchesVarDefaults = ()
def parseParams(_switchesVarDefaults):
global switchesVarDefaults
paramMap = {}
switchesVarDefaults = _switchesVarDefaults
swVarDefaultMap = {} # map from cmd switch to param var name
for switches, param, default in switchesVarDefaults:
for sw in switches:
swVarDefaultMap[sw] = (param, default)
paramMap[param] = default # set default values
try:
while len(argv):
sw = argv[0]; del argv[0]
paramVar, defaultVal = swVarDefaultMap[sw]
if (defaultVal):
val = argv[0]; del argv[0]
paramMap[paramVar] = val
else:
paramMap[paramVar] = True
except Exception as e:
print "Problem parsing parameters (exception=%s)" % e
usage()
return paramMap
def usage():
print "%s usage:" % progName
for switches, param, default in switchesVarDefaults:
for sw in switches:
if default:
print " [%s %s] (default = %s)" % (sw, param, default)
else:
print " [%s] (%s if present)" % (sw, param)
sys.exit(1)