summaryrefslogtreecommitdiffstatshomepage
path: root/py/makeqstrdefs.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2020-02-27 15:36:53 +1100
committerDamien George <damien.p.george@gmail.com>2020-02-28 10:33:03 +1100
commit69661f3343bedf86e514337cff63d96cc42f8859 (patch)
treeaf5dfb380ffdb75dda84828f63cf9d840d992f0f /py/makeqstrdefs.py
parent3f39d18c2b884d32f0443e2e8114ff9d7a14d718 (diff)
downloadmicropython-69661f3343bedf86e514337cff63d96cc42f8859.tar.gz
micropython-69661f3343bedf86e514337cff63d96cc42f8859.zip
all: Reformat C and Python source code with tools/codeformat.py.
This is run with uncrustify 0.70.1, and black 19.10b0.
Diffstat (limited to 'py/makeqstrdefs.py')
-rw-r--r--py/makeqstrdefs.py17
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":