sbsv2/raptor/util/install-windows/raptorinstallermaker.py
branchwip
changeset 338 9372474d4b07
parent 143 a00bdef52597
equal deleted inserted replaced
337:62e1f66421b1 338:9372474d4b07
    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="sbshome",
    33 
    34                   help="Path to use as SBS_HOME environment variable. If not present the script exits.")
    34 parser.add_option("-s", "--sbs-home", dest="sbshome", help="Path to use as SBS_HOME environment variable. If not present the script exits.")
    35 parser.add_option("-w", "--win32-support", dest="win32support",
    35 
    36                   help="Path to Win32 support directory. If not present the script exits.")
    36 parser.add_option("-w", "--win32-support", dest="win32support", help="Path to Win32 support directory. If not present the script exits.")
       
    37 
       
    38 parser.add_option("-b", "--bv", dest="bv", help="Path to Binary variation CPP \"root\" directory. Can be a full/relatitve path; prefix with \"WIN32SUPPORT\\\" to be relative to the Win32 support directory. Omitting this value will assume a default to a path inside the Win32 support directory.")
       
    39 
       
    40 parser.add_option("-c", "--cygwin", dest="cygwin", help="Path to Cygwin \"root\" directory. Can be a full/relatitve path; prefix with \"WIN32SUPPORT\\\" to be relative to the Win32 support directory. Omitting this value will assume a default to a path inside the Win32 support directory.")
       
    41 
       
    42 parser.add_option("-m", "--mingw", dest="mingw", help="Path to MinGW \"root\" directory. Can be a full/relatitve path; prefix with \"WIN32SUPPORT\\\" to be relative to the Win32 support directory. Omitting this value will assume a default to a path inside the Win32 support directory.")
       
    43 
       
    44 parser.add_option("-p", "--python", dest="python", help="Path to Python \"root\" directory. Can be a full/relatitve path; prefix with \"WIN32SUPPORT\\\" to be relative to the Win32 support directory. Omitting this value will assume a default to a path inside the Win32 support directory.")
       
    45 
       
    46 parser.add_option("--prefix", dest="versionprefix", help="A string to use as a prefix to the Raptor version string. This will be present in the Raptor installer's file name, the installer's pages as well as the in output from sbs -v.", type="string", default="")
       
    47 
       
    48 parser.add_option("--postfix", dest="versionpostfix", help="A string to use as a postfix to the Raptor version string. This will be present in the Raptor installer's file name, the installer's pages as well as the in output from sbs -v.", type="string", default="")
    37 
    49 
    38 (options, args) = parser.parse_args()
    50 (options, args) = parser.parse_args()
       
    51 
       
    52 # Required directories inside the win32-support repository
       
    53 win32supportdirs = {"bv":"bv", "cygwin":"cygwin", "mingw":"mingw", "python":"python264"}
    39 
    54 
    40 if options.sbshome == None:
    55 if options.sbshome == None:
    41 	print "ERROR: no SBS_HOME passed in. Exiting..."
    56 	print "ERROR: no SBS_HOME passed in. Exiting..."
    42 	sys.exit(2)
    57 	sys.exit(2)
    43 
    58 
    44 if options.win32support == None:
    59 if options.win32support == None:
    45 	print "ERROR: no win32support directory specified. Unable to proceed. Exiting..."
    60 	print "ERROR: no win32support directory specified. Unable to proceed. Exiting..."
    46 	sys.exit(2)
    61 	sys.exit(2)
    47 else:
    62 else:
    48 	# Required irectories inside the win32-support repository
    63 	# Check for command line overrides to defaults
    49 	win32supportdirs = ["bv", "cygwin", "mingw", "python264"]
    64 	for directory in win32supportdirs:
    50 	for dir in win32supportdirs:
    65 		print "TEST %s" % directory
    51 		if not os.path.isdir(os.path.join(options.win32support, dir)):
    66 		value = getattr(options,directory)
       
    67 		print "value =  %s" % str(value)
       
    68 		if value != None: # Command line override
       
    69 			if value.lower().startswith("win32support"):
       
    70 				# Strip off "WIN32SUPPORT\" and join to Win32 support location
       
    71 				win32supportdirs[directory] = os.path.join(options.win32support, value[13:]) 
       
    72 			else:
       
    73 				# Relative to current directory
       
    74 				win32supportdirs[directory] = value
       
    75 
       
    76 		else: # Use default location
       
    77 			win32supportdirs[directory] = os.path.join(options.win32support, win32supportdirs[directory])
       
    78 	
       
    79 	print "\n\nwin32supportdirs = %s\n\n" % win32supportdirs
       
    80 
       
    81 	# Check that all the specified directories exist and exit if any of them is missing.
       
    82 	for directory in win32supportdirs:
       
    83 		dir = win32supportdirs[directory]
       
    84 		if os.path.isdir(dir):
       
    85 			print "Found directory %s" % dir
       
    86 		else:
    52 			print "ERROR: directory %s does not exist. Cannot build installer. Exiting..." % dir
    87 			print "ERROR: directory %s does not exist. Cannot build installer. Exiting..." % dir
    53 			sys.exit(2)
    88 			sys.exit(2)
    54 
       
    55 def parseconfig(xmlFile="raptorinstallermaker.xml"):
       
    56 	pass
       
    57 
    89 
    58 def generateinstallerversionheader(sbshome = None):
    90 def generateinstallerversionheader(sbshome = None):
    59 	shellenv = os.environ.copy()
    91 	shellenv = os.environ.copy()
    60 	shellenv["PYTHONPATH"] = os.path.join(sbshome, "python")
    92 	shellenv["PYTHONPATH"] = os.path.join(sbshome, "python")
    61 	
    93 	
    81 	fh = open("raptorversion.nsh", "w")
   113 	fh = open("raptorversion.nsh", "w")
    82 	fh.write(raptorversion_nsis_header_string)
   114 	fh.write(raptorversion_nsis_header_string)
    83 	fh.close()
   115 	fh.close()
    84 	print "Wrote raptorversion.nsh"
   116 	print "Wrote raptorversion.nsh"
    85 	return 0
   117 	return 0
       
   118 
       
   119 def generateinstallerversion(sbshome = None):
       
   120 	shellenv = os.environ.copy()
       
   121 	shellenv["PYTHONPATH"] = os.path.join(sbshome, "python")
       
   122 	
       
   123 	raptorversioncommand = "python -c \"import raptor_version; print raptor_version.numericversion()\""
       
   124 	
       
   125 	# Raptor version is obtained from raptor_version module's numericversion function.
       
   126 	sbs_version_matcher = re.compile(".*(\d+\.\d+\.\d+).*", re.I)
       
   127 	
       
   128 	# Create Raptor subprocess
       
   129 	versioncommand = subprocess.Popen(raptorversioncommand, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=shellenv)
       
   130 	raptorversion = ""
       
   131 	# Get all the lines matching the RE
       
   132 	for line in versioncommand.stdout.readlines():
       
   133 		res = sbs_version_matcher.match(line)
       
   134 		if res:
       
   135 			raptorversion = res.group(1)
       
   136 			print "Successfully determined Raptor version %s" % raptorversion
       
   137 
       
   138 	versioncommand.wait() # Wait for process to end
       
   139 	
       
   140 	return raptorversion
    86 	
   141 	
    87 def unzipnsis(pathtozip):
   142 def unzipnsis(pathtozip):
    88     global tempdir
   143     global tempdir
    89     tempdir = tempfile.mkdtemp()
   144     tempdir = tempfile.mkdtemp()
    90     un = unzip.unzip()
   145     un = unzip.unzip()
   111 	except:
   166 	except:
   112 		print "ERROR: failed to remove raptorversion.nsh - remove manually if needed."
   167 		print "ERROR: failed to remove raptorversion.nsh - remove manually if needed."
   113 	print "Done."
   168 	print "Done."
   114 
   169 
   115 makensispath = unzipnsis(".\\NSIS.zip")
   170 makensispath = unzipnsis(".\\NSIS.zip")
   116 generateinstallerversionheader(options.sbshome)
   171 # generateinstallerversionheader(options.sbshome)
   117 nsiscommand = makensispath + " /DRAPTOR_LOCATION=%s /DWIN32SUPPORT=%s raptorinstallerscript.nsi" % (options.sbshome, options.win32support)
   172 raptorversion = options.versionprefix + generateinstallerversion(options.sbshome) + options.versionpostfix
       
   173 nsiscommand = makensispath + " /DRAPTOR_LOCATION=%s /DBV_LOCATION=%s /DCYGWIN_LOCATION=%s /DMINGW_LOCATION=%s /DPYTHON_LOCATION=%s /DRAPTOR_VERSION=%s raptorinstallerscript.nsi" % (options.sbshome, 
       
   174 				win32supportdirs["bv"],
       
   175 				win32supportdirs["cygwin"],
       
   176 				win32supportdirs["mingw"],
       
   177 				win32supportdirs["python"],
       
   178 				raptorversion)
   118 print "nsiscommand = %s" % nsiscommand
   179 print "nsiscommand = %s" % nsiscommand
   119 runmakensis(nsiscommand)
   180 runmakensis(nsiscommand)
   120 cleanup()
   181 cleanup()
   121 
   182