]>
Commit | Line | Data |
---|---|---|
010bf6f1 DL |
1 | #!/usr/bin/env python3 |
2 | # | |
3 | # Quick demo program that checks whether files define commands that aren't | |
4 | # in vtysh. Execute after building. | |
5 | # | |
6 | # This is free and unencumbered software released into the public domain. | |
7 | # | |
8 | # Anyone is free to copy, modify, publish, use, compile, sell, or | |
9 | # distribute this software, either in source code form or as a compiled | |
10 | # binary, for any purpose, commercial or non-commercial, and by any | |
11 | # means. | |
12 | # | |
13 | # In jurisdictions that recognize copyright laws, the author or authors | |
14 | # of this software dedicate any and all copyright interest in the | |
15 | # software to the public domain. We make this dedication for the benefit | |
16 | # of the public at large and to the detriment of our heirs and | |
17 | # successors. We intend this dedication to be an overt act of | |
18 | # relinquishment in perpetuity of all present and future rights to this | |
19 | # software under copyright law. | |
20 | # | |
21 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
22 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
23 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
24 | # IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | |
25 | # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
26 | # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
27 | # OTHER DEALINGS IN THE SOFTWARE. | |
28 | # | |
29 | # For more information, please refer to <http://unlicense.org/> | |
30 | ||
31 | import os | |
32 | import json | |
33 | import subprocess | |
34 | ||
35 | os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
36 | ||
37 | with open("frr.xref", "r") as fd: | |
38 | data = json.load(fd) | |
39 | ||
40 | vtysh_scan, _ = subprocess.Popen( | |
41 | ["make", "var-vtysh_scan"], stdout=subprocess.PIPE | |
42 | ).communicate() | |
43 | vtysh_scan = set(vtysh_scan.decode("US-ASCII").split()) | |
44 | ||
45 | check = set() | |
46 | vtysh = {} | |
47 | ||
48 | for cmd, defs in data["cli"].items(): | |
49 | for binary, clidef in defs.items(): | |
50 | if clidef["defun"]["file"].startswith("vtysh/"): | |
51 | vtysh[clidef["string"]] = clidef | |
52 | ||
53 | for cmd, defs in data["cli"].items(): | |
54 | for binary, clidef in defs.items(): | |
55 | if clidef["defun"]["file"].startswith("vtysh/"): | |
56 | continue | |
57 | ||
58 | if clidef["defun"]["file"] not in vtysh_scan: | |
59 | vtysh_def = vtysh.get(clidef["string"]) | |
60 | if vtysh_def is not None: | |
61 | print( | |
62 | "\033[33m%s defines %s, has a custom define in vtysh %s\033[m" | |
63 | % (clidef["defun"]["file"], cmd, vtysh_def["defun"]["file"]) | |
64 | ) | |
65 | else: | |
66 | print( | |
67 | "\033[31m%s defines %s, not in vtysh_scan\033[m" | |
68 | % (clidef["defun"]["file"], cmd) | |
69 | ) | |
70 | check.add(clidef["defun"]["file"]) | |
71 | ||
72 | print("\nfiles to check:\n\t" + " ".join(sorted(check))) |