numam-spdk/scripts/genconfig.py
James Bergsten 0c93fc7330 scripts:Fix Python errors in checking scripts
Python3 (3.6.7) gives W605 errors in regular expressions, causing the
SPDK style checks to fail on the Python scripts doing the style checking.

This fix allows these Python scripts to run without errors.

This is a known issue - see https://github.com/PyCQA/pycodestyle/issues/814

Change-Id: I71cdff5d6c89e19b200c989f3d9da35bb4f7189d
Signed-off-by: James Bergsten <jamesx.bergsten@intel.com>
Reviewed-on: https://review.gerrithub.io/c/443955
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-by: Karol Latecki <karol.latecki@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
2019-02-12 18:37:09 +00:00

47 lines
1.3 KiB
Python
Executable File

#!/usr/bin/env python3
import os
import re
import sys
comment = re.compile(r'^\s*#')
assign = re.compile(r'^\s*([a-zA-Z_]+)\s*(\?)?=\s*([^#]*)')
args = os.environ.copy()
for arg in sys.argv:
m = assign.match(arg)
if m:
var = m.group(1).strip()
val = m.group(3).strip()
args[var] = val
defs = {}
try:
with open("mk/config.mk") as f:
for line in f:
line = line.strip()
if not comment.match(line):
m = assign.match(line)
if m:
var = m.group(1).strip()
default = m.group(3).strip()
val = default
if var in args:
val = args[var]
if default.lower() == 'y' or default.lower() == 'n':
if val.lower() == 'y':
defs["SPDK_{0}".format(var)] = 1
else:
defs["SPDK_{0}".format(var)] = 0
else:
strval = val.replace('"', '\"')
defs["SPDK_{0}".format(var)] = strval
except IOError:
print("mk/config.mk not found")
for key, value in sorted(defs.items()):
if value == 0:
print("#undef {0}".format(key))
else:
print("#define {0} {1}".format(key, value))