sbsv2/raptor/util/install-windows/raptorinstallermaker.py
author Richard Taylor <richard.i.taylor@nokia.com>
Tue, 16 Feb 2010 10:11:06 +0000
changeset 212 18372202b584
parent 143 a00bdef52597
child 338 9372474d4b07
permissions -rw-r--r--
escape filenames in <member> tags
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     1
#
142
26f2f0b4002b Update Windows installation script to put Python 2.6.4 into the Windows installer.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 79
diff changeset
     2
# Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     3
# All rights reserved.
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     4
# This component and the accompanying materials are made available
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     5
# under the terms of the License "Eclipse Public License v1.0"
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     6
# which accompanies this distribution, and is available
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     8
#
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     9
# Initial Contributors:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    10
# Nokia Corporation - initial contribution.
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    11
#
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    12
# Contributors:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    13
#
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    14
# Description: 
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    15
#
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    16
#! python
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    17
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    18
# Raptor installer maker!
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    19
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    20
import os
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    21
import os.path
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    22
import subprocess
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    23
import re
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    24
import optparse
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    25
import sys
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    26
import tempfile
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    27
import shutil
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    28
import unzip
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    29
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    30
tempdir = ""
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    31
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    32
parser = optparse.OptionParser()
79
540de0f551cf Updates to Raptor Installer Maker tool to take into account win32-support repository location.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 3
diff changeset
    33
parser.add_option("-s", "--sbs-home", dest="sbshome",
540de0f551cf Updates to Raptor Installer Maker tool to take into account win32-support repository location.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 3
diff changeset
    34
                  help="Path to use as SBS_HOME environment variable. If not present the script exits.")
540de0f551cf Updates to Raptor Installer Maker tool to take into account win32-support repository location.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 3
diff changeset
    35
parser.add_option("-w", "--win32-support", dest="win32support",
143
a00bdef52597 Correct problems in raptorinstallermaker.py: ensure missing directories' names are printed rather than %s when checking Win32 support directory, and remove final reliance on SBS_HOME environment variable (use only the value passed to the -s switch).
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 142
diff changeset
    36
                  help="Path to Win32 support directory. If not present the script exits.")
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    37
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    38
(options, args) = parser.parse_args()
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    39
79
540de0f551cf Updates to Raptor Installer Maker tool to take into account win32-support repository location.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 3
diff changeset
    40
if options.sbshome == None:
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    41
	print "ERROR: no SBS_HOME passed in. Exiting..."
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    42
	sys.exit(2)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    43
79
540de0f551cf Updates to Raptor Installer Maker tool to take into account win32-support repository location.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 3
diff changeset
    44
if options.win32support == None:
540de0f551cf Updates to Raptor Installer Maker tool to take into account win32-support repository location.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 3
diff changeset
    45
	print "ERROR: no win32support directory specified. Unable to proceed. Exiting..."
540de0f551cf Updates to Raptor Installer Maker tool to take into account win32-support repository location.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 3
diff changeset
    46
	sys.exit(2)
540de0f551cf Updates to Raptor Installer Maker tool to take into account win32-support repository location.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 3
diff changeset
    47
else:
540de0f551cf Updates to Raptor Installer Maker tool to take into account win32-support repository location.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 3
diff changeset
    48
	# Required irectories inside the win32-support repository
142
26f2f0b4002b Update Windows installation script to put Python 2.6.4 into the Windows installer.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 79
diff changeset
    49
	win32supportdirs = ["bv", "cygwin", "mingw", "python264"]
79
540de0f551cf Updates to Raptor Installer Maker tool to take into account win32-support repository location.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 3
diff changeset
    50
	for dir in win32supportdirs:
540de0f551cf Updates to Raptor Installer Maker tool to take into account win32-support repository location.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 3
diff changeset
    51
		if not os.path.isdir(os.path.join(options.win32support, dir)):
143
a00bdef52597 Correct problems in raptorinstallermaker.py: ensure missing directories' names are printed rather than %s when checking Win32 support directory, and remove final reliance on SBS_HOME environment variable (use only the value passed to the -s switch).
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 142
diff changeset
    52
			print "ERROR: directory %s does not exist. Cannot build installer. Exiting..." % dir
79
540de0f551cf Updates to Raptor Installer Maker tool to take into account win32-support repository location.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 3
diff changeset
    53
			sys.exit(2)
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    54
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    55
def parseconfig(xmlFile="raptorinstallermaker.xml"):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    56
	pass
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    57
79
540de0f551cf Updates to Raptor Installer Maker tool to take into account win32-support repository location.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 3
diff changeset
    58
def generateinstallerversionheader(sbshome = None):
540de0f551cf Updates to Raptor Installer Maker tool to take into account win32-support repository location.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 3
diff changeset
    59
	shellenv = os.environ.copy()
