-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-repo.py
executable file
·105 lines (90 loc) · 2.81 KB
/
build-repo.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
#!/usr/bin/env python2
import ConfigParser
import subprocess
import os
import logging
import sys
from contextlib import contextmanager
from glob import glob
DRY_RUN = False
RELEASE_FILE = "release"
tito_config = ConfigParser.RawConfigParser()
tito_config.read('.tito/releasers.conf')
logging.basicConfig(level=logging.INFO)
def log_command(cmd):
logging.info("Executing [%s] in path [%s]" %(cmd, os.getcwd()))
def check_call(cmd):
log_command(cmd)
if not DRY_RUN:
subprocess.check_call(cmd, shell=True)
else:
logging.debug("Not Executing due to DRY RUN")
def call(cmd):
log_command(cmd)
if not DRY_RUN:
return subprocess.call(cmd, shell=True)
else:
logging.debug("Not Executing due to DRY RUN")
return 0
@contextmanager
def cd(path):
prevdir = os.getcwd()
os.chdir(os.path.expanduser(path))
try:
yield
finally:
os.chdir(prevdir)
# Returns the builds that succeeded
def try_build(release_target, paths):
good = set()
test = ""
if release_target.endswith("-test") or release_target.endswith("-test-src"):
test = "--test"
for path in paths:
logging.info("Building specs in %s" %(path))
with cd(path):
tito_cmd = "tito release %s %s" %(test, release_target)
result = call(tito_cmd)
if result == 0:
good.add(path)
return good
def clear_bucket(s3bucket):
# Clear folder if it exists
check_cmd = "s3cmd info %s" %(s3bucket)
check_result = call(check_cmd)
if(check_result == 12):
pass
elif(check_result == 0):
clear_cmd = "s3cmd del -r %s" %(s3bucket)
check_call(clear_cmd)
else:
raise Exception('Unknown bucket status')
def create_index(s3bucket):
# Create the initial index
index_upload_cmd = "s3cmd put index.html %s" %(s3bucket)
check_call(index_upload_cmd)
def do_release(release_target, path):
logging.info("Release target: %s" %(release_target))
# get bucket we are going to clear
s3bucket = tito_config.get(release_target,'s3cmd')
clear_bucket(s3bucket)
create_index(s3bucket)
src_paths = set(glob(path + '/*/'))
while True:
logging.info("Attempting another round of builds")
good_builds = try_build(release_target, src_paths)
src_paths -= good_builds
if len(good_builds) == 0 or len(src_paths) == 0:
break
def release_repo(path, release_targets=[]):
if not release_targets:
expected_release_file = os.path.join(path, RELEASE_FILE)
if not os.path.isfile(expected_release_file):
raise RuntimeError("No %s file found at path %s" % (RELEASE_FILE, path))
release_targets = [line.rstrip('\n') for line in open(expected_release_file)]
logging.info("In directory %s using the following release targets %s" % (path, release_targets))
for release_target in release_targets:
do_release(release_target, path)
if __name__ == "__main__":
path = sys.argv[1]
release_repo(path, sys.argv[2:])