blob: ff34b9354b08fffbc5a8e22d536a6ef3539cc7b6 [file] [log] [blame]
Martin v. Löwis2a241ca2008-04-05 18:58:09 +00001import msilib,os,win32com,tempfile
2PCBUILD="PCBuild"
3from config import *
4
5Win64 = "amd64" in PCBUILD
6
7mod_dir = os.path.join(os.environ["ProgramFiles"], "Common Files", "Merge Modules")
8if Win64:
9 modules = ["Microsoft_VC90_CRT_x86.msm", "policy_8_0_Microsoft_VC80_CRT_x86_x64.msm"]
10 msi = "python-%s.amd64.msi" % full_current_version
11else:
12 modules = ["Microsoft_VC90_CRT_x86.msm","policy_8_0_Microsoft_VC80_CRT_x86.msm"]
13 msi = "python-%s.msi" % full_current_version
14for i, n in enumerate(modules):
15 modules[i] = os.path.join(mod_dir, n)
16
17def merge(msi, feature, rootdir, modules):
18 cab_and_filecount = []
19 # Step 1: Merge databases, extract cabfiles
20 m = msilib.MakeMerge2()
21 m.OpenLog("merge.log")
Martin v. Löwis3b6cc0952008-07-18 18:40:42 +000022 print "Opened Log"
Martin v. Löwis2a241ca2008-04-05 18:58:09 +000023 m.OpenDatabase(msi)
Martin v. Löwis3b6cc0952008-07-18 18:40:42 +000024 print "Opened DB"
Martin v. Löwis2a241ca2008-04-05 18:58:09 +000025 for module in modules:
Martin v. Löwis3b6cc0952008-07-18 18:40:42 +000026 print module
Martin v. Löwis2a241ca2008-04-05 18:58:09 +000027 m.OpenModule(module,0)
Martin v. Löwis3b6cc0952008-07-18 18:40:42 +000028 print "Opened Module",module
Martin v. Löwis2a241ca2008-04-05 18:58:09 +000029 m.Merge(feature, rootdir)
Martin v. Löwis3b6cc0952008-07-18 18:40:42 +000030 print "Errors:"
Martin v. Löwis2a241ca2008-04-05 18:58:09 +000031 for e in m.Errors:
Martin v. Löwis3b6cc0952008-07-18 18:40:42 +000032 print e.Type, e.ModuleTable, e.DatabaseTable
33 print " Modkeys:",
34 for s in e.ModuleKeys: print s,
35 print
36 print " DBKeys:",
37 for s in e.DatabaseKeys: print s,
38 print
Martin v. Löwis2a241ca2008-04-05 18:58:09 +000039 cabname = tempfile.mktemp(suffix=".cab")
40 m.ExtractCAB(cabname)
41 cab_and_filecount.append((cabname, len(m.ModuleFiles)))
42 m.CloseModule()
43 m.CloseDatabase(True)
44 m.CloseLog()
45
46 # Step 2: Add CAB files
47 i = msilib.MakeInstaller()
48 db = i.OpenDatabase(msi, win32com.client.constants.msiOpenDatabaseModeTransact)
49
50 v = db.OpenView("SELECT LastSequence FROM Media")
51 v.Execute(None)
52 maxmedia = -1
53 while 1:
54 r = v.Fetch()
55 if not r: break
56 seq = r.IntegerData(1)
57 if seq > maxmedia:
58 maxmedia = seq
Martin v. Löwis3b6cc0952008-07-18 18:40:42 +000059 print "Start of Media", maxmedia
Martin v. Löwis2a241ca2008-04-05 18:58:09 +000060
61 for cabname, count in cab_and_filecount:
62 stream = "merged%d" % maxmedia
63 msilib.add_data(db, "Media",
64 [(maxmedia+1, maxmedia+count, None, "#"+stream, None, None)])
65 msilib.add_stream(db, stream, cabname)
66 os.unlink(cabname)
67 maxmedia += count
Martin v. Löwis21c80f22008-04-07 21:14:19 +000068 # The merge module sets ALLUSERS to 1 in the property table.
69 # This is undesired; delete that
70 v = db.OpenView("DELETE FROM Property WHERE Property='ALLUSERS'")
71 v.Execute(None)
72 v.Close()
Martin v. Löwis2a241ca2008-04-05 18:58:09 +000073 db.Commit()
74
75merge(msi, "SharedCRT", "TARGETDIR", modules)