diff options
Diffstat (limited to 'py/makeqstrdefs.py')
-rw-r--r-- | py/makeqstrdefs.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/py/makeqstrdefs.py b/py/makeqstrdefs.py index 209e7a132d..03ea1afc79 100644 --- a/py/makeqstrdefs.py +++ b/py/makeqstrdefs.py @@ -20,16 +20,17 @@ def write_out(fname, output): with open(args.output_dir + "/" + fname + ".qstr", "w") as f: f.write("\n".join(output) + "\n") + def process_file(f): re_line = re.compile(r"#[line]*\s\d+\s\"([^\"]+)\"") - re_qstr = re.compile(r'MP_QSTR_[_a-zA-Z0-9]+') + re_qstr = re.compile(r"MP_QSTR_[_a-zA-Z0-9]+") output = [] last_fname = None for line in f: if line.isspace(): continue # match gcc-like output (# n "file") and msvc-like output (#line n "file") - if line.startswith(('# ', '#line')): + if line.startswith(("# ", "#line")): m = re_line.match(line) assert m is not None fname = m.group(1) @@ -41,8 +42,8 @@ def process_file(f): last_fname = fname continue for match in re_qstr.findall(line): - name = match.replace('MP_QSTR_', '') - output.append('Q(' + name + ')') + name = match.replace("MP_QSTR_", "") + output.append("Q(" + name + ")") write_out(last_fname, output) return "" @@ -51,6 +52,7 @@ def process_file(f): def cat_together(): import glob import hashlib + hasher = hashlib.md5() all_lines = [] outf = open(args.output_dir + "/out", "wb") @@ -64,7 +66,7 @@ def cat_together(): outf.close() hasher.update(all_lines) new_hash = hasher.hexdigest() - #print(new_hash) + # print(new_hash) old_hash = None try: with open(args.output_file + ".hash") as f: @@ -87,11 +89,12 @@ def cat_together(): if __name__ == "__main__": if len(sys.argv) != 5: - print('usage: %s command input_filename output_dir output_file' % sys.argv[0]) + print("usage: %s command input_filename output_dir output_file" % sys.argv[0]) sys.exit(2) class Args: pass + args = Args() args.command = sys.argv[1] args.input_filename = sys.argv[2] @@ -104,7 +107,7 @@ if __name__ == "__main__": pass if args.command == "split": - with io.open(args.input_filename, encoding='utf-8') as infile: + with io.open(args.input_filename, encoding="utf-8") as infile: process_file(infile) if args.command == "cat": |