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/fixup-deprecated.py | |
| parent | bd407b54d26981f30a95bc316ea2ed965d070c53 (diff) | |
*: reformat python files
We are now using black.
Signed-off-by: Quentin Young <qlyoung@nvidia.com>
Diffstat (limited to 'tools/fixup-deprecated.py')
| -rwxr-xr-x | tools/fixup-deprecated.py | 66 | 
1 files changed, 46 insertions, 20 deletions
diff --git a/tools/fixup-deprecated.py b/tools/fixup-deprecated.py index 38958480a8..57f9df9065 100755 --- a/tools/fixup-deprecated.py +++ b/tools/fixup-deprecated.py @@ -8,48 +8,74 @@  import sys, re, subprocess, os +  class replaceEntry: -    compiled = None    #compiled regex -    repl    = None     #regex +    compiled = None  # compiled regex +    repl = None  # regex +      def __init__(self, c, r):          self.compiled = c          self.repl = r +  rList = [      # old #define VNL, VTYNL, VTY_NEWLINE -    replaceEntry(re.compile(r'(VNL|VTYNL|VTY_NEWLINE)'), -                 r'"\\n"'), +    replaceEntry(re.compile(r"(VNL|VTYNL|VTY_NEWLINE)"), r'"\\n"'),      # old #define VTY_GET_INTEGER(desc, v, str)      # old #define VTY_GET_INTEGER_RANGE(desc, v, str, min, max)      # old #define VTY_GET_ULONG(desc, v, str) -    replaceEntry(re.compile(r'(VTY_GET_INTEGER(_RANGE|)|VTY_GET_ULONG)[\s\(]*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)(\s*|)(\)|,).*?;', re.M | re.S), -                 r'(\4) = strtoul((\5), NULL, 10);\t/* \3 */'), +    replaceEntry( +        re.compile( +            r"(VTY_GET_INTEGER(_RANGE|)|VTY_GET_ULONG)[\s\(]*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)(\s*|)(\)|,).*?;", +            re.M | re.S, +        ), +        r"(\4) = strtoul((\5), NULL, 10);\t/* \3 */", +    ),      # old #define VTY_GET_ULL(desc, v, str) -    replaceEntry(re.compile(r'VTY_GET_ULL[\s\(]*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)(\s*|)(\)|,).*?;', re.M | re.S), -                 r'(\2) = strtoull((\3), NULL, 10);\t/* \1 */'), +    replaceEntry( +        re.compile( +            r"VTY_GET_ULL[\s\(]*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)(\s*|)(\)|,).*?;", +            re.M | re.S, +        ), +        r"(\2) = strtoull((\3), NULL, 10);\t/* \1 */", +    ),      # old #define VTY_GET_IPV4_ADDRESS(desc, v, str) -    replaceEntry(re.compile(r'VTY_GET_IPV4_ADDRESS[\s\(]*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)(\s*|)(\)|,).*?;', re.M | re.S), -                 r'inet_aton((\3), &(\2));\t/* \1 */'), +    replaceEntry( +        re.compile( +            r"VTY_GET_IPV4_ADDRESS[\s\(]*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)(\s*|)(\)|,).*?;", +            re.M | re.S, +        ), +        r"inet_aton((\3), &(\2));\t/* \1 */", +    ),      # old #define VTY_GET_IPV4_PREFIX(desc, v, str) -    replaceEntry(re.compile(r'VTY_GET_IPV4_PREFIX[\s\(]*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)(\s*|)(\)|,).*?;', re.M | re.S), -                 r'str2prefix_ipv4((\3), &(\2));\t/* \1 */'), +    replaceEntry( +        re.compile( +            r"VTY_GET_IPV4_PREFIX[\s\(]*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)(\s*|)(\)|,).*?;", +            re.M | re.S, +        ), +        r"str2prefix_ipv4((\3), &(\2));\t/* \1 */", +    ),      # old #define vty_outln(vty, str, ...) -    replaceEntry(re.compile(r'vty_outln[\s\(]*(.*?)\s*,\s*(".*?"|.*?)\s*(\)|,)', re.M | re.S), -                 r'vty_out(\1, \2 "\\n"\3'), -        ] +    replaceEntry( +        re.compile(r'vty_outln[\s\(]*(.*?)\s*,\s*(".*?"|.*?)\s*(\)|,)', re.M | re.S), +        r'vty_out(\1, \2 "\\n"\3', +    ), +] +  def fixup_file(fn): -    with open(fn, 'r') as fd: +    with open(fn, "r") as fd:          text = fd.read()          for re in rList: -            text = re.compiled.sub(re.repl,text) +            text = re.compiled.sub(re.repl, text) -        tmpname = fn + '.fixup' -        with open(tmpname, 'w') as ofd: +        tmpname = fn + ".fixup" +        with open(tmpname, "w") as ofd:              ofd.write(text)          os.rename(tmpname, fn) -if __name__ == '__main__': + +if __name__ == "__main__":      for fn in sys.argv[1:]:          fixup_file(fn)  | 
