diff options
| author | Quentin Young <qlyoung@cumulusnetworks.com> | 2016-10-25 00:29:25 +0000 |
|---|---|---|
| committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2016-10-25 00:29:25 +0000 |
| commit | 55bdefacac374c0c592f420c20caba4c27a3cc66 (patch) | |
| tree | 67c7f1016f28285a90903b4db01e99f3652edb5f | |
| parent | 71f11720efcb373d5ce312c9b7fb988405b2e97b (diff) | |
tools: cmd_check.py checks headers too
Sometimes commands are externed and installed in another
file, so check for a command's name in the header file
corresponding to the file it's defined in before marking
it uninstalled.
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
| -rwxr-xr-x[-rw-r--r--] | tools/cmd_check.py | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/tools/cmd_check.py b/tools/cmd_check.py index ccfb2964bb..3a402138bd 100644..100755 --- a/tools/cmd_check.py +++ b/tools/cmd_check.py @@ -8,36 +8,52 @@ import re import os from pprint import pprint -# searching regex -search = [ +# patterns used to extract commands +command_patterns = [ r'DEF.*\(.*\n\s*(.*_cmd)', r'ALIAS.*\(.*\n\s*(.*_cmd)', ] +# patterns that count as installing the command +install_patterns = [ + r'install_element.*\(.*{0}', + r'INSTALL.*\(.*{0}' +] + def process(filename): cmds = [] - notinstalled = [] + uninstalled = [] + sourcetext = '' + headertext = '' + + # read source file and header file with open(filename) as cf: try: - tf = cf.read() + sourcetext = cf.read() + if os.path.isfile(filename.replace('.c', '.h')): + with open(filename) as hf: + headertext = hf.read() except: print('Error reading {0}, skipping'.format(filename)) return - # build list of defined commands - for expression in search: - for match in re.findall(expression, tf, re.M): + + # build list of defined commands that aren't mentioned in header + for pattern in command_patterns: + for match in re.findall(pattern, sourcetext, re.M): + if re.search(match, headertext) is None: cmds.append(match) - # build list of not installed commands - notinstalled = filter( - lambda x: len(re.findall('install_element.*\(.*{0}'.format(x), tf, re.M)) == 0, - cmds) - notinstalled = list(notinstalled) - if len(notinstalled) > 0: + # build list of not installed commands + for cmd in cmds: + pats = [ ip.format(cmd) for ip in install_patterns ] + if not any([ re.search(pat, sourcetext) is not None for pat in pats ]): + uninstalled.append(cmd) + + if len(uninstalled) > 0: print('\033[92m', end='') print('{0}'.format(filename)) print('\033[0m', end='') - for cmd in notinstalled: + for cmd in uninstalled: print(' {0}'.format(cmd)) print('') |
