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/scriptslib.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 scripts/scriptslib.py (limited to 'scripts/scriptslib.py') 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) -- cgit v1.2.1