sbsv2/raptor/util/install-windows/raptorinstallermaker.py
branchwip
changeset 79 540de0f551cf
parent 3 e1eecf4d390d
child 142 26f2f0b4002b
equal deleted inserted replaced
78:796529273552 79:540de0f551cf
    28 import unzip
    28 import unzip
    29 
    29 
    30 tempdir = ""
    30 tempdir = ""
    31 
    31 
    32 parser = optparse.OptionParser()
    32 parser = optparse.OptionParser()
    33 parser.add_option("-s", "--sbs_home", dest="sbs_home",
    33 parser.add_option("-s", "--sbs-home", dest="sbshome",
       
    34                   help="Path to use as SBS_HOME environment variable. If not present the script exits.")
       
    35 parser.add_option("-w", "--win32-support", dest="win32support",
    34                   help="Path to use as SBS_HOME environment variable. If not present the script exits.")
    36                   help="Path to use as SBS_HOME environment variable. If not present the script exits.")
    35 
    37 
    36 (options, args) = parser.parse_args()
    38 (options, args) = parser.parse_args()
    37 
    39 
    38 if options.sbs_home == None:
    40 if options.sbshome == None:
    39 	print "ERROR: no SBS_HOME passed in. Exiting..."
    41 	print "ERROR: no SBS_HOME passed in. Exiting..."
    40 	sys.exit(2)
    42 	sys.exit(2)
    41 
    43 
       
    44 if options.win32support == None:
       
    45 	print "ERROR: no win32support directory specified. Unable to proceed. Exiting..."
       
    46 	sys.exit(2)
       
    47 else:
       
    48 	# Required irectories inside the win32-support repository
       
    49 	win32supportdirs = ["bv", "cygwin", "mingw", "python252"]
       
    50 	for dir in win32supportdirs:
       
    51 		if not os.path.isdir(os.path.join(options.win32support, dir)):
       
    52 			print "ERROR: directory %s does not exist. Cannot build installer. Exiting..."
       
    53 			sys.exit(2)
    42 
    54 
    43 def parseconfig(xmlFile="raptorinstallermaker.xml"):
    55 def parseconfig(xmlFile="raptorinstallermaker.xml"):
    44 	pass
    56 	pass
    45 
    57 
    46 def generateinstallerversionheader(sbs_home = None):
    58 def generateinstallerversionheader(sbshome = None):
    47 	os.environ["SBS_HOME"] = sbs_home
    59 	shellenv = os.environ.copy()
    48 	os.environ["PATH"] = os.path.join(os.environ["SBS_HOME"], "bin") + os.pathsep + os.environ["PATH"]
    60 	shellenv["PYTHONPATH"] = os.path.join(os.environ["SBS_HOME"], "python")
    49 	
    61 	
    50 	versioncommand = "sbs -v"
    62 	raptorversioncommand = "python -c \"import raptor_version; print raptor_version.numericversion()\""
    51 	
    63 	
    52 	# Raptor version string looks like this
    64 	# Raptor version is obtained from raptor_version module's numericversion function.
    53 	# sbs version 2.5.0 [2009-02-20 release]
       
    54 	sbs_version_matcher = re.compile(".*(\d+\.\d+\.\d+).*", re.I)
    65 	sbs_version_matcher = re.compile(".*(\d+\.\d+\.\d+).*", re.I)
    55 	
    66 	
    56 	# Create Raptor subprocess
    67 	# Create Raptor subprocess
    57 	sbs = subprocess.Popen(versioncommand, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    68 	versioncommand = subprocess.Popen(raptorversioncommand, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=shellenv)
    58 	
    69 	raptorversion = ""
    59 	# Get all the lines matching the RE
    70 	# Get all the lines matching the RE
    60 	for line in sbs.stdout.readlines():
    71 	for line in versioncommand.stdout.readlines():
    61 		res = sbs_version_matcher.match(line)
    72 		res = sbs_version_matcher.match(line)
    62 		if res:
    73 		if res:
    63 			raptorversion = res.group(1)
    74 			raptorversion = res.group(1)
    64 			print "Successfully determined Raptor version %s" % raptorversion
    75 			print "Successfully determined Raptor version %s" % raptorversion
    65 
    76 
    66 	sbs.wait() # Wait for process to end
    77 	versioncommand.wait() # Wait for process to end
    67 	
    78 	
    68 	raptorversion_nsis_header_string = "# Raptor version file\n\n!define RAPTOR_VERSION %s\n" % raptorversion
    79 	raptorversion_nsis_header_string = "# Raptor version file\n\n!define RAPTOR_VERSION %s\n" % raptorversion
    69 	
    80 	
    70 	fh = open("raptorversion.nsh", "w")
    81 	fh = open("raptorversion.nsh", "w")
    71 	fh.write(raptorversion_nsis_header_string)
    82 	fh.write(raptorversion_nsis_header_string)
    92 def cleanup():
   103 def cleanup():
    93 	""" Clean up tempdir """
   104 	""" Clean up tempdir """
    94 	global tempdir
   105 	global tempdir
    95 	print "Cleaning up temporary directory %s" % tempdir
   106 	print "Cleaning up temporary directory %s" % tempdir
    96 	shutil.rmtree(tempdir,True)
   107 	shutil.rmtree(tempdir,True)
       
   108 	try:
       
   109 		os.remove("raptorversion.nsh")
       
   110 		print "Successfully deleted raptorversion.nsh."
       
   111 	except:
       
   112 		print "ERROR: failed to remove raptorversion.nsh - remove manually if needed."
    97 	print "Done."
   113 	print "Done."
    98 
   114 
    99 makensispath = unzipnsis(".\\NSIS.zip")
   115 makensispath = unzipnsis(".\\NSIS.zip")
   100 generateinstallerversionheader(options.sbs_home)
   116 generateinstallerversionheader(options.sbshome)
   101 nsiscommand = makensispath + " /DRAPTOR_LOCATION=%s raptorinstallerscript.nsi" % options.sbs_home
   117 nsiscommand = makensispath + " /DRAPTOR_LOCATION=%s /DWIN32SUPPORT=%s raptorinstallerscript.nsi" % (options.sbshome, options.win32support)
   102 print "nsiscommand = %s" % nsiscommand
   118 print "nsiscommand = %s" % nsiscommand
   103 runmakensis(nsiscommand)
   119 runmakensis(nsiscommand)
   104 cleanup()
   120 cleanup()
   105 
   121