scripts: python: cleanup script and fix PEP8 issues
Ran scripts through flake8 and fixed issues.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
diff --git a/scripts/process_gperf.py b/scripts/process_gperf.py
index 3388722..9abf564 100755
--- a/scripts/process_gperf.py
+++ b/scripts/process_gperf.py
@@ -25,6 +25,7 @@
This saves a considerable amount of space.
"""
+
def debug(text):
if not args.verbose:
return
@@ -37,7 +38,12 @@
def warn(text):
- sys.stdout.write(os.path.basename(sys.argv[0]) + " WARNING: " + text + "\n")
+ sys.stdout.write(
+ os.path.basename(
+ sys.argv[0]) +
+ " WARNING: " +
+ text +
+ "\n")
def reformat_str(match_obj):
@@ -54,14 +60,14 @@
break
if addr_str[i] == "\\":
- if addr_str[i+1].isdigit():
+ if addr_str[i + 1].isdigit():
# Octal escape sequence
- val_str = addr_str[i+1:i+4]
+ val_str = addr_str[i + 1:i + 4]
addr_vals[ctr] = int(val_str, 8)
i += 4
else:
# Char value that had to be escaped by C string rules
- addr_vals[ctr] = ord(addr_str[i+1])
+ addr_vals[ctr] = ord(addr_str[i + 1])
i += 2
else:
@@ -72,6 +78,7 @@
return "(char *)0x%02x%02x%02x%02x" % tuple(addr_vals)
+
def process_line(line, fp):
if line.startswith("#"):
fp.write(line)
@@ -90,7 +97,7 @@
v_hi = LooseVersion("3.1")
if (v < v_lo or v > v_hi):
warn("gperf %s is not tested, versions %s through %s supported" %
- (v, v_lo, v_hi))
+ (v, v_lo, v_hi))
# Replace length lookups with constant len of 4 since we're always
# looking at pointers
@@ -110,7 +117,7 @@
# Hashing the address of the string
line = re.sub(r"hash [(]str, len[)]",
- r"hash((const char *)&str, len)", line)
+ r"hash((const char *)&str, len)", line)
# Just compare pointers directly instead of using memcmp
if re.search("if [(][*]str", line):
@@ -123,18 +130,20 @@
fp.write(line)
+
def parse_args():
global args
- parser = argparse.ArgumentParser(description = __doc__,
- formatter_class = argparse.RawDescriptionHelpFormatter)
+ parser = argparse.ArgumentParser(
+ description=__doc__,
+ formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument("-i", "--input", required=True,
- help="Input C file from gperf")
+ help="Input C file from gperf")
parser.add_argument("-o", "--output", required=True,
- help="Output C file with processing done")
+ help="Output C file with processing done")
parser.add_argument("-v", "--verbose", action="store_true",
- help="Print extra debugging information")
+ help="Print extra debugging information")
args = parser.parse_args()