summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorBen Brown <ben.brown@codethink.co.uk>2016-03-04 12:32:17 (GMT)
committerBen Brown <ben.brown@codethink.co.uk>2016-03-04 13:52:53 (GMT)
commitf94f0330eb1d4011868910a0f7234559e48ceff7 (patch)
treef12095e1b6e9b2ded6f0d19d0a3ac50cd53cfecf /scripts
parenta6652bf61c4f4042e1d001ed9715b0857dbc792f (diff)
downloaddefinitions-f94f0330eb1d4011868910a0f7234559e48ceff7.tar.gz
Add small python library for common(ish) code in scripts/
Change-Id: I74ab24ecdcda1c358a2c187f89685bdd8f949c55
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/check-unpetrify-refs.py32
-rwxr-xr-xscripts/licensecheck.py19
-rwxr-xr-xscripts/organize-morphologies.py15
-rw-r--r--scripts/scriptslib.py45
4 files changed, 58 insertions, 53 deletions
diff --git a/scripts/check-unpetrify-refs.py b/scripts/check-unpetrify-refs.py
index 27792c4..36eaa2d 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 "
diff --git a/scripts/licensecheck.py b/scripts/licensecheck.py
index 4b255dc..59125ea 100755
--- a/scripts/licensecheck.py
+++ b/scripts/licensecheck.py
@@ -23,7 +23,8 @@ import string
import subprocess
import sys
import tempfile
-import yaml
+
+import scriptslib
gpl3_chunks = ("autoconf",
@@ -51,16 +52,6 @@ gpl3_chunks = ("autoconf",
"texinfo-tarball")
-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 license_file_name(repo_name, sha, licenses_dir):
license_file = os.path.join(licenses_dir, repo_name + '-' + sha)
return license_file
@@ -126,7 +117,7 @@ def check_repo_if_needed(name, repo, ref, repos_dir, licenses_dir):
def check_stratum(stratum_file, repos_dir, licenses_dir):
- stratum = load_yaml_file(stratum_file)
+ stratum = scriptslib.load_yaml_file(stratum_file)
license_files = []
for chunk in stratum['chunks']:
@@ -154,11 +145,11 @@ def main():
args = parser.parse_args()
- system = load_yaml_file(args.system)
+ system = scriptslib.load_yaml_file(args.system)
license_files = []
for stratum in system['strata']:
stratum_file = stratum['morph']
- stratum_path = os.path.join(definitions_root(), stratum_file)
+ stratum_path = os.path.join(scriptslib.definitions_root(), stratum_file)
license_files.extend(check_stratum(stratum_path, args.repos_dir, args.licenses_dir))
for chunk_repo, chunk_license in license_files:
diff --git a/scripts/organize-morphologies.py b/scripts/organize-morphologies.py
index abc8c73..3072c8f 100755
--- a/scripts/organize-morphologies.py
+++ b/scripts/organize-morphologies.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-# Copyright (C) 2014 Codethink Limited
+# Copyright (C) 2014-2016 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -42,17 +42,6 @@ which has been moved.
'''
-# NOTE: The following reimplements part of morphlib's remote repo cache stuff
-def parse_repo_alias(repo):
- domain, path = repo.split(':')
- if domain == 'baserock':
- repo = 'ssh://git@git.baserock.org/baserock/%s' % path
- elif domain == 'upstream':
- repo = 'ssh://git@git.baserock.org/delta/%s' % path
- else:
- raise Exception("I don't know how to parse the repo-alias \"%s\"" % repo)
- return repo
-
def make_request(path):
server_url = 'http://git.baserock.org:8080/'
url = urlparse.urljoin(server_url, '/1.0/%s' % path)
@@ -206,7 +195,7 @@ def download_chunks(morph, loader):
else:
raise err
ref = chunk['ref']
- repo = parse_repo_alias(chunk['repo'])
+ repo = scriptslib.parse_repo_alias(chunk['repo'])
try:
print "\nDownloading %s from %s into %s" %(name, repo, chunk['morph'])
chunk_str = cat_file(repo, ref, name)
diff --git a/scripts/scriptslib.py b/scripts/scriptslib.py
new file mode 100644
index 0000000..68470c2
--- /dev/null
+++ b/scripts/scriptslib.py
@@ -0,0 +1,45 @@
+# Copyright (C) 2016 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+# Small library of useful things for the scripts that live here.
+
+import yaml
+import subprocess
+
+
+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 parse_repo_alias(repo, trove_host='git.baserock.org'):
+ global aliases
+ remote = repo[:repo.find(':') + 1]
+ aliases = {k: v % {'trove': trove_host} for k, v in aliases.iteritems()}
+ try:
+ return repo.replace(remote, aliases[remote])
+ except KeyError as e:
+ raise Exception("Unknown repo-alias \"%s\"" % repo)
+
+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)