blob: 0b3833f2cfa505fded1187904b4e0c5e017e06c4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#!/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)
|