From f94f0330eb1d4011868910a0f7234559e48ceff7 Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Fri, 4 Mar 2016 12:32:17 +0000 Subject: Add small python library for common(ish) code in scripts/ Change-Id: I74ab24ecdcda1c358a2c187f89685bdd8f949c55 --- scripts/check-unpetrify-refs.py | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) (limited to 'scripts/check-unpetrify-refs.py') diff --git a/scripts/check-unpetrify-refs.py b/scripts/check-unpetrify-refs.py index 27792c4a..36eaa2d7 100755 --- a/scripts/check-unpetrify-refs.py +++ b/scripts/check-unpetrify-refs.py @@ -17,9 +17,10 @@ import os import sys import glob -import yaml import subprocess +import scriptslib + ''' Script for checking unpetrify-refs in strata. @@ -32,13 +33,6 @@ a missing or non-existent unpetrify-ref and if it fails to check the remote strata_dir = "strata" trove_host = "git.baserock.org" -aliases = { - 'baserock:': 'git://%(trove)s/baserock/', - 'freedesktop:': 'git://anongit.freedesktop.org/', - 'github:': 'git://github.com/', - 'gnome:': 'git://git.gnome.org/', - 'upstream:': 'git://%(trove)s/delta/' -} def ref_exists(remote, ref): output = subprocess.check_output( @@ -46,43 +40,29 @@ def ref_exists(remote, ref): stderr=subprocess.STDOUT).strip() return True if output else False -def get_repo_url(repo): - remote = repo[:repo.find(':') + 1] - return repo.replace(remote, aliases[remote]) - -def definitions_root(): - return subprocess.check_output( - ["git", "rev-parse", "--show-toplevel"]).strip() - -def load_yaml_file(yaml_file): - with open(yaml_file, 'r') as f: - return yaml.safe_load(f) - def main(args): - global trove_host, aliases + 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]] - aliases = {k: v % {'trove': trove_host} for k, v in aliases.iteritems()} - if args: strata = args else: - strata_path = os.path.join(definitions_root(), strata_dir) + strata_path = os.path.join(scriptslib.definitions_root(), strata_dir) strata = glob.glob("%s/*.morph" % strata_path) for stratum in strata: path = os.path.relpath(stratum) - morphology = load_yaml_file(stratum) + morphology = scriptslib.load_yaml_file(stratum) for chunk in morphology['chunks']: unpetrify_ref = chunk.get("unpetrify-ref") if not unpetrify_ref: print ("%s: '%s' has no unpetrify-ref!" % (path, chunk['name'])) continue - remote = get_repo_url(chunk['repo']) + remote = scriptslib.parse_repo_alias(chunk['repo'], trove_host) try: if not ref_exists(remote, unpetrify_ref): print ("%s: unpetrify-ref for '%s' is not present on the " -- cgit v1.2.1