-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrigger_travis.py
executable file
·111 lines (97 loc) · 3.05 KB
/
trigger_travis.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env python2.7
__author__ = 'Bjoern Riemer <bjoern.riemer@tu-berlin.de>'
__copyright__ = "2015 Bjoern Riemer. TUB"
__licence__ = "GPL"
__version__ = 0.1
from travispy import TravisPy
import yaml
import os.path,sys
verbose = True
def read_config(filename):
with open(filename, 'r') as ymlfile:
config = yaml.load(ymlfile)
return config
def old_logic(gh_token):
t = TravisPy.github_auth(gh_token)
user = t.user()
repos = t.repos(member=user.login)
print "found", len(repos), "repositories:"
for r in repos:
print r.slug
repo = t.repo('FITeagle/integration-test')
branch_bin = t.branch(repo_id_or_slug=repo.slug,name='binary-only')
branch_master = t.branch(repo_id_or_slug=repo.slug,name='master')
print "bin:", branch_bin.repository_id, branch_bin.number
print "master:", branch_master.repository_id, branch_master.number
builds_master = t.builds(repository_id=branch_master.repository_id,number=branch_master.number)
builds_bin = t.builds(repository_id=branch_bin.repository_id,number=branch_bin.number)
print "Branch >>binary-only<< has", len(builds_bin), "Builds"
print "Branch >>master<< has", len(builds_master), "Builds"
build_master=builds_master[0]
build_bin=builds_bin[0]
#print "restarting >>binary-only<< build...", build_bin.restart()
#print "restarting >>master<< build...", build_master.restart()
def cfgExample():
cfgdata = {
'github_token':"1234567890123456789012345678901234567890",
'triggers':[{
"trigger_file":"/tmp/trigger.txt",
"delete_after":True,
"repositories":[{
"slug":"FITeagle/integration-test",
"branches":["master","binary-only"]
},
{
"slug":"FITeagle/core",
"branches":["master"]
}
]
},
{
"trigger_file":"/tmp/trigger_two.txt",
"delete_after":False,
"repositories":[{
"slug":"FITeagle/two",
"branches":["master"]
}]
}]
}
print yaml.dump(cfgdata)
try:
config = read_config(os.path.dirname(sys.argv[0])+"/trigger_travis.yaml")
except Exception, e:
print "can't open config file!\nCreate a file named >>trigger_travis.yaml<< with the following contens:"
cfgExample()
exit(1)
t=False
if len(config['triggers']):
for trigger in config['triggers']:
fname=trigger['trigger_file']
if verbose :
print "file:",fname,"delete:",trigger['delete_after'], "targets:", trigger['repositories']
if os.path.isfile(fname):
if not t:
t = TravisPy.github_auth(config['github_token'])
restart_ok = True
for r in trigger['repositories']:
repo = t.repo(r['slug'])
for bname in r['branches']:
branch = t.branch(repo_id_or_slug=repo.slug,name=bname)
build = t.builds(repository_id=branch.repository_id,number=branch.number)[0]
if verbose :
print "Restarting",repo.slug, "branch", bname, "Build..."
if build.restart():
if verbose :
print "OK"
else:
print "Restart of Build for",repo.slug, "branch", bname, "failed!"
restart_ok=False
try:
if trigger['delete_after']:
os.remove(fname)
except Exception, e:
print e
else:
if verbose :
print "nothing to do for",fname
pass