143
a00bdef52597 Correct problems in raptorinstallermaker.py: ensure missing directories' names are printed rather than %s when checking Win32 support directory, and remove final reliance on SBS_HOME environment variable (use only the value passed to the -s switch).
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 142
diff changeset
    60
	shellenv["PYTHONPATH"] = os.path.join(sbshome, "python")
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    61
	
79
540de0f551cf Updates to Raptor Installer Maker tool to take into account win32-support repository location.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 3
diff changeset
    62
	raptorversioncommand = "python -c \"import raptor_version; print raptor_version.numericversion()\""
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    63
	
79
540de0f551cf Updates to Raptor Installer Maker tool to take into account win32-support repository location.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 3
diff changeset
    64
	# Raptor version is obtained from raptor_version module's numericversion function.
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    65
	sbs_version_matcher = re.compile(".*(\d+\.\d+\.\d+).*", re.I)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    66
	
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    67
	# Create Raptor subprocess
79
540de0f551cf Updates to Raptor Installer Maker tool to take into account win32-support repository location.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 3
diff changeset
    68
	versioncommand = subprocess.Popen(raptorversioncommand, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=shellenv)
540de0f551cf Updates to Raptor Installer Maker tool to take into account win32-support repository location.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 3
diff changeset
    69
	raptorversion = ""
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    70
	# Get all the lines matching the RE
79
540de0f551cf Updates to Raptor Installer Maker tool to take into account win32-support repository location.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 3
diff changeset
    71
	for line in versioncommand.stdout.readlines():
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    72
		res = sbs_version_matcher.match(line)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    73
		if res:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    74
			raptorversion = res.group(1)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    75
			print "Successfully determined Raptor version %s" % raptorversion
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    76
79
540de0f551cf Updates to Raptor Installer Maker tool to take into account win32-support repository location.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 3
diff changeset
    77
	versioncommand.wait() # Wait for process to end
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    78
	
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    79
	raptorversion_nsis_header_string = "# Raptor version file\n\n!define RAPTOR_VERSION %s\n" % raptorversion
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    80
	
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    81
	fh = open("raptorversion.nsh", "w")
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    82
	fh.write(raptorversion_nsis_header_string)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    83
	fh.close()
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    84
	print "Wrote raptorversion.nsh"
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    85
	return 0
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    86
	
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    87
def unzipnsis(pathtozip):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    88
    global tempdir
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    89
    tempdir = tempfile.mkdtemp()
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    90
    un = unzip.unzip()
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    91
    print "Unzipping NSIS to %s..." % tempdir
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    92
    un.extract(pathtozip, tempdir)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    93
    print "Done."
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    94
    
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    95
    return os.path.join(tempdir, "NSIS", "makensis.exe")
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    96
    
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    97
def runmakensis(nsiscommand):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    98
	# Create makensis subprocess
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    99
	print "Running NSIS command\n%s" % nsiscommand
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   100
	makensis = subprocess.Popen(nsiscommand, shell=True)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   101
	makensis.wait() # Wait for process to end
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   102
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   103
def cleanup():
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   104
	""" Clean up tempdir """
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   105
	global tempdir
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   106
	print "Cleaning up temporary directory %s" % tempdir
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   107
	shutil.rmtree(tempdir,True)
79
540de0f551cf Updates to Raptor Installer Maker tool to take into account win32-support repository location.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 3
diff changeset
   108
	try:
540de0f551cf Updates to Raptor Installer Maker tool to take into account win32-support repository location.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 3
diff changeset
   109
		os.remove("raptorversion.nsh")
540de0f551cf Updates to Raptor Installer Maker tool to take into account win32-support repository location.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 3
diff changeset
   110
		print "Successfully deleted raptorversion.nsh."
540de0f551cf Updates to Raptor Installer Maker tool to take into account win32-support repository location.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 3
diff changeset
   111
	except:
540de0f551cf Updates to Raptor Installer Maker tool to take into account win32-support repository location.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 3
diff changeset
   112
		print "ERROR: failed to remove raptorversion.nsh - remove manually if needed."
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   113
	print "Done."
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   114
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   115
makensispath = unzipnsis(".\\NSIS.zip")
79
540de0f551cf Updates to Raptor Installer Maker tool to take into account win32-support repository location.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 3
diff changeset
   116
generateinstallerversionheader(options.sbshome)
540de0f551cf Updates to Raptor Installer Maker tool to take into account win32-support repository location.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents: 3
diff changeset
   117
nsiscommand = makensispath + " /DRAPTOR_LOCATION=%s /DWIN32SUPPORT=%s raptorinstallerscript.nsi" % (options.sbshome, options.win32support)
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   118
print "nsiscommand = %s" % nsiscommand
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   119
runmakensis(nsiscommand)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   120
cleanup()
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   121