From: david-sarah Date: Sun, 9 Oct 2011 05:03:01 +0000 (+0000) Subject: check-miscaptures.py: report the number of files that were not analysed due to syntax... X-Git-Url: https://git.rkrishnan.org/?a=commitdiff_plain;h=4d6260d6ad5f54005a81727c432d409bb0791342;p=tahoe-lafs%2Ftahoe-lafs.git check-miscaptures.py: report the number of files that were not analysed due to syntax errors (and don't count them in the number of suspicious captures). refs #1555 --- diff --git a/misc/coding_tools/check-miscaptures.py b/misc/coding_tools/check-miscaptures.py index f2637f09..07b94a5b 100644 --- a/misc/coding_tools/check-miscaptures.py +++ b/misc/coding_tools/check-miscaptures.py @@ -14,7 +14,7 @@ def check_thing(parser, thing): try: ast = parser(thing) except SyntaxError, e: - return [e] + return e else: results = [] check_ast(ast, results) @@ -133,25 +133,27 @@ def make_result(funcnode, var_name, var_lineno): def report(out, path, results): for r in results: - if isinstance(r, SyntaxError): - print >>out, path + (" NOT ANALYSED due to syntax error: %s" % r) - else: - print >>out, path + (":%r %s captures %r assigned at line %d" % r) + print >>out, path + (":%r %s captures %r assigned at line %d" % r) def check(sources, out): class Counts: n = 0 processed_files = 0 suspect_files = 0 + error_files = 0 counts = Counts() def _process(path): results = check_file(path) - report(out, path, results) - counts.n += len(results) - counts.processed_files += 1 - if len(results) > 0: - counts.suspect_files += 1 + if isinstance(results, SyntaxError): + print >>out, path + (" NOT ANALYSED due to syntax error: %s" % results) + counts.error_files += 1 + else: + report(out, path, results) + counts.n += len(results) + counts.processed_files += 1 + if len(results) > 0: + counts.suspect_files += 1 for source in sources: print >>out, "Checking %s..." % (source,) @@ -164,8 +166,11 @@ def check(sources, out): if ext == '.py': _process(os.path.join(dirpath, fn)) - print >>out, ("%d suspiciously captured variables in %d out of %d files" + print >>out, ("%d suspiciously captured variables in %d out of %d file(s)." % (counts.n, counts.suspect_files, counts.processed_files)) + if counts.error_files > 0: + print >>out, ("%d file(s) not processed due to syntax errors." + % (counts.error_files,)) return counts.n