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