]> git.proxmox.com Git - mirror_frr.git/blobdiff - tools/stringmangle.py
Merge pull request #8890 from rameshabhinay/ospf6_auth_trailer
[mirror_frr.git] / tools / stringmangle.py
index a2eb37336a70cc27ae2dd720dab7dc330ced439b..1c75c86a0d7abbf19efbd54d4e09484db1877a1e 100644 (file)
@@ -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()