diff options
| author | whitespace <nobody@nobody> | 2020-10-07 17:22:26 -0400 |
|---|---|---|
| committer | Quentin Young <qlyoung@nvidia.com> | 2020-10-07 17:22:26 -0400 |
| commit | 701a01920eee5431d2052aad92aefbdf50ac2139 (patch) | |
| tree | 2bf2339327241f59593b9583b060ebb347db1cea /tools/stringmangle.py | |
| parent | bd407b54d26981f30a95bc316ea2ed965d070c53 (diff) | |
*: reformat python files
We are now using black.
Signed-off-by: Quentin Young <qlyoung@nvidia.com>
Diffstat (limited to 'tools/stringmangle.py')
| -rw-r--r-- | tools/stringmangle.py | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/tools/stringmangle.py b/tools/stringmangle.py index a2eb37336a..1c75c86a0d 100644 --- a/tools/stringmangle.py +++ b/tools/stringmangle.py @@ -6,23 +6,24 @@ import re import argparse wrap_res = [ - (re.compile(r'(?<!\\n)"\s*\n\s*"', re.M), r''), + (re.compile(r'(?<!\\n)"\s*\n\s*"', re.M), r""), ] pri_res = [ - (re.compile(r'(PRI[udx][0-9]+)\s*\n\s*"', re.M), r'\1"'), - (re.compile(r'"\s*PRI([udx])32\s*"'), r'\1'), - (re.compile(r'"\s*PRI([udx])32'), r'\1"'), - (re.compile(r'"\s*PRI([udx])16\s*"'), r'h\1'), - (re.compile(r'"\s*PRI([udx])16'), r'h\1"'), - (re.compile(r'"\s*PRI([udx])8\s*"'), r'hh\1'), - (re.compile(r'"\s*PRI([udx])8'), r'hh\1"'), + (re.compile(r'(PRI[udx][0-9]+)\s*\n\s*"', re.M), r'\1"'), + (re.compile(r'"\s*PRI([udx])32\s*"'), r"\1"), + (re.compile(r'"\s*PRI([udx])32'), r'\1"'), + (re.compile(r'"\s*PRI([udx])16\s*"'), r"h\1"), + (re.compile(r'"\s*PRI([udx])16'), r'h\1"'), + (re.compile(r'"\s*PRI([udx])8\s*"'), r"hh\1"), + (re.compile(r'"\s*PRI([udx])8'), r'hh\1"'), ] + def main(): - argp = argparse.ArgumentParser(description = 'C string mangler') - argp.add_argument('--unwrap', action = 'store_const', const = True) - argp.add_argument('--pri8-16-32', action = 'store_const', const = True) - argp.add_argument('files', type = str, nargs = '+') + argp = argparse.ArgumentParser(description="C string mangler") + argp.add_argument("--unwrap", action="store_const", const=True) + argp.add_argument("--pri8-16-32", action="store_const", const=True) + argp.add_argument("files", type=str, nargs="+") args = argp.parse_args() regexes = [] @@ -31,14 +32,14 @@ def main(): if args.pri8_16_32: regexes.extend(pri_res) if len(regexes) == 0: - sys.stderr.write('no action selected to execute\n') + sys.stderr.write("no action selected to execute\n") sys.exit(1) l = 0 for fn in args.files: - sys.stderr.write(fn + '\033[K\r') - with open(fn, 'r') as ifd: + sys.stderr.write(fn + "\033[K\r") + with open(fn, "r") as ifd: data = ifd.read() newdata = data @@ -48,12 +49,13 @@ def main(): n += m if n > 0: - sys.stderr.write('changed: %s\n' % fn) - with open(fn + '.new', 'w') as ofd: + sys.stderr.write("changed: %s\n" % fn) + with open(fn + ".new", "w") as ofd: ofd.write(newdata) - os.rename(fn + '.new', fn) + os.rename(fn + ".new", fn) l += 1 - sys.stderr.write('%d files changed.\n' % (l)) + sys.stderr.write("%d files changed.\n" % (l)) + main() |
