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"
|
Benjamin Peterson | 247a9b8 | 2009-02-20 04:09:19 +0000 | [diff] [blame] | 3 | certname = None
|
Martin v. Löwis | 2a241ca | 2008-04-05 18:58:09 +0000 | [diff] [blame] | 4 | from config import *
|
| 5 |
|
| 6 | Win64 = "amd64" in PCBUILD
|
| 7 |
|
| 8 | 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] | 9 | msi = None
|
| 10 | if len(sys.argv)==2:
|
| 11 | msi = sys.argv[1]
|
Martin v. Löwis | 2a241ca | 2008-04-05 18:58:09 +0000 | [diff] [blame] | 12 | if Win64:
|
Martin v. Löwis | f7cef62 | 2008-10-02 11:46:09 +0000 | [diff] [blame] | 13 | 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] | 14 | 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] | 15 | else:
|
Martin v. Löwis | f7cef62 | 2008-10-02 11:46:09 +0000 | [diff] [blame] | 16 | 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] | 17 | if not msi: msi = "python-%s.msi" % full_current_version
|
Martin v. Löwis | 2a241ca | 2008-04-05 18:58:09 +0000 | [diff] [blame] | 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")
|
Martin v. Löwis | 3b6cc095 | 2008-07-18 18:40:42 +0000 | [diff] [blame] | 26 | print "Opened Log"
|
Martin v. Löwis | 2a241ca | 2008-04-05 18:58:09 +0000 | [diff] [blame] | 27 | m.OpenDatabase(msi)
|
Martin v. Löwis | 3b6cc095 | 2008-07-18 18:40:42 +0000 | [diff] [blame] | 28 | print "Opened DB"
|
Martin v. Löwis | 2a241ca | 2008-04-05 18:58:09 +0000 | [diff] [blame] | 29 | for module in modules:
|
Martin v. Löwis | 3b6cc095 | 2008-07-18 18:40:42 +0000 | [diff] [blame] | 30 | print module
|
Martin v. Löwis | 2a241ca | 2008-04-05 18:58:09 +0000 | [diff] [blame] | 31 | m.OpenModule(module,0)
|
Martin v. Löwis | 3b6cc095 | 2008-07-18 18:40:42 +0000 | [diff] [blame] | 32 | print "Opened Module",module
|
Martin v. Löwis | 2a241ca | 2008-04-05 18:58:09 +0000 | [diff] [blame] | 33 | m.Merge(feature, rootdir)
|
Martin v. Löwis | 3b6cc095 | 2008-07-18 18:40:42 +0000 | [diff] [blame] | 34 | print "Errors:"
|
Martin v. Löwis | 2a241ca | 2008-04-05 18:58:09 +0000 | [diff] [blame] | 35 | for e in m.Errors:
|
Martin v. Löwis | 3b6cc095 | 2008-07-18 18:40:42 +0000 | [diff] [blame] | 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
|
Martin v. Löwis | 2a241ca | 2008-04-05 18:58:09 +0000 | [diff] [blame] | 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
|
Martin v. Löwis | 3b6cc095 | 2008-07-18 18:40:42 +0000 | [diff] [blame] | 63 | print "Start of Media", maxmedia
|
Martin v. Löwis | 2a241ca | 2008-04-05 18:58:09 +0000 | [diff] [blame] | 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öwis | 21c80f2 | 2008-04-07 21:14:19 +0000 | [diff] [blame] | 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()
|
Martin v. Löwis | 2a241ca | 2008-04-05 18:58:09 +0000 | [diff] [blame] | 77 | db.Commit()
|
| 78 |
|
| 79 | merge(msi, "SharedCRT", "TARGETDIR", modules)
|
Benjamin Peterson | 247a9b8 | 2009-02-20 04:09:19 +0000 | [diff] [blame] | 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))
|