converge.py
2.46 KB
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
from datetime import date
import subprocess
import time
import os
import sys
#Needs future lib: pip install future
import concurrent.futures
#Needs git python: pip install gitpython
import git
#Get current dir
os.chdir(os.path.dirname(os.path.abspath(sys.argv[0])))
SRC_PATH = os.path.abspath(os.path.join(os.getcwd(), os.pardir))
SPB_PATH = os.path.abspath(os.path.join(SRC_PATH, os.pardir))
SPB_ENV = 'local'
today = str(date.today())
BUILDS = []
BUILD_COUNT = 0
buildDict = dict()
spb_repo = git.Git(SPB_PATH)
print('Using git stash to save your local changes before converging')
spb_repo.stash('save')
print('Trying to checkout from current branch to master')
spb_repo.checkout('master')
spb_repo.pull()
def checkBuildStatus(packageName,buildId):
buildStatus = str(subprocess.check_output(['copr-cli', 'status', buildId])).rstrip()
while buildStatus not in ('succeeded', 'failed'):
buildStatus = str(subprocess.check_output(['copr-cli', 'status', buildId])).rstrip()
print('Currently running build for %s with id %s, build status is: %s'% (packageName,buildId,buildStatus))
time.sleep(30)
print('%s build with id %s exited with status: %s'% (packageName,buildId,buildStatus))
with open(today+'_log', 'a+') as f:
f.write('%s build with id %s exited with status: %s\n'% (packageName,buildId,buildStatus))
if(buildStatus == 'succeeded'):
return 0
else:
return 1
pluginsUpload = subprocess.Popen('make release_plugins', shell=True, cwd=SRC_PATH)
pluginsUpload.wait()
noosferoUpload = subprocess.Popen('make noosfero-upload', shell=True, cwd=SRC_PATH)
noosferoUpload.wait()
colabUpload = subprocess.Popen('make colab-upload', shell=True, cwd=SRC_PATH)
colabUpload.wait()
with open(today+'.yaml') as f:
BUILD_COUNT = sum(1 for _ in f)
with open(today+'.yaml') as f:
BUILDS = f.read().splitlines()[-5:]
for build in BUILDS:
package, buildId = build.strip().split(':')
buildDict.update({package : buildId})
with concurrent.futures.ThreadPoolExecutor(max_workers=BUILD_COUNT) as executor:
future_builds = {executor.submit(checkBuildStatus,packageName,buildId) for packageName, buildId in buildDict.iteritems()}
for build in concurrent.futures.as_completed(future_builds):
status = build.result()
if(status != 0):
sys.exit('One of the packages failed to build, aborting converge, check the log file')
else:
print('All builds are ok, proceding to converge')
spbConverge = subprocess.Popen(['rake converge SPB_ENV='+SPB_ENV], shell=True, cwd=SPB_PATH)
spbConverge.wait()