sbsv2/raptor/util/install-windows/hudson.py
changeset 625 a1925fb7753a
equal deleted inserted replaced
624:f70b728ea30c 625:a1925fb7753a
       
     1 
       
     2 # hudson runs this from the raptor/util/install-windows directory
       
     3 
       
     4 import os
       
     5 import re
       
     6 import shutil
       
     7 import subprocess
       
     8 import sys
       
     9 
       
    10 # run "hg id" to get the current branch name and tip changeset
       
    11 
       
    12 hgid = subprocess.Popen(["hg", "id"], stdout=subprocess.PIPE)
       
    13 stdout = hgid.communicate()[0]
       
    14 
       
    15 if hgid.returncode == 0 and len(stdout) >= 12:
       
    16 	changeset = stdout[0:12]
       
    17 	print "CHANGESET", changeset
       
    18 
       
    19 	prototype = ("wip" in stdout or "fix" in stdout)
       
    20 	print "PROTOTYPE", prototype
       
    21 else:
       
    22 	sys.stderr.write("error: failed to get tip mercurial changeset.\n")
       
    23 	sys.exit(1)
       
    24 
       
    25 # get the raptor version string
       
    26 
       
    27 sbs_v = subprocess.Popen(["../../bin/sbs", "-v"], stdout=subprocess.PIPE)
       
    28 version = sbs_v.communicate()[0]
       
    29 
       
    30 if sbs_v.returncode == 0:
       
    31 	print "VERSION", version
       
    32 	if not changeset in version:
       
    33 		sys.stderr.write("error: changeset does not match the sbs version.\n")
       
    34 		sys.exit(1)
       
    35         if prototype and not "PROTOTYPE" in version:
       
    36 		sys.stderr.write("error: the sbs version should be marked PROTOTYPE.\n")
       
    37 		sys.exit(1)
       
    38 else:
       
    39 	sys.stderr.write("error: failed to get sbs version.\n")
       
    40 	sys.exit(1)
       
    41 
       
    42 # find the SBS_HOME and WIN32_SUPPORT
       
    43 
       
    44 if 'SBS_HOME' in os.environ:
       
    45 	sbs_home = os.environ['SBS_HOME']
       
    46 else:
       
    47 	sys.stderr.write("error: no SBS_HOME is set.\n")
       
    48 	sys.exit(1)
       
    49 
       
    50 if 'WIN32_SUPPORT' in os.environ:
       
    51 	win32_support = os.environ['WIN32_SUPPORT']
       
    52 else:
       
    53 	sys.stderr.write("error: no WIN32_SUPPORT is set.\n")
       
    54 	sys.exit(1)
       
    55 
       
    56 # run the Windows installer maker script
       
    57 
       
    58 if prototype:
       
    59 	postfix = "-PROTOTYPE-" + changeset
       
    60 else:
       
    61 	postfix = "-" + changeset
       
    62 
       
    63 package_sbs = subprocess.Popen(["python", "raptorinstallermaker.py",
       
    64                                 "-s", sbs_home, "-w", win32_support,
       
    65                                 "--postfix=" + postfix],
       
    66                                 stdout=subprocess.PIPE) #, stderr=subprocess.PIPE)
       
    67 (stdout, stderr) = package_sbs.communicate()
       
    68 
       
    69 if package_sbs.returncode == 0:
       
    70 	match = re.search('Output: "([^"]+)"', stdout)
       
    71 	zip_match = re.search('Zipoutput: "([^"]+)"', stdout)
       
    72 	if match:
       
    73 		tmp_archive = match.group(1)
       
    74 		print "TMP ARCHIVE", tmp_archive
       
    75 	else:
       
    76 		sys.stderr.write("error: failed to find packaged filename.\n")
       
    77 		sys.exit(1)
       
    78 	
       
    79 	if zip_match:
       
    80 		tmp_zip_archive = zip_match.group(1)
       
    81 		print "TMP ZIP ARCHIVE", tmp_zip_archive
       
    82 	else:
       
    83 		sys.stderr.write("error: failed to find zip filename.\n")
       
    84 		sys.exit(1)
       
    85 else:
       
    86 	sys.stderr.write("error: failed to create windows package of sbs.\n")
       
    87 	sys.exit(1)
       
    88 
       
    89 # move the results to WORKSPACE
       
    90 
       
    91 if 'WORKSPACE' in os.environ:
       
    92 	final_archive = os.path.join(os.environ['WORKSPACE'], os.path.basename(tmp_archive))
       
    93 	final_zip_archive = os.path.join(os.environ['WORKSPACE'], os.path.basename(tmp_zip_archive))
       
    94 	print "WORKSPACE ARCHIVE", final_archive
       
    95 	print "WORKSPACE ZIP ARCHIVE", final_zip_archive
       
    96 else:
       
    97 	sys.stderr.write("error: no WORKSPACE is set.\n")
       
    98 	sys.exit(1)
       
    99 
       
   100 try:
       
   101 	shutil.move(tmp_archive, final_archive)
       
   102 except Error, err:
       
   103 	sys.stderr.write("error: could not rename '%s' as '%s'.\n" % (tmp_archive, final_archive))
       
   104 	sys.exit(1)
       
   105 
       
   106 try:
       
   107 	shutil.move(tmp_zip_archive, final_zip_archive)
       
   108 except Error, err:
       
   109 	sys.stderr.write("error: could not rename '%s' as '%s'.\n" % (tmp_zip_archive, final_zip_archive))
       
   110 	sys.exit(1)
       
   111 
       
   112 # the end