Martin v. Löwis | 1c4c306 | 2008-09-08 16:27:54 +0000 | [diff] [blame] | 1 | import msilib,os,win32com,tempfile,sys
|
Martin v. Löwis | 2a241ca | 2008-04-05 18:58:09 +0000 | [diff] [blame] | 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")
|
Martin v. Löwis | 1c4c306 | 2008-09-08 16:27:54 +0000 | [diff] [blame] | 8 | msi = None
|
| 9 | if len(sys.argv)==2:
|
| 10 | msi = sys.argv[1]
|
Martin v. Löwis | 2a241ca | 2008-04-05 18:58:09 +0000 | [diff] [blame] | 11 | if Win64:
|
Martin v. Löwis | f7cef62 | 2008-10-02 11:46:09 +0000 | [diff] [blame] | 12 | modules = ["Microsoft_VC90_CRT_x86_x64.msm", "policy_9_0_Microsoft_VC90_CRT_x86_x64.msm"]
|
Martin v. Löwis | 1c4c306 | 2008-09-08 16:27:54 +0000 | [diff] [blame] | 13 | if not msi: msi = "python-%s.amd64.msi" % full_current_version
|
Martin v. Löwis | 2a241ca | 2008-04-05 18:58:09 +0000 | [diff] [blame] | 14 | else:
|
Martin v. Löwis | f7cef62 | 2008-10-02 11:46:09 +0000 | [diff] [blame] | 15 | modules = ["Microsoft_VC90_CRT_x86.msm","policy_9_0_Microsoft_VC90_CRT_x86.msm"]
|
Martin v. Löwis | 1c4c306 | 2008-09-08 16:27:54 +0000 | [diff] [blame] | 16 | if not msi: msi = "python-%s.msi" % full_current_version
|
Martin v. Löwis | 2a241ca | 2008-04-05 18:58:09 +0000 | [diff] [blame] | 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")
|
Martin v. Löwis | 3b6cc095 | 2008-07-18 18:40:42 +0000 | [diff] [blame] | 25 | print "Opened Log"
|
Martin v. Löwis | 2a241ca | 2008-04-05 18:58:09 +0000 | [diff] [blame] | 26 | m.OpenDatabase(msi)
|
Martin v. Löwis | 3b6cc095 | 2008-07-18 18:40:42 +0000 | [diff] [blame] | 27 | print "Opened DB"
|
Martin v. Löwis | 2a241ca | 2008-04-05 18:58:09 +0000 | [diff] [blame] | 28 | for module in modules:
|
Martin v. Löwis | 3b6cc095 | 2008-07-18 18:40:42 +0000 | [diff] [blame] | 29 | print module
|
Martin v. Löwis | 2a241ca | 2008-04-05 18:58:09 +0000 | [diff] [blame] | 30 | m.OpenModule(module,0)
|
Martin v. Löwis | 3b6cc095 | 2008-07-18 18:40:42 +0000 | [diff] [blame] | 31 | print "Opened Module",module
|
Martin v. Löwis | 2a241ca | 2008-04-05 18:58:09 +0000 | [diff] [blame] | 32 | m.Merge(feature, rootdir)
|
Martin v. Löwis | 3b6cc095 | 2008-07-18 18:40:42 +0000 | [diff] [blame] | 33 | print "Errors:"
|
Martin v. Löwis | 2a241ca | 2008-04-05 18:58:09 +0000 | [diff] [blame] | 34 | for e in m.Errors:
|
Martin v. Löwis | 3b6cc095 | 2008-07-18 18:40:42 +0000 | [diff] [blame] | 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
|
Martin v. Löwis | 2a241ca | 2008-04-05 18:58:09 +0000 | [diff] [blame] | 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
|
Martin v. Löwis | 3b6cc095 | 2008-07-18 18:40:42 +0000 | [diff] [blame] | 62 | print "Start of Media", maxmedia
|
Martin v. Löwis | 2a241ca | 2008-04-05 18:58:09 +0000 | [diff] [blame] | 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
|
Martin v. Löwis | 21c80f2 | 2008-04-07 21:14:19 +0000 | [diff] [blame] | 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()
|
Martin v. Löwis | 2a241ca | 2008-04-05 18:58:09 +0000 | [diff] [blame] | 76 | db.Commit()
|
| 77 |
|
| 78 | merge(msi, "SharedCRT", "TARGETDIR", modules)
|