]> git.proxmox.com Git - mirror_frr.git/blob - tools/fixup-deprecated.py
Merge pull request #4885 from satheeshkarra/pim_mlag
[mirror_frr.git] / tools / fixup-deprecated.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # Script used to replace deprecated quagga/frr mactors/types/etc.
5 #
6 # loosly based on indent.py, 2017 by David Lamparter
7 # 2018 by Lou Berger, placed in public domain
8
9 import sys, re, subprocess, os
10
11 class replaceEntry:
12 compiled = None #compiled regex
13 repl = None #regex
14 def __init__(self, c, r):
15 self.compiled = c
16 self.repl = r
17
18 rList = [
19 # old #define VNL, VTYNL, VTY_NEWLINE
20 replaceEntry(re.compile(r'(VNL|VTYNL|VTY_NEWLINE)'),
21 r'"\\n"'),
22 # old #define VTY_GET_INTEGER(desc, v, str)
23 # old #define VTY_GET_INTEGER_RANGE(desc, v, str, min, max)
24 # old #define VTY_GET_ULONG(desc, v, str)
25 replaceEntry(re.compile(r'(VTY_GET_INTEGER(_RANGE|)|VTY_GET_ULONG)[\s\(]*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)(\s*|)(\)|,).*?;', re.M | re.S),
26 r'(\4) = strtoul((\5), NULL, 10);\t/* \3 */'),
27 # old #define VTY_GET_ULL(desc, v, str)
28 replaceEntry(re.compile(r'VTY_GET_ULL[\s\(]*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)(\s*|)(\)|,).*?;', re.M | re.S),
29 r'(\2) = strtoull((\3), NULL, 10);\t/* \1 */'),
30 # old #define VTY_GET_IPV4_ADDRESS(desc, v, str)
31 replaceEntry(re.compile(r'VTY_GET_IPV4_ADDRESS[\s\(]*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)(\s*|)(\)|,).*?;', re.M | re.S),
32 r'inet_aton((\3), &(\2));\t/* \1 */'),
33 # old #define VTY_GET_IPV4_PREFIX(desc, v, str)
34 replaceEntry(re.compile(r'VTY_GET_IPV4_PREFIX[\s\(]*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)(\s*|)(\)|,).*?;', re.M | re.S),
35 r'str2prefix_ipv4((\3), &(\2));\t/* \1 */'),
36 # old #define vty_outln(vty, str, ...)
37 replaceEntry(re.compile(r'vty_outln[\s\(]*(.*?)\s*,\s*(".*?"|.*?)\s*(\)|,)', re.M | re.S),
38 r'vty_out(\1, \2 "\\n"\3'),
39 ]
40
41 def fixup_file(fn):
42 with open(fn, 'r') as fd:
43 text = fd.read()
44
45 for re in rList:
46 text = re.compiled.sub(re.repl,text)
47
48 tmpname = fn + '.fixup'
49 with open(tmpname, 'w') as ofd:
50 ofd.write(text)
51 os.rename(tmpname, fn)
52
53 if __name__ == '__main__':
54 for fn in sys.argv[1:]:
55 fixup_file(fn)