mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-24 04:13:28 +01:00
Practracker: add a --list-overstrict option
This option lists every exception that is stricter than it needs to be. Part of 30752
This commit is contained in:
parent
78768aafe1
commit
a5e1fa3a03
@ -56,6 +56,7 @@ else:
|
||||
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):
|
||||
@ -164,6 +165,8 @@ def main(argv):
|
||||
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="?",
|
||||
@ -213,6 +216,15 @@ See doc/HACKING/HelpfulTools.md for more information on using practracker.\
|
||||
""".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__':
|
||||
|
@ -22,6 +22,9 @@ class ProblemVault(object):
|
||||
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
|
||||
@ -71,9 +74,23 @@ class ProblemVault(object):
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user