diff options
Diffstat (limited to 'test/CheckComments.py')
-rw-r--r-- | test/CheckComments.py | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/test/CheckComments.py b/test/CheckComments.py index 446137b0..9bcfcbb3 100644 --- a/test/CheckComments.py +++ b/test/CheckComments.py @@ -1,20 +1,19 @@ +#!/usr/bin/env python3 + import sys import re import os +import argparse -ok = 100.0 -if sys.argv[1] == '-l': - ok = float(sys.argv[2]) - sys.argv = [sys.argv[0]] + sys.argv[3:] - -debug = False -if sys.argv[1] == '-v': - debug = True - sys.argv = [sys.argv[0]] + sys.argv[2:] +parser = argparse.ArgumentParser( prog='CheckComments') +parser.add_argument('-v', '--debug', dest='debug', action='store_true') +parser.add_argument('-l', '--limit', dest='ok', type=float, default=100.0) +parser.add_argument('path', nargs='+', help='Path to source file to check comments') +args = parser.parse_args() errors = 0 -for path in sys.argv[1:]: +for path in args.path: other_depth = 0 brace_depth = 0 code_count = 0 @@ -26,6 +25,7 @@ for path in sys.argv[1:]: ctor_dtor = False linenum = 0 + print(f'checking {path}') fd = open(path, 'r') for line in fd.readlines(): linenum += 1 @@ -48,48 +48,48 @@ for path in sys.argv[1:]: match = re.search('(namespace|enum|class|struct|union)', line) if match: kind = match.group(1) - if debug: print "kind =", kind + if args.debug: print("kind =", kind) elif kind == "function": match = re.search('(\S+)\(', line) if match: function_name = match.group(1) long_comments[function_name] = comment_count comment_count = 0 - if debug: print "name found %s" % function_name + if args.debug: print("name found %s" % function_name) if re.search('{', line) and not re.search('@{', line): if kind == "function": brace_depth += 1 - if debug: print "brace_depth =", brace_depth + if args.debug: print("brace_depth =", brace_depth) else: other_depth += 1 kind = "function" - if debug: print "other_depth =", other_depth + if args.debug: print("other_depth =", other_depth) if re.search('}', line) and not re.search('@}', line): if brace_depth > 0: brace_depth -= 1 - if debug: print "brace_depth =", brace_depth + if args.debug: print("brace_depth =", brace_depth) if brace_depth == 0: - if debug: print "function done" + if args.debug: print("function done") if function_name in long_comments: comment_count += long_comments[function_name] if code_count == 0: - percent = ok - print "%7s %4d/%4d %s:%d: %s" % \ + percent = args.ok + print("%7s %4d/%4d %s:%d: %s" % \ ("empty", comment_count, code_count, os.path.basename(path), linenum, - function_name) + function_name)) errors += 1 else: percent = 100.0 * (float(comment_count) / float(code_count)) - if percent < ok and not ctor_dtor: - print "%6.0f%% %4d/%4d %s:%d: %s" % \ + if percent < args.ok and not ctor_dtor: + print("%6.0f%% %4d/%4d %s:%d: %s" % \ (percent, comment_count, code_count, os.path.basename(path), linenum, - function_name) + function_name)) errors += 1 code_count = 0 comment_count = 0 @@ -98,7 +98,7 @@ for path in sys.argv[1:]: ctor_dtor = False else: other_depth -= 1 - if debug: print "other_depth =", other_depth + if args.debug: print("other_depth =", other_depth) if brace_depth > 0: if re.search("TRACE_[CD]TOR", line): |