# 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)