genconfig: simplify argument parsing

Split the arguments into var=val once at startup and put them in a dict.

Change-Id: Ic6b337e010a185448c1dab20659575081f03a645
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
Daniel Verkamp 2016-11-30 10:04:14 -07:00 committed by Ben Walker
parent 051b059e26
commit 1e9c049638

View File

@ -6,6 +6,14 @@ import sys
comment = re.compile('^\s*#') comment = re.compile('^\s*#')
assign = re.compile('^\s*([a-zA-Z_]+)\s*(\?)?=\s*([^#]*)') assign = re.compile('^\s*([a-zA-Z_]+)\s*(\?)?=\s*([^#]*)')
args = {}
for arg in sys.argv:
m = assign.match(arg)
if m:
var = m.group(1).strip()
val = m.group(3).strip()
args[var] = val
with open('CONFIG') as f: with open('CONFIG') as f:
for line in f: for line in f:
line = line.strip() line = line.strip()
@ -15,13 +23,8 @@ with open('CONFIG') as f:
var = m.group(1).strip() var = m.group(1).strip()
default = m.group(3).strip() default = m.group(3).strip()
val = default val = default
for arg in sys.argv: if var in args:
m = assign.match(arg) val = args[var]
if m:
argvar = m.group(1).strip()
argval = m.group(3).strip()
if argvar == var:
val = argval
if default.lower() == 'y' or default.lower() == 'n': if default.lower() == 'y' or default.lower() == 'n':
if val.lower() == 'y': if val.lower() == 'y':
print "#define SPDK_{} 1".format(var) print "#define SPDK_{} 1".format(var)