From f7f583f0c5ed026086a71d603b5e208364db03e5 Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Fri, 4 Mar 2016 12:44:34 +0000 Subject: Make use of argparse in check-unpetrify-refs.py Change-Id: I60f8e45073b1268b31d4654b2ab8b6342fa1d6e1 --- scripts/check-unpetrify-refs.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/scripts/check-unpetrify-refs.py b/scripts/check-unpetrify-refs.py index 36eaa2d7..c70b680d 100755 --- a/scripts/check-unpetrify-refs.py +++ b/scripts/check-unpetrify-refs.py @@ -15,8 +15,8 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import os -import sys import glob +import argparse import subprocess import scriptslib @@ -32,7 +32,6 @@ a missing or non-existent unpetrify-ref and if it fails to check the remote ''' strata_dir = "strata" -trove_host = "git.baserock.org" def ref_exists(remote, ref): output = subprocess.check_output( @@ -40,15 +39,17 @@ def ref_exists(remote, ref): stderr=subprocess.STDOUT).strip() return True if output else False -def main(args): - global trove_host - opt = next(((i, j.split('=')[1]) for i, j in enumerate(args) - if j.startswith("--trove-host=")), None) - if opt: - trove_host = opt[1] - del args[opt[0]] - if args: - strata = args +def main(): + parser = argparse.ArgumentParser( + description="Sanity checks unpetrify-refs in Baserock strata") + parser.add_argument("--trove-host", default="git.baserock.org", + help="Trove host to map repo aliases to") + parser.add_argument("strata", nargs="*", metavar="STRATA", + help="The strata to check (checks all by default)") + args = parser.parse_args() + + if args.strata: + strata = args.strata else: strata_path = os.path.join(scriptslib.definitions_root(), strata_dir) strata = glob.glob("%s/*.morph" % strata_path) @@ -62,7 +63,7 @@ def main(args): print ("%s: '%s' has no unpetrify-ref!" % (path, chunk['name'])) continue - remote = scriptslib.parse_repo_alias(chunk['repo'], trove_host) + remote = scriptslib.parse_repo_alias(chunk['repo'], args.trove_host) try: if not ref_exists(remote, unpetrify_ref): print ("%s: unpetrify-ref for '%s' is not present on the " @@ -72,4 +73,4 @@ def main(args): (path, remote, chunk['name'], e.output.strip())) if __name__ == "__main__": - main(sys.argv[1:]) + main() -- cgit v1.2.1