def consider_file_size(fname, f):
"""Consider file size issues for 'f' and return the number of new issues was found"""
file_size = metrics.get_file_len(f)
+
if file_size > MAX_FILE_SIZE:
p = problem.FileSizeProblem(fname, file_size)
if ProblemVault.register_problem(p):
parser = argparse.ArgumentParser(prog=progname)
parser.add_argument("--regen", action="store_true",
help="Regenerate the exceptions file")
+ parser.add_argument("--list-overstrict", action="store_true",
+ help="List over-strict exceptions")
parser.add_argument("--exceptions",
help="Override the location for the exceptions file")
parser.add_argument("topdir", default=".", nargs="?",
""".format(found_new_issues, exceptions_file)
print(new_issues_str)
+ if args.list_overstrict:
+ def k_fn(tup):
+ return tup[0].key()
+ for (ex,p) in sorted(ProblemVault.list_overstrict_exceptions(), key=k_fn):
+ if p is None:
+ print(ex, "->", 0)
+ else:
+ print(ex, "->", p.metric_value)
+
sys.exit(found_new_issues)
if __name__ == '__main__':
def __init__(self, exception_fname=None):
# Exception dictionary: { problem.key() : Problem object }
self.exceptions = {}
+ # Exception dictionary: maps key to the problem it was used to
+ # suppress.
+ self.used_exception_for = {}
if exception_fname == None:
return
if problem.is_worse_than(self.exceptions[problem.key()]):
print(problem)
return True
+ else:
+ self.used_exception_for[problem.key()] = problem
return False
+ def list_overstrict_exceptions(self):
+ """Return an iterator of tuples containing (ex,prob) where ex is an
+ exceptions in this vault that are stricter than it needs to be, and
+ prob is the worst problem (if any) that it covered.
+ """
+ for k in self.exceptions:
+ e = self.exceptions[k]
+ p = self.used_exception_for.get(k)
+ if p is None or e.is_worse_than(p):
+ yield (e, p)
+
+
class Problem(object):
"""
A generic problem in our source code. See the subclasses below for the