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