diff options
author | Ben Brown <ben.brown@codethink.co.uk> | 2016-03-04 12:32:17 +0000 |
---|---|---|
committer | Ben Brown <ben.brown@codethink.co.uk> | 2016-03-04 13:52:53 +0000 |
commit | f94f0330eb1d4011868910a0f7234559e48ceff7 (patch) | |
tree | f12095e1b6e9b2ded6f0d19d0a3ac50cd53cfecf /scripts/scriptslib.py | |
parent | a6652bf61c4f4042e1d001ed9715b0857dbc792f (diff) | |
download | definitions-f94f0330eb1d4011868910a0f7234559e48ceff7.tar.gz |
Add small python library for common(ish) code in scripts/
Change-Id: I74ab24ecdcda1c358a2c187f89685bdd8f949c55
Diffstat (limited to 'scripts/scriptslib.py')
-rw-r--r-- | scripts/scriptslib.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/scripts/scriptslib.py b/scripts/scriptslib.py new file mode 100644 index 00000000..68470c28 --- /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) |