1 | import msilib,os,win32com,tempfile,sys
|
---|
2 | PCBUILD="PCBuild"
|
---|
3 | certname = None
|
---|
4 | from config import *
|
---|
5 |
|
---|
6 | Win64 = "amd64" in PCBUILD
|
---|
7 |
|
---|
8 | mod_dir = os.path.join(os.environ["ProgramFiles"], "Common Files", "Merge Modules")
|
---|
9 | msi = None
|
---|
10 | if len(sys.argv)==2:
|
---|
11 | msi = sys.argv[1]
|
---|
12 | if Win64:
|
---|
13 | modules = ["Microsoft_VC90_CRT_x86_x64.msm", "policy_9_0_Microsoft_VC90_CRT_x86_x64.msm"]
|
---|
14 | if not msi: msi = "python-%s.amd64.msi" % full_current_version
|
---|
15 | else:
|
---|
16 | modules = ["Microsoft_VC90_CRT_x86.msm","policy_9_0_Microsoft_VC90_CRT_x86.msm"]
|
---|
17 | if not msi: msi = "python-%s.msi" % full_current_version
|
---|
18 | for i, n in enumerate(modules):
|
---|
19 | modules[i] = os.path.join(mod_dir, n)
|
---|
20 |
|
---|
21 | def merge(msi, feature, rootdir, modules):
|
---|
22 | cab_and_filecount = []
|
---|
23 | # Step 1: Merge databases, extract cabfiles
|
---|
24 | m = msilib.MakeMerge2()
|
---|
25 | m.OpenLog("merge.log")
|
---|
26 | print "Opened Log"
|
---|
27 | m.OpenDatabase(msi)
|
---|
28 | print "Opened DB"
|
---|
29 | for module in modules:
|
---|
30 | print module
|
---|
31 | m.OpenModule(module,0)
|
---|
32 | print "Opened Module",module
|
---|
33 | m.Merge(feature, rootdir)
|
---|
34 | print "Errors:"
|
---|
35 | for e in m.Errors:
|
---|
36 | print e.Type, e.ModuleTable, e.DatabaseTable
|
---|
37 | print " Modkeys:",
|
---|
38 | for s in e.ModuleKeys: print s,
|
---|
39 | print
|
---|
40 | print " DBKeys:",
|
---|
41 | for s in e.DatabaseKeys: print s,
|
---|
42 | print
|
---|
43 | cabname = tempfile.mktemp(suffix=".cab")
|
---|
44 | m.ExtractCAB(cabname)
|
---|
45 | cab_and_filecount.append((cabname, len(m.ModuleFiles)))
|
---|
46 | m.CloseModule()
|
---|
47 | m.CloseDatabase(True)
|
---|
48 | m.CloseLog()
|
---|
49 |
|
---|
50 | # Step 2: Add CAB files
|
---|
51 | i = msilib.MakeInstaller()
|
---|
52 | db = i.OpenDatabase(msi, win32com.client.constants.msiOpenDatabaseModeTransact)
|
---|
53 |
|
---|
54 | v = db.OpenView("SELECT LastSequence FROM Media")
|
---|
55 | v.Execute(None)
|
---|
56 | maxmedia = -1
|
---|
57 | while 1:
|
---|
58 | r = v.Fetch()
|
---|
59 | if not r: break
|
---|
60 | seq = r.IntegerData(1)
|
---|
61 | if seq > maxmedia:
|
---|
62 | maxmedia = seq
|
---|
63 | print "Start of Media", maxmedia
|
---|
64 |
|
---|
65 | for cabname, count in cab_and_filecount:
|
---|
66 | stream = "merged%d" % maxmedia
|
---|
67 | msilib.add_data(db, "Media",
|
---|
68 | [(maxmedia+1, maxmedia+count, None, "#"+stream, None, None)])
|
---|
69 | msilib.add_stream(db, stream, cabname)
|
---|
70 | os.unlink(cabname)
|
---|
71 | maxmedia += count
|
---|
72 | # The merge module sets ALLUSERS to 1 in the property table.
|
---|
73 | # This is undesired; delete that
|
---|
74 | v = db.OpenView("DELETE FROM Property WHERE Property='ALLUSERS'")
|
---|
75 | v.Execute(None)
|
---|
76 | v.Close()
|
---|
77 | db.Commit()
|
---|
78 |
|
---|
79 | merge(msi, "SharedCRT", "TARGETDIR", modules)
|
---|
80 |
|
---|
81 | # certname (from config.py) should be (a substring of)
|
---|
82 | # the certificate subject, e.g. "Python Software Foundation"
|
---|
83 | if certname:
|
---|
84 | os.system('signtool sign /n "%s" /t http://timestamp.verisign.com/scripts/timestamp.dll %s' % (certname, msi))
|
---|