|
@@ -13,9 +13,9 @@ practracker.py should be run with its second argument pointing to the Tor
|
|
|
top-level source directory like this:
|
|
|
$ python3 ./scripts/maint/practracker/practracker.py .
|
|
|
|
|
|
-The exceptions file is meant to be initialized once with the current state of
|
|
|
-the source code and then get saved in the repository for ever after:
|
|
|
- $ python3 ./scripts/maint/practracker/practracker.py . > ./scripts/maint/practracker/exceptions.txt
|
|
|
+To regenerate the exceptions file so that it allows all current
|
|
|
+problems in the Tor source, use the --regen flag:
|
|
|
+ $ python3 --regen ./scripts/maint/practracker/practracker.py .
|
|
|
"""
|
|
|
|
|
|
from __future__ import print_function
|
|
@@ -120,14 +120,59 @@ def consider_metrics_for_file(fname, f):
|
|
|
|
|
|
return found_new_issues
|
|
|
|
|
|
-def main():
|
|
|
- if (len(sys.argv) != 2):
|
|
|
- print("Usage:\n\t$ practracker.py <tor topdir>\n\t(e.g. $ practracker.py ~/tor/)")
|
|
|
- return
|
|
|
+HEADER="""\
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+""".format(**globals())
|
|
|
+
|
|
|
+def main(argv):
|
|
|
+ import argparse
|
|
|
+
|
|
|
+ progname = argv[0]
|
|
|
+ parser = argparse.ArgumentParser(prog=progname)
|
|
|
+ parser.add_argument("--regen", action="store_true",
|
|
|
+ help="Regenerate the exceptions file")
|
|
|
+ parser.add_argument("--exceptions",
|
|
|
+ help="Override the location for the exceptions file")
|
|
|
+ parser.add_argument("topdir", default=".", nargs="?",
|
|
|
+ help="Top-level directory for the tor source")
|
|
|
+ args = parser.parse_args(argv[1:])
|
|
|
|
|
|
global TOR_TOPDIR
|
|
|
- TOR_TOPDIR = sys.argv[1]
|
|
|
- exceptions_file = os.path.join(TOR_TOPDIR, "scripts/maint/practracker", EXCEPTIONS_FNAME)
|
|
|
+ TOR_TOPDIR = args.topdir
|
|
|
+ if args.exceptions:
|
|
|
+ exceptions_file = args.exceptions
|
|
|
+ else:
|
|
|
+ exceptions_file = os.path.join(TOR_TOPDIR, "scripts/maint/practracker", EXCEPTIONS_FNAME)
|
|
|
|
|
|
|
|
|
files_list = util.get_tor_c_files(TOR_TOPDIR)
|
|
@@ -135,13 +180,26 @@ def main():
|
|
|
|
|
|
|
|
|
global ProblemVault
|
|
|
- ProblemVault = problem.ProblemVault(exceptions_file)
|
|
|
+
|
|
|
+ if args.regen:
|
|
|
+ tmpname = exceptions_file + ".tmp"
|
|
|
+ tmpfile = open(tmpname, "w")
|
|
|
+ sys.stdout = tmpfile
|
|
|
+ sys.stdout.write(HEADER)
|
|
|
+ ProblemVault = problem.ProblemVault()
|
|
|
+ else:
|
|
|
+ ProblemVault = problem.ProblemVault(exceptions_file)
|
|
|
|
|
|
|
|
|
found_new_issues = consider_all_metrics(files_list)
|
|
|
|
|
|
+ if args.regen:
|
|
|
+ tmpfile.close()
|
|
|
+ os.rename(tmpname, exceptions_file)
|
|
|
+ sys.exit(0)
|
|
|
+
|
|
|
|
|
|
- if (found_new_issues):
|
|
|
+ if found_new_issues and not args.regen:
|
|
|
new_issues_str = """\
|
|
|
FAILURE: practracker found new problems in the code: see warnings above.
|
|
|
|
|
@@ -155,4 +213,4 @@ See doc/HACKING/HelpfulTools.md for more information on using practracker.\
|
|
|
sys.exit(found_new_issues)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
- main()
|
|
|
+ main(sys.argv)
|