blob: def396479909e8b798023bb7265e4333ebdbd272 [file] [log] [blame]
Martin v. Löwis67543a92008-09-08 12:02:45 +00001import msilib,os,win32com,tempfile,sys
Martin v. Löwisdb508be2008-04-05 15:50:58 +00002PCBUILD="PCBuild"
Martin v. Löwis7e28b9c2009-02-13 20:51:48 +00003certname = None
Martin v. Löwisdb508be2008-04-05 15:50:58 +00004from config import *
5
6Win64 = "amd64" in PCBUILD
7
8mod_dir = os.path.join(os.environ["ProgramFiles"], "Common Files", "Merge Modules")
Martin v. Löwis67543a92008-09-08 12:02:45 +00009msi = None
10if len(sys.argv)==2:
11 msi = sys.argv[1]
Martin v. Löwisdb508be2008-04-05 15:50:58 +000012if Win64:
Martin v. Löwisf738f0b2008-10-02 11:44:17 +000013 modules = ["Microsoft_VC90_CRT_x86_x64.msm", "policy_9_0_Microsoft_VC90_CRT_x86_x64.msm"]
Martin v. Löwis67543a92008-09-08 12:02:45 +000014 if not msi: msi = "python-%s.amd64.msi" % full_current_version
Martin v. Löwisdb508be2008-04-05 15:50:58 +000015else:
Martin v. Löwisf738f0b2008-10-02 11:44:17 +000016 modules = ["Microsoft_VC90_CRT_x86.msm","policy_9_0_Microsoft_VC90_CRT_x86.msm"]
Martin v. Löwis67543a92008-09-08 12:02:45 +000017 if not msi: msi = "python-%s.msi" % full_current_version
Martin v. Löwisdb508be2008-04-05 15:50:58 +000018for i, n in enumerate(modules):
19 modules[i] = os.path.join(mod_dir, n)
20
21def 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
Martin v. Löwis54d489a2008-04-07 14:53:34 +000072 # 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()
Martin v. Löwisdb508be2008-04-05 15:50:58 +000077 db.Commit()
78
79merge(msi, "SharedCRT", "TARGETDIR", modules)
Martin v. Löwis7e28b9c2009-02-13 20:51:48 +000080
81# certname (from config.py) should be (a substring of)
82# the certificate subject, e.g. "Python Software Foundation"
83if certname:
84 os.system('signtool sign /n "%s" /t http://timestamp.verisign.com/scripts/timestamp.dll %s' % (certname, msi))