625
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
1 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
2 |
# hudson runs this from the raptor/util/install-linux directory
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
3 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
4 |
import datetime
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
5 |
import os
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
6 |
import re
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
7 |
import shutil
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
8 |
import subprocess
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
9 |
import sys
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
10 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
11 |
# run "hg id" to get the current branch name and tip changeset
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
12 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
13 |
hgid = subprocess.Popen(["hg", "id"], stdout=subprocess.PIPE)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
14 |
stdout = hgid.communicate()[0]
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
15 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
16 |
if hgid.returncode == 0 and len(stdout) >= 12:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
17 |
changeset = stdout[0:12]
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
18 |
print "CHANGESET", changeset
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
19 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
20 |
prototype = ("wip" in stdout or "fix" in stdout)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
21 |
print "PROTOTYPE", prototype
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
22 |
else:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
23 |
sys.stderr.write("error: failed to get tip mercurial changeset.\n")
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
24 |
sys.exit(1)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
25 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
26 |
# get today's date in ISO format YYYY-MM-DD
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
27 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
28 |
today = datetime.date.today().isoformat()
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
29 |
print "DATE", today
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
30 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
31 |
# insert the date and changeset into the raptor_version.py file
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
32 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
33 |
filename = "../../python/raptor_version.py"
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
34 |
lines = []
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
35 |
try:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
36 |
file = open(filename, "r")
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
37 |
for line in file.readlines():
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
38 |
if "ISODATE" in line and "CHANGESET" in line:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
39 |
line = line.replace("ISODATE", today)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
40 |
line = line.replace("CHANGESET", changeset)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
41 |
if prototype:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
42 |
line = line.replace("system", "system PROTOTYPE")
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
43 |
lines.append(line)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
44 |
else:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
45 |
lines.append(line)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
46 |
except IOError, ex:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
47 |
sys.stderr.write("error: failed to read file '%s'\n%s" % (filename, str(ex)))
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
48 |
sys.exit(1)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
49 |
finally:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
50 |
file.close()
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
51 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
52 |
# ... and write the modified raptor_version.py file
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
53 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
54 |
try:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
55 |
file = open(filename, "w")
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
56 |
for line in lines:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
57 |
file.write(line)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
58 |
except IOError, ex:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
59 |
sys.stderr.write("error: failed to write file '%s'\n%s" % (filename, str(ex)))
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
60 |
sys.exit(1)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
61 |
finally:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
62 |
file.close()
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
63 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
64 |
# check that we really did change the raptor version string
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
65 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
66 |
sbs_v = subprocess.Popen(["../../bin/sbs", "-v"], stdout=subprocess.PIPE)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
67 |
version = sbs_v.communicate()[0]
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
68 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
69 |
if sbs_v.returncode == 0:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
70 |
print "VERSION", version
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
71 |
if not today in version or not changeset in version:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
72 |
sys.stderr.write("error: date or changeset does not match the sbs version.\n")
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
73 |
sys.exit(1)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
74 |
if prototype and not "PROTOTYPE" in version:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
75 |
sys.stderr.write("error: the sbs version should be marked PROTOTYPE.\n")
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
76 |
sys.exit(1)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
77 |
else:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
78 |
sys.stderr.write("error: failed to get sbs version.\n")
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
79 |
sys.exit(1)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
80 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
81 |
# run the Linux installer maker script
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
82 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
83 |
package_sbs = subprocess.Popen(["./package_sbs.sh", "-s"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
84 |
(stdout, stderr) = package_sbs.communicate()
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
85 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
86 |
if package_sbs.returncode != 0:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
87 |
sys.stderr.write("error: failed to create linux package of sbs.\n")
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
88 |
sys.exit(1)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
89 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
90 |
# find the name of the archive in /tmp
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
91 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
92 |
match = re.search('archive "([^"]+)" successfully created', stdout)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
93 |
if match:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
94 |
tmp_archive = "/tmp/" + match.group(1)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
95 |
print "TMP ARCHIVE", tmp_archive
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
96 |
else:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
97 |
sys.stderr.write("error: failed to find linux archive file.\n")
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
98 |
sys.exit(1)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
99 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
100 |
# move it to the WORKSPACE root
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
101 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
102 |
if 'WORKSPACE' in os.environ:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
103 |
name = re.sub(r'/tmp/(sbs-\d+\.\d+\.\d+-).*', r'\1', tmp_archive)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
104 |
if prototype:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
105 |
fullname = name + "PROTOTYPE-" + changeset + ".run"
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
106 |
else:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
107 |
fullname = name + changeset + ".run"
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
108 |
final_archive = os.path.join(os.environ['WORKSPACE'], fullname)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
109 |
print "WORKSPACE ARCHIVE", final_archive
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
110 |
else:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
111 |
sys.stderr.write("error: no WORKSPACE is set.\n")
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
112 |
sys.exit(1)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
113 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
114 |
try:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
115 |
shutil.move(tmp_archive, final_archive)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
116 |
except Error, err:
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
117 |
sys.stderr.write("error: could not rename '%s' as '%s'.\n" % (tmp_archive, final_archive))
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
118 |
sys.exit(1)
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
119 |
|
Richard Taylor <richard.i.taylor@nokia.com>
parents:
diff
changeset
|
120 |
# the end
|