|
1 # |
|
2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of the License "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # |
|
16 #! python |
|
17 |
|
18 # Raptor installer maker! |
|
19 |
|
20 import os |
|
21 import os.path |
|
22 import subprocess |
|
23 import re |
|
24 import optparse |
|
25 import sys |
|
26 import tempfile |
|
27 import shutil |
|
28 import unzip |
|
29 |
|
30 tempdir = "" |
|
31 |
|
32 parser = optparse.OptionParser() |
|
33 parser.add_option("-s", "--sbs_home", dest="sbs_home", |
|
34 help="Path to use as SBS_HOME environment variable. If not present the script exits.") |
|
35 |
|
36 (options, args) = parser.parse_args() |
|
37 |
|
38 if options.sbs_home == None: |
|
39 print "ERROR: no SBS_HOME passed in. Exiting..." |
|
40 sys.exit(2) |
|
41 |
|
42 |
|
43 def parseconfig(xmlFile="raptorinstallermaker.xml"): |
|
44 pass |
|
45 |
|
46 def generateinstallerversionheader(sbs_home = None): |
|
47 os.environ["SBS_HOME"] = sbs_home |
|
48 os.environ["PATH"] = os.path.join(os.environ["SBS_HOME"], "bin") + os.pathsep + os.environ["PATH"] |
|
49 |
|
50 versioncommand = "sbs -v" |
|
51 |
|
52 # Raptor version string looks like this |
|
53 # sbs version 2.5.0 [2009-02-20 release] |
|
54 sbs_version_matcher = re.compile(".*(\d+\.\d+\.\d+).*", re.I) |
|
55 |
|
56 # Create Raptor subprocess |
|
57 sbs = subprocess.Popen(versioncommand, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE) |
|
58 |
|
59 # Get all the lines matching the RE |
|
60 for line in sbs.stdout.readlines(): |
|
61 res = sbs_version_matcher.match(line) |
|
62 if res: |
|
63 raptorversion = res.group(1) |
|
64 print "Successfully determined Raptor version %s" % raptorversion |
|
65 |
|
66 sbs.wait() # Wait for process to end |
|
67 |
|
68 raptorversion_nsis_header_string = "# Raptor version file\n\n!define RAPTOR_VERSION %s\n" % raptorversion |
|
69 |
|
70 fh = open("raptorversion.nsh", "w") |
|
71 fh.write(raptorversion_nsis_header_string) |
|
72 fh.close() |
|
73 print "Wrote raptorversion.nsh" |
|
74 return 0 |
|
75 |
|
76 def unzipnsis(pathtozip): |
|
77 global tempdir |
|
78 tempdir = tempfile.mkdtemp() |
|
79 un = unzip.unzip() |
|
80 print "Unzipping NSIS to %s..." % tempdir |
|
81 un.extract(pathtozip, tempdir) |
|
82 print "Done." |
|
83 |
|
84 return os.path.join(tempdir, "NSIS", "makensis.exe") |
|
85 |
|
86 def runmakensis(nsiscommand): |
|
87 # Create makensis subprocess |
|
88 print "Running NSIS command\n%s" % nsiscommand |
|
89 makensis = subprocess.Popen(nsiscommand, shell=True) |
|
90 makensis.wait() # Wait for process to end |
|
91 |
|
92 def cleanup(): |
|
93 """ Clean up tempdir """ |
|
94 global tempdir |
|
95 print "Cleaning up temporary directory %s" % tempdir |
|
96 shutil.rmtree(tempdir,True) |
|
97 print "Done." |
|
98 |
|
99 makensispath = unzipnsis(".\\NSIS.zip") |
|
100 generateinstallerversionheader(options.sbs_home) |
|
101 nsiscommand = makensispath + " /DRAPTOR_LOCATION=%s raptorinstallerscript.nsi" % options.sbs_home |
|
102 print "nsiscommand = %s" % nsiscommand |
|
103 runmakensis(nsiscommand) |
|
104 cleanup() |
|
105 |