#!/usr/bin/python from __future__ import print_function """\ Script to generate a bash script from .travis.yml CI recipe Once this script is on your PATH, use it like this:: $ cd my-project $ bash <(travis-extract) Any improvement is welcome. """ __author__ = "Jan Pokorny" __license__ = "GPLv2" import yaml from os.path import abspath from sys import stderr from subprocess import call shellcall = lambda *args, **kws: call(*args, **(dict(shell=True, **kws))) errprint = lambda *args, **kws: print(*args, **(dict(file=stderr, **kws))) # if system == 'Fedora' ... REPODATA = True REPODATA_CMD = "rpm -qa --filesbypkg | grep -q '/%s$'" REPODATA_GLOBAL = True REPODATA_GLOBAL_CMD = "repoquery -qf '*/%s' >&2" class TravisRunError(Exception): pass with open(abspath(".travis.yml")) as yaml_file: try: data = yaml.load(yaml_file) if 'script' not in data: raise TravisRunError("no script, sorry") print("#!/bin/bash") for i, cmd in enumerate(data['script']): if REPODATA: cmd_base = cmd[:cmd.find(' ')] if shellcall(REPODATA_CMD % cmd_base) != 0: errprint("missing `%s' command%s" % (cmd_base, REPODATA_GLOBAL and ", searching it..." or "")) if REPODATA_GLOBAL \ and shellcall(REPODATA_GLOBAL_CMD % cmd_base) != 0: errprint("sorry, `%s' command too special" % cmd_base) print("#%02d\n%s" % (i + 1, cmd)) except TravisRunError as e: errprint(e)