PageRenderTime 54ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/Tools/msi/msi.py

http://unladen-swallow.googlecode.com/
Python | 1301 lines | 1258 code | 11 blank | 32 comment | 43 complexity | c42c3665caff481aaffbdac3b7a308c5 MD5 | raw file
Possible License(s): 0BSD, BSD-3-Clause
  1. # Python MSI Generator
  2. # (C) 2003 Martin v. Loewis
  3. # See "FOO" in comments refers to MSDN sections with the title FOO.
  4. import msilib, schema, sequence, os, glob, time, re, shutil
  5. from msilib import Feature, CAB, Directory, Dialog, Binary, add_data
  6. import uisample
  7. from win32com.client import constants
  8. from distutils.spawn import find_executable
  9. from uuids import product_codes
  10. # Settings can be overridden in config.py below
  11. # 0 for official python.org releases
  12. # 1 for intermediate releases by anybody, with
  13. # a new product code for every package.
  14. snapshot = 1
  15. # 1 means that file extension is px, not py,
  16. # and binaries start with x
  17. testpackage = 0
  18. # Location of build tree
  19. srcdir = os.path.abspath("../..")
  20. # Text to be displayed as the version in dialogs etc.
  21. # goes into file name and ProductCode. Defaults to
  22. # current_version.day for Snapshot, current_version otherwise
  23. full_current_version = None
  24. # Is Tcl available at all?
  25. have_tcl = True
  26. # path to PCbuild directory
  27. PCBUILD="PCbuild"
  28. # msvcrt version
  29. MSVCR = "90"
  30. try:
  31. from config import *
  32. except ImportError:
  33. pass
  34. # Extract current version from Include/patchlevel.h
  35. lines = open(srcdir + "/Include/patchlevel.h").readlines()
  36. major = minor = micro = level = serial = None
  37. levels = {
  38. 'PY_RELEASE_LEVEL_ALPHA':0xA,
  39. 'PY_RELEASE_LEVEL_BETA': 0xB,
  40. 'PY_RELEASE_LEVEL_GAMMA':0xC,
  41. 'PY_RELEASE_LEVEL_FINAL':0xF
  42. }
  43. for l in lines:
  44. if not l.startswith("#define"):
  45. continue
  46. l = l.split()
  47. if len(l) != 3:
  48. continue
  49. _, name, value = l
  50. if name == 'PY_MAJOR_VERSION': major = value
  51. if name == 'PY_MINOR_VERSION': minor = value
  52. if name == 'PY_MICRO_VERSION': micro = value
  53. if name == 'PY_RELEASE_LEVEL': level = levels[value]
  54. if name == 'PY_RELEASE_SERIAL': serial = value
  55. short_version = major+"."+minor
  56. # See PC/make_versioninfo.c
  57. FIELD3 = 1000*int(micro) + 10*level + int(serial)
  58. current_version = "%s.%d" % (short_version, FIELD3)
  59. # This should never change. The UpgradeCode of this package can be
  60. # used in the Upgrade table of future packages to make the future
  61. # package replace this one. See "UpgradeCode Property".
  62. # upgrade_code gets set to upgrade_code_64 when we have determined
  63. # that the target is Win64.
  64. upgrade_code_snapshot='{92A24481-3ECB-40FC-8836-04B7966EC0D5}'
  65. upgrade_code='{65E6DE48-A358-434D-AA4F-4AF72DB4718F}'
  66. upgrade_code_64='{6A965A0C-6EE6-4E3A-9983-3263F56311EC}'
  67. if snapshot:
  68. current_version = "%s.%s.%s" % (major, minor, int(time.time()/3600/24))
  69. product_code = msilib.gen_uuid()
  70. else:
  71. product_code = product_codes[current_version]
  72. if full_current_version is None:
  73. full_current_version = current_version
  74. extensions = [
  75. 'bz2.pyd',
  76. 'pyexpat.pyd',
  77. 'select.pyd',
  78. 'unicodedata.pyd',
  79. 'winsound.pyd',
  80. '_elementtree.pyd',
  81. '_bsddb.pyd',
  82. '_socket.pyd',
  83. '_ssl.pyd',
  84. '_testcapi.pyd',
  85. '_tkinter.pyd',
  86. '_msi.pyd',
  87. '_ctypes.pyd',
  88. '_ctypes_test.pyd',
  89. '_sqlite3.pyd',
  90. '_hashlib.pyd',
  91. '_multiprocessing.pyd'
  92. ]
  93. # Well-known component UUIDs
  94. # These are needed for SharedDLLs reference counter; if
  95. # a different UUID was used for each incarnation of, say,
  96. # python24.dll, an upgrade would set the reference counter
  97. # from 1 to 2 (due to what I consider a bug in MSI)
  98. # Using the same UUID is fine since these files are versioned,
  99. # so Installer will always keep the newest version.
  100. # NOTE: All uuids are self generated.
  101. pythondll_uuid = {
  102. "24":"{9B81E618-2301-4035-AC77-75D9ABEB7301}",
  103. "25":"{2e41b118-38bd-4c1b-a840-6977efd1b911}",
  104. "26":"{34ebecac-f046-4e1c-b0e3-9bac3cdaacfa}",
  105. } [major+minor]
  106. # Compute the name that Sphinx gives to the docfile
  107. docfile = ""
  108. if micro:
  109. docfile = str(micro)
  110. if level < 0xf:
  111. docfile += '%x%s' % (level, serial)
  112. docfile = 'python%s%s%s.chm' % (major, minor, docfile)
  113. # Build the mingw import library, libpythonXY.a
  114. # This requires 'nm' and 'dlltool' executables on your PATH
  115. def build_mingw_lib(lib_file, def_file, dll_file, mingw_lib):
  116. warning = "WARNING: %s - libpythonXX.a not built"
  117. nm = find_executable('nm')
  118. dlltool = find_executable('dlltool')
  119. if not nm or not dlltool:
  120. print warning % "nm and/or dlltool were not found"
  121. return False
  122. nm_command = '%s -Cs %s' % (nm, lib_file)
  123. dlltool_command = "%s --dllname %s --def %s --output-lib %s" % \
  124. (dlltool, dll_file, def_file, mingw_lib)
  125. export_match = re.compile(r"^_imp__(.*) in python\d+\.dll").match
  126. f = open(def_file,'w')
  127. print >>f, "LIBRARY %s" % dll_file
  128. print >>f, "EXPORTS"
  129. nm_pipe = os.popen(nm_command)
  130. for line in nm_pipe.readlines():
  131. m = export_match(line)
  132. if m:
  133. print >>f, m.group(1)
  134. f.close()
  135. exit = nm_pipe.close()
  136. if exit:
  137. print warning % "nm did not run successfully"
  138. return False
  139. if os.system(dlltool_command) != 0:
  140. print warning % "dlltool did not run successfully"
  141. return False
  142. return True
  143. # Target files (.def and .a) go in PCBuild directory
  144. lib_file = os.path.join(srcdir, PCBUILD, "python%s%s.lib" % (major, minor))
  145. def_file = os.path.join(srcdir, PCBUILD, "python%s%s.def" % (major, minor))
  146. dll_file = "python%s%s.dll" % (major, minor)
  147. mingw_lib = os.path.join(srcdir, PCBUILD, "libpython%s%s.a" % (major, minor))
  148. have_mingw = build_mingw_lib(lib_file, def_file, dll_file, mingw_lib)
  149. # Determine the target architechture
  150. dll_path = os.path.join(srcdir, PCBUILD, dll_file)
  151. msilib.set_arch_from_file(dll_path)
  152. if msilib.pe_type(dll_path) != msilib.pe_type("msisupport.dll"):
  153. raise SystemError, "msisupport.dll for incorrect architecture"
  154. if msilib.Win64:
  155. upgrade_code = upgrade_code_64
  156. # Bump the last digit of the code by one, so that 32-bit and 64-bit
  157. # releases get separate product codes
  158. digit = hex((int(product_code[-2],16)+1)%16)[-1]
  159. product_code = product_code[:-2] + digit + '}'
  160. if testpackage:
  161. ext = 'px'
  162. testprefix = 'x'
  163. else:
  164. ext = 'py'
  165. testprefix = ''
  166. if msilib.Win64:
  167. SystemFolderName = "[System64Folder]"
  168. registry_component = 4|256
  169. else:
  170. SystemFolderName = "[SystemFolder]"
  171. registry_component = 4
  172. msilib.reset()
  173. # condition in which to install pythonxy.dll in system32:
  174. # a) it is Windows 9x or
  175. # b) it is NT, the user is privileged, and has chosen per-machine installation
  176. sys32cond = "(Windows9x or (Privileged and ALLUSERS))"
  177. def build_database():
  178. """Generate an empty database, with just the schema and the
  179. Summary information stream."""
  180. if snapshot:
  181. uc = upgrade_code_snapshot
  182. else:
  183. uc = upgrade_code
  184. if msilib.Win64:
  185. productsuffix = " (64-bit)"
  186. else:
  187. productsuffix = ""
  188. # schema represents the installer 2.0 database schema.
  189. # sequence is the set of standard sequences
  190. # (ui/execute, admin/advt/install)
  191. db = msilib.init_database("python-%s%s.msi" % (full_current_version, msilib.arch_ext),
  192. schema, ProductName="Python "+full_current_version+productsuffix,
  193. ProductCode=product_code,
  194. ProductVersion=current_version,
  195. Manufacturer=u"Python Software Foundation",
  196. request_uac = True)
  197. # The default sequencing of the RemoveExistingProducts action causes
  198. # removal of files that got just installed. Place it after
  199. # InstallInitialize, so we first uninstall everything, but still roll
  200. # back in case the installation is interrupted
  201. msilib.change_sequence(sequence.InstallExecuteSequence,
  202. "RemoveExistingProducts", 1510)
  203. msilib.add_tables(db, sequence)
  204. # We cannot set ALLUSERS in the property table, as this cannot be
  205. # reset if the user choses a per-user installation. Instead, we
  206. # maintain WhichUsers, which can be "ALL" or "JUSTME". The UI manages
  207. # this property, and when the execution starts, ALLUSERS is set
  208. # accordingly.
  209. add_data(db, "Property", [("UpgradeCode", uc),
  210. ("WhichUsers", "ALL"),
  211. ("ProductLine", "Python%s%s" % (major, minor)),
  212. ])
  213. db.Commit()
  214. return db
  215. def remove_old_versions(db):
  216. "Fill the upgrade table."
  217. start = "%s.%s.0" % (major, minor)
  218. # This requests that feature selection states of an older
  219. # installation should be forwarded into this one. Upgrading
  220. # requires that both the old and the new installation are
  221. # either both per-machine or per-user.
  222. migrate_features = 1
  223. # See "Upgrade Table". We remove releases with the same major and
  224. # minor version. For an snapshot, we remove all earlier snapshots. For
  225. # a release, we remove all snapshots, and all earlier releases.
  226. if snapshot:
  227. add_data(db, "Upgrade",
  228. [(upgrade_code_snapshot, start,
  229. current_version,
  230. None, # Ignore language
  231. migrate_features,
  232. None, # Migrate ALL features
  233. "REMOVEOLDSNAPSHOT")])
  234. props = "REMOVEOLDSNAPSHOT"
  235. else:
  236. add_data(db, "Upgrade",
  237. [(upgrade_code, start, current_version,
  238. None, migrate_features, None, "REMOVEOLDVERSION"),
  239. (upgrade_code_snapshot, start, "%s.%d.0" % (major, int(minor)+1),
  240. None, migrate_features, None, "REMOVEOLDSNAPSHOT")])
  241. props = "REMOVEOLDSNAPSHOT;REMOVEOLDVERSION"
  242. props += ";TARGETDIR;DLLDIR"
  243. # Installer collects the product codes of the earlier releases in
  244. # these properties. In order to allow modification of the properties,
  245. # they must be declared as secure. See "SecureCustomProperties Property"
  246. add_data(db, "Property", [("SecureCustomProperties", props)])
  247. class PyDialog(Dialog):
  248. """Dialog class with a fixed layout: controls at the top, then a ruler,
  249. then a list of buttons: back, next, cancel. Optionally a bitmap at the
  250. left."""
  251. def __init__(self, *args, **kw):
  252. """Dialog(database, name, x, y, w, h, attributes, title, first,
  253. default, cancel, bitmap=true)"""
  254. Dialog.__init__(self, *args)
  255. ruler = self.h - 36
  256. bmwidth = 152*ruler/328
  257. if kw.get("bitmap", True):
  258. self.bitmap("Bitmap", 0, 0, bmwidth, ruler, "PythonWin")
  259. self.line("BottomLine", 0, ruler, self.w, 0)
  260. def title(self, title):
  261. "Set the title text of the dialog at the top."
  262. # name, x, y, w, h, flags=Visible|Enabled|Transparent|NoPrefix,
  263. # text, in VerdanaBold10
  264. self.text("Title", 135, 10, 220, 60, 0x30003,
  265. r"{\VerdanaBold10}%s" % title)
  266. def back(self, title, next, name = "Back", active = 1):
  267. """Add a back button with a given title, the tab-next button,
  268. its name in the Control table, possibly initially disabled.
  269. Return the button, so that events can be associated"""
  270. if active:
  271. flags = 3 # Visible|Enabled
  272. else:
  273. flags = 1 # Visible
  274. return self.pushbutton(name, 180, self.h-27 , 56, 17, flags, title, next)
  275. def cancel(self, title, next, name = "Cancel", active = 1):
  276. """Add a cancel button with a given title, the tab-next button,
  277. its name in the Control table, possibly initially disabled.
  278. Return the button, so that events can be associated"""
  279. if active:
  280. flags = 3 # Visible|Enabled
  281. else:
  282. flags = 1 # Visible
  283. return self.pushbutton(name, 304, self.h-27, 56, 17, flags, title, next)
  284. def next(self, title, next, name = "Next", active = 1):
  285. """Add a Next button with a given title, the tab-next button,
  286. its name in the Control table, possibly initially disabled.
  287. Return the button, so that events can be associated"""
  288. if active:
  289. flags = 3 # Visible|Enabled
  290. else:
  291. flags = 1 # Visible
  292. return self.pushbutton(name, 236, self.h-27, 56, 17, flags, title, next)
  293. def xbutton(self, name, title, next, xpos):
  294. """Add a button with a given title, the tab-next button,
  295. its name in the Control table, giving its x position; the
  296. y-position is aligned with the other buttons.
  297. Return the button, so that events can be associated"""
  298. return self.pushbutton(name, int(self.w*xpos - 28), self.h-27, 56, 17, 3, title, next)
  299. def add_ui(db):
  300. x = y = 50
  301. w = 370
  302. h = 300
  303. title = "[ProductName] Setup"
  304. # see "Dialog Style Bits"
  305. modal = 3 # visible | modal
  306. modeless = 1 # visible
  307. track_disk_space = 32
  308. add_data(db, 'ActionText', uisample.ActionText)
  309. add_data(db, 'UIText', uisample.UIText)
  310. # Bitmaps
  311. if not os.path.exists(srcdir+r"\PC\python_icon.exe"):
  312. raise "Run icons.mak in PC directory"
  313. add_data(db, "Binary",
  314. [("PythonWin", msilib.Binary(r"%s\PCbuild\installer.bmp" % srcdir)), # 152x328 pixels
  315. ("py.ico",msilib.Binary(srcdir+r"\PC\py.ico")),
  316. ])
  317. add_data(db, "Icon",
  318. [("python_icon.exe", msilib.Binary(srcdir+r"\PC\python_icon.exe"))])
  319. # Scripts
  320. # CheckDir sets TargetExists if TARGETDIR exists.
  321. # UpdateEditIDLE sets the REGISTRY.tcl component into
  322. # the installed/uninstalled state according to both the
  323. # Extensions and TclTk features.
  324. if os.system("nmake /nologo /c /f msisupport.mak") != 0:
  325. raise "'nmake /f msisupport.mak' failed"
  326. add_data(db, "Binary", [("Script", msilib.Binary("msisupport.dll"))])
  327. # See "Custom Action Type 1"
  328. if msilib.Win64:
  329. CheckDir = "CheckDir"
  330. UpdateEditIDLE = "UpdateEditIDLE"
  331. else:
  332. CheckDir = "_CheckDir@4"
  333. UpdateEditIDLE = "_UpdateEditIDLE@4"
  334. add_data(db, "CustomAction",
  335. [("CheckDir", 1, "Script", CheckDir)])
  336. if have_tcl:
  337. add_data(db, "CustomAction",
  338. [("UpdateEditIDLE", 1, "Script", UpdateEditIDLE)])
  339. # UI customization properties
  340. add_data(db, "Property",
  341. # See "DefaultUIFont Property"
  342. [("DefaultUIFont", "DlgFont8"),
  343. # See "ErrorDialog Style Bit"
  344. ("ErrorDialog", "ErrorDlg"),
  345. ("Progress1", "Install"), # modified in maintenance type dlg
  346. ("Progress2", "installs"),
  347. ("MaintenanceForm_Action", "Repair")])
  348. # Fonts, see "TextStyle Table"
  349. add_data(db, "TextStyle",
  350. [("DlgFont8", "Tahoma", 9, None, 0),
  351. ("DlgFontBold8", "Tahoma", 8, None, 1), #bold
  352. ("VerdanaBold10", "Verdana", 10, None, 1),
  353. ("VerdanaRed9", "Verdana", 9, 255, 0),
  354. ])
  355. compileargs = r'-Wi "[TARGETDIR]Lib\compileall.py" -f -x bad_coding|badsyntax|site-packages|py3_ "[TARGETDIR]Lib"'
  356. lib2to3args = r'-c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"'
  357. # See "CustomAction Table"
  358. add_data(db, "CustomAction", [
  359. # msidbCustomActionTypeFirstSequence + msidbCustomActionTypeTextData + msidbCustomActionTypeProperty
  360. # See "Custom Action Type 51",
  361. # "Custom Action Execution Scheduling Options"
  362. ("InitialTargetDir", 307, "TARGETDIR",
  363. "[WindowsVolume]Python%s%s" % (major, minor)),
  364. ("SetDLLDirToTarget", 307, "DLLDIR", "[TARGETDIR]"),
  365. ("SetDLLDirToSystem32", 307, "DLLDIR", SystemFolderName),
  366. # msidbCustomActionTypeExe + msidbCustomActionTypeSourceFile
  367. # See "Custom Action Type 18"
  368. ("CompilePyc", 18, "python.exe", compileargs),
  369. ("CompilePyo", 18, "python.exe", "-O "+compileargs),
  370. ("CompileGrammar", 18, "python.exe", lib2to3args),
  371. ])
  372. # UI Sequences, see "InstallUISequence Table", "Using a Sequence Table"
  373. # Numbers indicate sequence; see sequence.py for how these action integrate
  374. add_data(db, "InstallUISequence",
  375. [("PrepareDlg", "Not Privileged or Windows9x or Installed", 140),
  376. ("WhichUsersDlg", "Privileged and not Windows9x and not Installed", 141),
  377. ("InitialTargetDir", 'TARGETDIR=""', 750),
  378. # In the user interface, assume all-users installation if privileged.
  379. ("SetDLLDirToSystem32", 'DLLDIR="" and ' + sys32cond, 751),
  380. ("SetDLLDirToTarget", 'DLLDIR="" and not ' + sys32cond, 752),
  381. ("SelectDirectoryDlg", "Not Installed", 1230),
  382. # XXX no support for resume installations yet
  383. #("ResumeDlg", "Installed AND (RESUME OR Preselected)", 1240),
  384. ("MaintenanceTypeDlg", "Installed AND NOT RESUME AND NOT Preselected", 1250),
  385. ("ProgressDlg", None, 1280)])
  386. add_data(db, "AdminUISequence",
  387. [("InitialTargetDir", 'TARGETDIR=""', 750),
  388. ("SetDLLDirToTarget", 'DLLDIR=""', 751),
  389. ])
  390. # Execute Sequences
  391. add_data(db, "InstallExecuteSequence",
  392. [("InitialTargetDir", 'TARGETDIR=""', 750),
  393. ("SetDLLDirToSystem32", 'DLLDIR="" and ' + sys32cond, 751),
  394. ("SetDLLDirToTarget", 'DLLDIR="" and not ' + sys32cond, 752),
  395. ("UpdateEditIDLE", None, 1050),
  396. ("CompilePyc", "COMPILEALL", 6800),
  397. ("CompilePyo", "COMPILEALL", 6801),
  398. ("CompileGrammar", "COMPILEALL", 6802),
  399. ])
  400. add_data(db, "AdminExecuteSequence",
  401. [("InitialTargetDir", 'TARGETDIR=""', 750),
  402. ("SetDLLDirToTarget", 'DLLDIR=""', 751),
  403. ("CompilePyc", "COMPILEALL", 6800),
  404. ("CompilePyo", "COMPILEALL", 6801),
  405. ("CompileGrammar", "COMPILEALL", 6802),
  406. ])
  407. #####################################################################
  408. # Standard dialogs: FatalError, UserExit, ExitDialog
  409. fatal=PyDialog(db, "FatalError", x, y, w, h, modal, title,
  410. "Finish", "Finish", "Finish")
  411. fatal.title("[ProductName] Installer ended prematurely")
  412. fatal.back("< Back", "Finish", active = 0)
  413. fatal.cancel("Cancel", "Back", active = 0)
  414. fatal.text("Description1", 135, 70, 220, 80, 0x30003,
  415. "[ProductName] setup ended prematurely because of an error. Your system has not been modified. To install this program at a later time, please run the installation again.")
  416. fatal.text("Description2", 135, 155, 220, 20, 0x30003,
  417. "Click the Finish button to exit the Installer.")
  418. c=fatal.next("Finish", "Cancel", name="Finish")
  419. # See "ControlEvent Table". Parameters are the event, the parameter
  420. # to the action, and optionally the condition for the event, and the order
  421. # of events.
  422. c.event("EndDialog", "Exit")
  423. user_exit=PyDialog(db, "UserExit", x, y, w, h, modal, title,
  424. "Finish", "Finish", "Finish")
  425. user_exit.title("[ProductName] Installer was interrupted")
  426. user_exit.back("< Back", "Finish", active = 0)
  427. user_exit.cancel("Cancel", "Back", active = 0)
  428. user_exit.text("Description1", 135, 70, 220, 80, 0x30003,
  429. "[ProductName] setup was interrupted. Your system has not been modified. "
  430. "To install this program at a later time, please run the installation again.")
  431. user_exit.text("Description2", 135, 155, 220, 20, 0x30003,
  432. "Click the Finish button to exit the Installer.")
  433. c = user_exit.next("Finish", "Cancel", name="Finish")
  434. c.event("EndDialog", "Exit")
  435. exit_dialog = PyDialog(db, "ExitDialog", x, y, w, h, modal, title,
  436. "Finish", "Finish", "Finish")
  437. exit_dialog.title("Completing the [ProductName] Installer")
  438. exit_dialog.back("< Back", "Finish", active = 0)
  439. exit_dialog.cancel("Cancel", "Back", active = 0)
  440. exit_dialog.text("Acknowledgements", 135, 95, 220, 120, 0x30003,
  441. "Special Windows thanks to:\n"
  442. " Mark Hammond, without whose years of freely \n"
  443. " shared Windows expertise, Python for Windows \n"
  444. " would still be Python for DOS.")
  445. c = exit_dialog.text("warning", 135, 200, 220, 40, 0x30003,
  446. "{\\VerdanaRed9}Warning: Python 2.5.x is the last "
  447. "Python release for Windows 9x.")
  448. c.condition("Hide", "NOT Version9X")
  449. exit_dialog.text("Description", 135, 235, 220, 20, 0x30003,
  450. "Click the Finish button to exit the Installer.")
  451. c = exit_dialog.next("Finish", "Cancel", name="Finish")
  452. c.event("EndDialog", "Return")
  453. #####################################################################
  454. # Required dialog: FilesInUse, ErrorDlg
  455. inuse = PyDialog(db, "FilesInUse",
  456. x, y, w, h,
  457. 19, # KeepModeless|Modal|Visible
  458. title,
  459. "Retry", "Retry", "Retry", bitmap=False)
  460. inuse.text("Title", 15, 6, 200, 15, 0x30003,
  461. r"{\DlgFontBold8}Files in Use")
  462. inuse.text("Description", 20, 23, 280, 20, 0x30003,
  463. "Some files that need to be updated are currently in use.")
  464. inuse.text("Text", 20, 55, 330, 50, 3,
  465. "The following applications are using files that need to be updated by this setup. Close these applications and then click Retry to continue the installation or Cancel to exit it.")
  466. inuse.control("List", "ListBox", 20, 107, 330, 130, 7, "FileInUseProcess",
  467. None, None, None)
  468. c=inuse.back("Exit", "Ignore", name="Exit")
  469. c.event("EndDialog", "Exit")
  470. c=inuse.next("Ignore", "Retry", name="Ignore")
  471. c.event("EndDialog", "Ignore")
  472. c=inuse.cancel("Retry", "Exit", name="Retry")
  473. c.event("EndDialog","Retry")
  474. # See "Error Dialog". See "ICE20" for the required names of the controls.
  475. error = Dialog(db, "ErrorDlg",
  476. 50, 10, 330, 101,
  477. 65543, # Error|Minimize|Modal|Visible
  478. title,
  479. "ErrorText", None, None)
  480. error.text("ErrorText", 50,9,280,48,3, "")
  481. error.control("ErrorIcon", "Icon", 15, 9, 24, 24, 5242881, None, "py.ico", None, None)
  482. error.pushbutton("N",120,72,81,21,3,"No",None).event("EndDialog","ErrorNo")
  483. error.pushbutton("Y",240,72,81,21,3,"Yes",None).event("EndDialog","ErrorYes")
  484. error.pushbutton("A",0,72,81,21,3,"Abort",None).event("EndDialog","ErrorAbort")
  485. error.pushbutton("C",42,72,81,21,3,"Cancel",None).event("EndDialog","ErrorCancel")
  486. error.pushbutton("I",81,72,81,21,3,"Ignore",None).event("EndDialog","ErrorIgnore")
  487. error.pushbutton("O",159,72,81,21,3,"Ok",None).event("EndDialog","ErrorOk")
  488. error.pushbutton("R",198,72,81,21,3,"Retry",None).event("EndDialog","ErrorRetry")
  489. #####################################################################
  490. # Global "Query Cancel" dialog
  491. cancel = Dialog(db, "CancelDlg", 50, 10, 260, 85, 3, title,
  492. "No", "No", "No")
  493. cancel.text("Text", 48, 15, 194, 30, 3,
  494. "Are you sure you want to cancel [ProductName] installation?")
  495. cancel.control("Icon", "Icon", 15, 15, 24, 24, 5242881, None,
  496. "py.ico", None, None)
  497. c=cancel.pushbutton("Yes", 72, 57, 56, 17, 3, "Yes", "No")
  498. c.event("EndDialog", "Exit")
  499. c=cancel.pushbutton("No", 132, 57, 56, 17, 3, "No", "Yes")
  500. c.event("EndDialog", "Return")
  501. #####################################################################
  502. # Global "Wait for costing" dialog
  503. costing = Dialog(db, "WaitForCostingDlg", 50, 10, 260, 85, modal, title,
  504. "Return", "Return", "Return")
  505. costing.text("Text", 48, 15, 194, 30, 3,
  506. "Please wait while the installer finishes determining your disk space requirements.")
  507. costing.control("Icon", "Icon", 15, 15, 24, 24, 5242881, None,
  508. "py.ico", None, None)
  509. c = costing.pushbutton("Return", 102, 57, 56, 17, 3, "Return", None)
  510. c.event("EndDialog", "Exit")
  511. #####################################################################
  512. # Preparation dialog: no user input except cancellation
  513. prep = PyDialog(db, "PrepareDlg", x, y, w, h, modeless, title,
  514. "Cancel", "Cancel", "Cancel")
  515. prep.text("Description", 135, 70, 220, 40, 0x30003,
  516. "Please wait while the Installer prepares to guide you through the installation.")
  517. prep.title("Welcome to the [ProductName] Installer")
  518. c=prep.text("ActionText", 135, 110, 220, 20, 0x30003, "Pondering...")
  519. c.mapping("ActionText", "Text")
  520. c=prep.text("ActionData", 135, 135, 220, 30, 0x30003, None)
  521. c.mapping("ActionData", "Text")
  522. prep.back("Back", None, active=0)
  523. prep.next("Next", None, active=0)
  524. c=prep.cancel("Cancel", None)
  525. c.event("SpawnDialog", "CancelDlg")
  526. #####################################################################
  527. # Target directory selection
  528. seldlg = PyDialog(db, "SelectDirectoryDlg", x, y, w, h, modal, title,
  529. "Next", "Next", "Cancel")
  530. seldlg.title("Select Destination Directory")
  531. c = seldlg.text("Existing", 135, 25, 235, 30, 0x30003,
  532. "{\VerdanaRed9}This update will replace your existing [ProductLine] installation.")
  533. c.condition("Hide", 'REMOVEOLDVERSION="" and REMOVEOLDSNAPSHOT=""')
  534. seldlg.text("Description", 135, 50, 220, 40, 0x30003,
  535. "Please select a directory for the [ProductName] files.")
  536. seldlg.back("< Back", None, active=0)
  537. c = seldlg.next("Next >", "Cancel")
  538. c.event("DoAction", "CheckDir", "TargetExistsOk<>1", order=1)
  539. # If the target exists, but we found that we are going to remove old versions, don't bother
  540. # confirming that the target directory exists. Strictly speaking, we should determine that
  541. # the target directory is indeed the target of the product that we are going to remove, but
  542. # I don't know how to do that.
  543. c.event("SpawnDialog", "ExistingDirectoryDlg", 'TargetExists=1 and REMOVEOLDVERSION="" and REMOVEOLDSNAPSHOT=""', 2)
  544. c.event("SetTargetPath", "TARGETDIR", 'TargetExists=0 or REMOVEOLDVERSION<>"" or REMOVEOLDSNAPSHOT<>""', 3)
  545. c.event("SpawnWaitDialog", "WaitForCostingDlg", "CostingComplete=1", 4)
  546. c.event("NewDialog", "SelectFeaturesDlg", 'TargetExists=0 or REMOVEOLDVERSION<>"" or REMOVEOLDSNAPSHOT<>""', 5)
  547. c = seldlg.cancel("Cancel", "DirectoryCombo")
  548. c.event("SpawnDialog", "CancelDlg")
  549. seldlg.control("DirectoryCombo", "DirectoryCombo", 135, 70, 172, 80, 393219,
  550. "TARGETDIR", None, "DirectoryList", None)
  551. seldlg.control("DirectoryList", "DirectoryList", 135, 90, 208, 136, 3, "TARGETDIR",
  552. None, "PathEdit", None)
  553. seldlg.control("PathEdit", "PathEdit", 135, 230, 206, 16, 3, "TARGETDIR", None, "Next", None)
  554. c = seldlg.pushbutton("Up", 306, 70, 18, 18, 3, "Up", None)
  555. c.event("DirectoryListUp", "0")
  556. c = seldlg.pushbutton("NewDir", 324, 70, 30, 18, 3, "New", None)
  557. c.event("DirectoryListNew", "0")
  558. #####################################################################
  559. # SelectFeaturesDlg
  560. features = PyDialog(db, "SelectFeaturesDlg", x, y, w, h, modal|track_disk_space,
  561. title, "Tree", "Next", "Cancel")
  562. features.title("Customize [ProductName]")
  563. features.text("Description", 135, 35, 220, 15, 0x30003,
  564. "Select the way you want features to be installed.")
  565. features.text("Text", 135,45,220,30, 3,
  566. "Click on the icons in the tree below to change the way features will be installed.")
  567. c=features.back("< Back", "Next")
  568. c.event("NewDialog", "SelectDirectoryDlg")
  569. c=features.next("Next >", "Cancel")
  570. c.mapping("SelectionNoItems", "Enabled")
  571. c.event("SpawnDialog", "DiskCostDlg", "OutOfDiskSpace=1", order=1)
  572. c.event("EndDialog", "Return", "OutOfDiskSpace<>1", order=2)
  573. c=features.cancel("Cancel", "Tree")
  574. c.event("SpawnDialog", "CancelDlg")
  575. # The browse property is not used, since we have only a single target path (selected already)
  576. features.control("Tree", "SelectionTree", 135, 75, 220, 95, 7, "_BrowseProperty",
  577. "Tree of selections", "Back", None)
  578. #c=features.pushbutton("Reset", 42, 243, 56, 17, 3, "Reset", "DiskCost")
  579. #c.mapping("SelectionNoItems", "Enabled")
  580. #c.event("Reset", "0")
  581. features.control("Box", "GroupBox", 135, 170, 225, 90, 1, None, None, None, None)
  582. c=features.xbutton("DiskCost", "Disk &Usage", None, 0.10)
  583. c.mapping("SelectionNoItems","Enabled")
  584. c.event("SpawnDialog", "DiskCostDlg")
  585. c=features.xbutton("Advanced", "Advanced", None, 0.30)
  586. c.event("SpawnDialog", "AdvancedDlg")
  587. c=features.text("ItemDescription", 140, 180, 210, 30, 3,
  588. "Multiline description of the currently selected item.")
  589. c.mapping("SelectionDescription","Text")
  590. c=features.text("ItemSize", 140, 210, 210, 45, 3,
  591. "The size of the currently selected item.")
  592. c.mapping("SelectionSize", "Text")
  593. #####################################################################
  594. # Disk cost
  595. cost = PyDialog(db, "DiskCostDlg", x, y, w, h, modal, title,
  596. "OK", "OK", "OK", bitmap=False)
  597. cost.text("Title", 15, 6, 200, 15, 0x30003,
  598. "{\DlgFontBold8}Disk Space Requirements")
  599. cost.text("Description", 20, 20, 280, 20, 0x30003,
  600. "The disk space required for the installation of the selected features.")
  601. cost.text("Text", 20, 53, 330, 60, 3,
  602. "The highlighted volumes (if any) do not have enough disk space "
  603. "available for the currently selected features. You can either "
  604. "remove some files from the highlighted volumes, or choose to "
  605. "install less features onto local drive(s), or select different "
  606. "destination drive(s).")
  607. cost.control("VolumeList", "VolumeCostList", 20, 100, 330, 150, 393223,
  608. None, "{120}{70}{70}{70}{70}", None, None)
  609. cost.xbutton("OK", "Ok", None, 0.5).event("EndDialog", "Return")
  610. #####################################################################
  611. # WhichUsers Dialog. Only available on NT, and for privileged users.
  612. # This must be run before FindRelatedProducts, because that will
  613. # take into account whether the previous installation was per-user
  614. # or per-machine. We currently don't support going back to this
  615. # dialog after "Next" was selected; to support this, we would need to
  616. # find how to reset the ALLUSERS property, and how to re-run
  617. # FindRelatedProducts.
  618. # On Windows9x, the ALLUSERS property is ignored on the command line
  619. # and in the Property table, but installer fails according to the documentation
  620. # if a dialog attempts to set ALLUSERS.
  621. whichusers = PyDialog(db, "WhichUsersDlg", x, y, w, h, modal, title,
  622. "AdminInstall", "Next", "Cancel")
  623. whichusers.title("Select whether to install [ProductName] for all users of this computer.")
  624. # A radio group with two options: allusers, justme
  625. g = whichusers.radiogroup("AdminInstall", 135, 60, 235, 80, 3,
  626. "WhichUsers", "", "Next")
  627. g.condition("Disable", "VersionNT=600") # Not available on Vista and Windows 2008
  628. g.add("ALL", 0, 5, 150, 20, "Install for all users")
  629. g.add("JUSTME", 0, 25, 235, 20, "Install just for me (not available on Windows Vista)")
  630. whichusers.back("Back", None, active=0)
  631. c = whichusers.next("Next >", "Cancel")
  632. c.event("[ALLUSERS]", "1", 'WhichUsers="ALL"', 1)
  633. c.event("EndDialog", "Return", order = 2)
  634. c = whichusers.cancel("Cancel", "AdminInstall")
  635. c.event("SpawnDialog", "CancelDlg")
  636. #####################################################################
  637. # Advanced Dialog.
  638. advanced = PyDialog(db, "AdvancedDlg", x, y, w, h, modal, title,
  639. "CompilePyc", "Ok", "Ok")
  640. advanced.title("Advanced Options for [ProductName]")
  641. # A radio group with two options: allusers, justme
  642. advanced.checkbox("CompilePyc", 135, 60, 230, 50, 3,
  643. "COMPILEALL", "Compile .py files to byte code after installation", "Ok")
  644. c = advanced.cancel("Ok", "CompilePyc", name="Ok") # Button just has location of cancel button.
  645. c.event("EndDialog", "Return")
  646. #####################################################################
  647. # Existing Directory dialog
  648. dlg = Dialog(db, "ExistingDirectoryDlg", 50, 30, 200, 80, modal, title,
  649. "No", "No", "No")
  650. dlg.text("Title", 10, 20, 180, 40, 3,
  651. "[TARGETDIR] exists. Are you sure you want to overwrite existing files?")
  652. c=dlg.pushbutton("Yes", 30, 60, 55, 17, 3, "Yes", "No")
  653. c.event("[TargetExists]", "0", order=1)
  654. c.event("[TargetExistsOk]", "1", order=2)
  655. c.event("EndDialog", "Return", order=3)
  656. c=dlg.pushbutton("No", 115, 60, 55, 17, 3, "No", "Yes")
  657. c.event("EndDialog", "Return")
  658. #####################################################################
  659. # Installation Progress dialog (modeless)
  660. progress = PyDialog(db, "ProgressDlg", x, y, w, h, modeless, title,
  661. "Cancel", "Cancel", "Cancel", bitmap=False)
  662. progress.text("Title", 20, 15, 200, 15, 0x30003,
  663. "{\DlgFontBold8}[Progress1] [ProductName]")
  664. progress.text("Text", 35, 65, 300, 30, 3,
  665. "Please wait while the Installer [Progress2] [ProductName]. "
  666. "This may take several minutes.")
  667. progress.text("StatusLabel", 35, 100, 35, 20, 3, "Status:")
  668. c=progress.text("ActionText", 70, 100, w-70, 20, 3, "Pondering...")
  669. c.mapping("ActionText", "Text")
  670. #c=progress.text("ActionData", 35, 140, 300, 20, 3, None)
  671. #c.mapping("ActionData", "Text")
  672. c=progress.control("ProgressBar", "ProgressBar", 35, 120, 300, 10, 65537,
  673. None, "Progress done", None, None)
  674. c.mapping("SetProgress", "Progress")
  675. progress.back("< Back", "Next", active=False)
  676. progress.next("Next >", "Cancel", active=False)
  677. progress.cancel("Cancel", "Back").event("SpawnDialog", "CancelDlg")
  678. # Maintenance type: repair/uninstall
  679. maint = PyDialog(db, "MaintenanceTypeDlg", x, y, w, h, modal, title,
  680. "Next", "Next", "Cancel")
  681. maint.title("Welcome to the [ProductName] Setup Wizard")
  682. maint.text("BodyText", 135, 63, 230, 42, 3,
  683. "Select whether you want to repair or remove [ProductName].")
  684. g=maint.radiogroup("RepairRadioGroup", 135, 108, 230, 60, 3,
  685. "MaintenanceForm_Action", "", "Next")
  686. g.add("Change", 0, 0, 200, 17, "&Change [ProductName]")
  687. g.add("Repair", 0, 18, 200, 17, "&Repair [ProductName]")
  688. g.add("Remove", 0, 36, 200, 17, "Re&move [ProductName]")
  689. maint.back("< Back", None, active=False)
  690. c=maint.next("Finish", "Cancel")
  691. # Change installation: Change progress dialog to "Change", then ask
  692. # for feature selection
  693. c.event("[Progress1]", "Change", 'MaintenanceForm_Action="Change"', 1)
  694. c.event("[Progress2]", "changes", 'MaintenanceForm_Action="Change"', 2)
  695. # Reinstall: Change progress dialog to "Repair", then invoke reinstall
  696. # Also set list of reinstalled features to "ALL"
  697. c.event("[REINSTALL]", "ALL", 'MaintenanceForm_Action="Repair"', 5)
  698. c.event("[Progress1]", "Repairing", 'MaintenanceForm_Action="Repair"', 6)
  699. c.event("[Progress2]", "repairs", 'MaintenanceForm_Action="Repair"', 7)
  700. c.event("Reinstall", "ALL", 'MaintenanceForm_Action="Repair"', 8)
  701. # Uninstall: Change progress to "Remove", then invoke uninstall
  702. # Also set list of removed features to "ALL"
  703. c.event("[REMOVE]", "ALL", 'MaintenanceForm_Action="Remove"', 11)
  704. c.event("[Progress1]", "Removing", 'MaintenanceForm_Action="Remove"', 12)
  705. c.event("[Progress2]", "removes", 'MaintenanceForm_Action="Remove"', 13)
  706. c.event("Remove", "ALL", 'MaintenanceForm_Action="Remove"', 14)
  707. # Close dialog when maintenance action scheduled
  708. c.event("EndDialog", "Return", 'MaintenanceForm_Action<>"Change"', 20)
  709. c.event("NewDialog", "SelectFeaturesDlg", 'MaintenanceForm_Action="Change"', 21)
  710. maint.cancel("Cancel", "RepairRadioGroup").event("SpawnDialog", "CancelDlg")
  711. # See "Feature Table". The feature level is 1 for all features,
  712. # and the feature attributes are 0 for the DefaultFeature, and
  713. # FollowParent for all other features. The numbers are the Display
  714. # column.
  715. def add_features(db):
  716. # feature attributes:
  717. # msidbFeatureAttributesFollowParent == 2
  718. # msidbFeatureAttributesDisallowAdvertise == 8
  719. # Features that need to be installed with together with the main feature
  720. # (i.e. additional Python libraries) need to follow the parent feature.
  721. # Features that have no advertisement trigger (e.g. the test suite)
  722. # must not support advertisement
  723. global default_feature, tcltk, htmlfiles, tools, testsuite, ext_feature, private_crt
  724. default_feature = Feature(db, "DefaultFeature", "Python",
  725. "Python Interpreter and Libraries",
  726. 1, directory = "TARGETDIR")
  727. shared_crt = Feature(db, "SharedCRT", "MSVCRT", "C Run-Time (system-wide)", 0,
  728. level=0)
  729. private_crt = Feature(db, "PrivateCRT", "MSVCRT", "C Run-Time (private)", 0,
  730. level=0)
  731. add_data(db, "Condition", [("SharedCRT", 1, sys32cond),
  732. ("PrivateCRT", 1, "not "+sys32cond)])
  733. # We don't support advertisement of extensions
  734. ext_feature = Feature(db, "Extensions", "Register Extensions",
  735. "Make this Python installation the default Python installation", 3,
  736. parent = default_feature, attributes=2|8)
  737. if have_tcl:
  738. tcltk = Feature(db, "TclTk", "Tcl/Tk", "Tkinter, IDLE, pydoc", 5,
  739. parent = default_feature, attributes=2)
  740. htmlfiles = Feature(db, "Documentation", "Documentation",
  741. "Python HTMLHelp File", 7, parent = default_feature)
  742. tools = Feature(db, "Tools", "Utility Scripts",
  743. "Python utility scripts (Tools/", 9,
  744. parent = default_feature, attributes=2)
  745. testsuite = Feature(db, "Testsuite", "Test suite",
  746. "Python test suite (Lib/test/)", 11,
  747. parent = default_feature, attributes=2|8)
  748. def extract_msvcr90():
  749. # Find the redistributable files
  750. if msilib.Win64:
  751. arch = "amd64"
  752. else:
  753. arch = "x86"
  754. dir = os.path.join(os.environ['VS90COMNTOOLS'], r"..\..\VC\redist\%s\Microsoft.VC90.CRT" % arch)
  755. result = []
  756. installer = msilib.MakeInstaller()
  757. # omit msvcm90 and msvcp90, as they aren't really needed
  758. files = ["Microsoft.VC90.CRT.manifest", "msvcr90.dll"]
  759. for f in files:
  760. path = os.path.join(dir, f)
  761. kw = {'src':path}
  762. if f.endswith('.dll'):
  763. kw['version'] = installer.FileVersion(path, 0)
  764. kw['language'] = installer.FileVersion(path, 1)
  765. result.append((f, kw))
  766. return result
  767. def generate_license():
  768. import shutil, glob
  769. out = open("LICENSE.txt", "w")
  770. shutil.copyfileobj(open(os.path.join(srcdir, "LICENSE")), out)
  771. shutil.copyfileobj(open("crtlicense.txt"), out)
  772. for name, pat, file in (("bzip2","bzip2-*", "LICENSE"),
  773. ("Berkeley DB", "db-*", "LICENSE"),
  774. ("openssl", "openssl-*", "LICENSE"),
  775. ("Tcl", "tcl8*", "license.terms"),
  776. ("Tk", "tk8*", "license.terms"),
  777. ("Tix", "tix-*", "license.terms")):
  778. out.write("\nThis copy of Python includes a copy of %s, which is licensed under the following terms:\n\n" % name)
  779. dirs = glob.glob(srcdir+"/../"+pat)
  780. if not dirs:
  781. raise ValueError, "Could not find "+srcdir+"/../"+pat
  782. if len(dirs) > 2:
  783. raise ValueError, "Multiple copies of "+pat
  784. dir = dirs[0]
  785. shutil.copyfileobj(open(os.path.join(dir, file)), out)
  786. out.close()
  787. class PyDirectory(Directory):
  788. """By default, all components in the Python installer
  789. can run from source."""
  790. def __init__(self, *args, **kw):
  791. if not kw.has_key("componentflags"):
  792. kw['componentflags'] = 2 #msidbComponentAttributesOptional
  793. Directory.__init__(self, *args, **kw)
  794. # See "File Table", "Component Table", "Directory Table",
  795. # "FeatureComponents Table"
  796. def add_files(db):
  797. cab = CAB("python")
  798. tmpfiles = []
  799. # Add all executables, icons, text files into the TARGETDIR component
  800. root = PyDirectory(db, cab, None, srcdir, "TARGETDIR", "SourceDir")
  801. default_feature.set_current()
  802. if not msilib.Win64:
  803. root.add_file("%s/w9xpopen.exe" % PCBUILD)
  804. root.add_file("README.txt", src="README")
  805. root.add_file("NEWS.txt", src="Misc/NEWS")
  806. generate_license()
  807. root.add_file("LICENSE.txt", src=os.path.abspath("LICENSE.txt"))
  808. root.start_component("python.exe", keyfile="python.exe")
  809. root.add_file("%s/python.exe" % PCBUILD)
  810. root.start_component("pythonw.exe", keyfile="pythonw.exe")
  811. root.add_file("%s/pythonw.exe" % PCBUILD)
  812. # msidbComponentAttributesSharedDllRefCount = 8, see "Component Table"
  813. dlldir = PyDirectory(db, cab, root, srcdir, "DLLDIR", ".")
  814. pydll = "python%s%s.dll" % (major, minor)
  815. pydllsrc = os.path.join(srcdir, PCBUILD, pydll)
  816. dlldir.start_component("DLLDIR", flags = 8, keyfile = pydll, uuid = pythondll_uuid)
  817. installer = msilib.MakeInstaller()
  818. pyversion = installer.FileVersion(pydllsrc, 0)
  819. if not snapshot:
  820. # For releases, the Python DLL has the same version as the
  821. # installer package.
  822. assert pyversion.split(".")[:3] == current_version.split(".")
  823. dlldir.add_file("%s/python%s%s.dll" % (PCBUILD, major, minor),
  824. version=pyversion,
  825. language=installer.FileVersion(pydllsrc, 1))
  826. DLLs = PyDirectory(db, cab, root, srcdir + "/" + PCBUILD, "DLLs", "DLLS|DLLs")
  827. # msvcr90.dll: Need to place the DLL and the manifest into the root directory,
  828. # plus another copy of the manifest in the DLLs directory, with the manifest
  829. # pointing to the root directory
  830. root.start_component("msvcr90", feature=private_crt)
  831. # Results are ID,keyword pairs
  832. manifest, crtdll = extract_msvcr90()
  833. root.add_file(manifest[0], **manifest[1])
  834. root.add_file(crtdll[0], **crtdll[1])
  835. # Copy the manifest
  836. # Actually, don't do that anymore - no DLL in DLLs should have a manifest
  837. # dependency on msvcr90.dll anymore, so this should not be necessary
  838. #manifest_dlls = manifest[0]+".root"
  839. #open(manifest_dlls, "w").write(open(manifest[1]['src']).read().replace("msvcr","../msvcr"))
  840. #DLLs.start_component("msvcr90_dlls", feature=private_crt)
  841. #DLLs.add_file(manifest[0], src=os.path.abspath(manifest_dlls))
  842. # Now start the main component for the DLLs directory;
  843. # no regular files have been added to the directory yet.
  844. DLLs.start_component()
  845. # Check if _ctypes.pyd exists
  846. have_ctypes = os.path.exists(srcdir+"/%s/_ctypes.pyd" % PCBUILD)
  847. if not have_ctypes:
  848. print "WARNING: _ctypes.pyd not found, ctypes will not be included"
  849. extensions.remove("_ctypes.pyd")
  850. # Add all .py files in Lib, except lib-tk, test
  851. dirs={}
  852. pydirs = [(root,"Lib")]
  853. while pydirs:
  854. # Commit every now and then, or else installer will complain
  855. db.Commit()
  856. parent, dir = pydirs.pop()
  857. if dir == ".svn" or dir.startswith("plat-"):
  858. continue
  859. elif dir in ["lib-tk", "idlelib", "Icons"]:
  860. if not have_tcl:
  861. continue
  862. tcltk.set_current()
  863. elif dir in ['test', 'tests', 'data', 'output']:
  864. # test: Lib, Lib/email, Lib/bsddb, Lib/ctypes, Lib/sqlite3
  865. # tests: Lib/distutils
  866. # data: Lib/email/test
  867. # output: Lib/test
  868. testsuite.set_current()
  869. elif not have_ctypes and dir == "ctypes":
  870. continue
  871. else:
  872. default_feature.set_current()
  873. lib = PyDirectory(db, cab, parent, dir, dir, "%s|%s" % (parent.make_short(dir), dir))
  874. # Add additional files
  875. dirs[dir]=lib
  876. lib.glob("*.txt")
  877. if dir=='site-packages':
  878. lib.add_file("README.txt", src="README")
  879. continue
  880. files = lib.glob("*.py")
  881. files += lib.glob("*.pyw")
  882. if files:
  883. # Add an entry to the RemoveFile table to remove bytecode files.
  884. lib.remove_pyc()
  885. if dir.endswith('.egg-info'):
  886. lib.add_file('entry_points.txt')
  887. lib.add_file('PKG-INFO')
  888. lib.add_file('top_level.txt')
  889. lib.add_file('zip-safe')
  890. continue
  891. if dir=='test' and parent.physical=='Lib':
  892. lib.add_file("185test.db")
  893. lib.add_file("audiotest.au")
  894. lib.add_file("cfgparser.1")
  895. lib.add_file("sgml_input.html")
  896. lib.add_file("test.xml")
  897. lib.add_file("test.xml.out")
  898. lib.add_file("testtar.tar")
  899. lib.add_file("test_difflib_expect.html")
  900. lib.add_file("check_soundcard.vbs")
  901. lib.add_file("empty.vbs")
  902. lib.add_file("Sine-1000Hz-300ms.aif")
  903. lib.glob("*.uue")
  904. lib.glob("*.pem")
  905. lib.glob("*.pck")
  906. lib.add_file("readme.txt", src="README")
  907. lib.add_file("zipdir.zip")
  908. if dir=='decimaltestdata':
  909. lib.glob("*.decTest")
  910. if dir=='output':
  911. lib.glob("test_*")
  912. if dir=='idlelib':
  913. lib.glob("*.def")
  914. lib.add_file("idle.bat")
  915. if dir=="Icons":
  916. lib.glob("*.gif")
  917. lib.add_file("idle.icns")
  918. if dir=="command" and parent.physical=="distutils":
  919. lib.glob("wininst*.exe")
  920. if dir=="setuptools":
  921. lib.add_file("cli.exe")
  922. lib.add_file("gui.exe")
  923. if dir=="lib2to3":
  924. lib.removefile("pickle", "*.pickle")
  925. if dir=="data" and parent.physical=="test" and parent.basedir.physical=="email":
  926. # This should contain all non-.svn files listed in subversion
  927. for f in os.listdir(lib.absolute):
  928. if f.endswith(".txt") or f==".svn":continue
  929. if f.endswith(".au") or f.endswith(".gif"):
  930. lib.add_file(f)
  931. else:
  932. print "WARNING: New file %s in email/test/data" % f
  933. for f in os.listdir(lib.absolute):
  934. if os.path.isdir(os.path.join(lib.absolute, f)):
  935. pydirs.append((lib, f))
  936. # Add DLLs
  937. default_feature.set_current()
  938. lib = DLLs
  939. lib.add_file("py.ico", src=srcdir+"/PC/py.ico")
  940. lib.add_file("pyc.ico", src=srcdir+"/PC/pyc.ico")
  941. dlls = []
  942. tclfiles = []
  943. for f in extensions:
  944. if f=="_tkinter.pyd":
  945. continue
  946. if not os.path.exists(srcdir + "/" + PCBUILD + "/" + f):
  947. print "WARNING: Missing extension", f
  948. continue
  949. dlls.append(f)
  950. lib.add_file(f)
  951. # Add sqlite
  952. if msilib.msi_type=="Intel64;1033":
  953. sqlite_arch = "/ia64"
  954. elif msilib.msi_type=="x64;1033":
  955. sqlite_arch = "/amd64"
  956. tclsuffix = "64"
  957. else:
  958. sqlite_arch = ""
  959. tclsuffix = ""
  960. lib.add_file("sqlite3.dll")
  961. if have_tcl:
  962. if not os.path.exists("%s/%s/_tkinter.pyd" % (srcdir, PCBUILD)):
  963. print "WARNING: Missing _tkinter.pyd"
  964. else:
  965. lib.start_component("TkDLLs", tcltk)
  966. lib.add_file("_tkinter.pyd")
  967. dlls.append("_tkinter.pyd")
  968. tcldir = os.path.normpath(srcdir+("/../tcltk%s/bin" % tclsuffix))
  969. for f in glob.glob1(tcldir, "*.dll"):
  970. lib.add_file(f, src=os.path.join(tcldir, f))
  971. # check whether there are any unknown extensions
  972. for f in glob.glob1(srcdir+"/"+PCBUILD, "*.pyd"):
  973. if f.endswith("_d.pyd"): continue # debug version
  974. if f in dlls: continue
  975. print "WARNING: Unknown extension", f
  976. # Add headers
  977. default_feature.set_current()
  978. lib = PyDirectory(db, cab, root, "include", "include", "INCLUDE|include")
  979. lib.glob("*.h")
  980. lib.add_file("pyconfig.h", src="../PC/pyconfig.h")
  981. # Add import libraries
  982. lib = PyDirectory(db, cab, root, PCBUILD, "libs", "LIBS|libs")
  983. for f in dlls:
  984. lib.add_file(f.replace('pyd','lib'))
  985. lib.add_file('python%s%s.lib' % (major, minor))
  986. # Add the mingw-format library
  987. if have_mingw:
  988. lib.add_file('libpython%s%s.a' % (major, minor))
  989. if have_tcl:
  990. # Add Tcl/Tk
  991. tcldirs = [(root, '../tcltk%s/lib' % tclsuffix, 'tcl')]
  992. tcltk.set_current()
  993. while tcldirs:
  994. parent, phys, dir = tcldirs.pop()
  995. lib = PyDirectory(db, cab, parent, phys, dir, "%s|%s" % (parent.make_short(dir), dir))
  996. if not os.path.exists(lib.absolute):
  997. continue
  998. for f in os.listdir(lib.absolute):
  999. if os.path.isdir(os.path.join(lib.absolute, f)):
  1000. tcldirs.append((lib, f, f))
  1001. else:
  1002. lib.add_file(f)
  1003. # Add tools
  1004. tools.set_current()
  1005. tooldir = PyDirectory(db, cab, root, "Tools", "Tools", "TOOLS|Tools")
  1006. for f in ['i18n', 'pynche', 'Scripts', 'versioncheck', 'webchecker']:
  1007. lib = PyDirectory(db, cab, tooldir, f, f, "%s|%s" % (tooldir.make_short(f), f))
  1008. lib.glob("*.py")
  1009. lib.glob("*.pyw", exclude=['pydocgui.pyw'])
  1010. lib.remove_pyc()
  1011. lib.glob("*.txt")
  1012. if f == "pynche":
  1013. x = PyDirectory(db, cab, lib, "X", "X", "X|X")
  1014. x.glob("*.txt")
  1015. if os.path.exists(os.path.join(lib.absolute, "README")):
  1016. lib.add_file("README.txt", src="README")
  1017. if f == 'Scripts':
  1018. lib.add_file("2to3.py", src="2to3")
  1019. if have_tcl:
  1020. lib.start_component("pydocgui.pyw", tcltk, keyfile="pydocgui.pyw")
  1021. lib.add_file("pydocgui.pyw")
  1022. # Add documentation
  1023. htmlfiles.set_current()
  1024. lib = PyDirectory(db, cab, root, "Doc", "Doc", "DOC|Doc")
  1025. lib.start_component("documentation", keyfile=docfile)
  1026. lib.add_file(docfile, src="build/htmlhelp/"+docfile)
  1027. cab.commit(db)
  1028. for f in tmpfiles:
  1029. os.unlink(f)
  1030. # See "Registry Table", "Component Table"
  1031. def add_registry(db):
  1032. # File extensions, associated with the REGISTRY.def component
  1033. # IDLE verbs depend on the tcltk feature.
  1034. # msidbComponentAttributesRegistryKeyPath = 4
  1035. # -1 for Root specifies "dependent on ALLUSERS property"
  1036. tcldata = []
  1037. if have_tcl:
  1038. tcldata = [
  1039. ("REGISTRY.tcl", msilib.gen_uuid(), "TARGETDIR", registry_component, None,
  1040. "py.IDLE")]
  1041. add_data(db, "Component",
  1042. # msidbComponentAttributesRegistryKeyPath = 4
  1043. [("REGISTRY", msilib.gen_uuid(), "TARGETDIR", registry_component, None,
  1044. "InstallPath"),
  1045. ("REGISTRY.doc", msilib.gen_uuid(), "TARGETDIR", registry_component, None,
  1046. "Documentation"),
  1047. ("REGISTRY.def", msilib.gen_uuid(), "TARGETDIR", registry_component,
  1048. None, None)] + tcldata)
  1049. # See "FeatureComponents Table".
  1050. # The association between TclTk and pythonw.exe is necessary to make ICE59
  1051. # happy, because the installer otherwise believes that the IDLE and PyDoc
  1052. # shortcuts might get installed without pythonw.exe being install. This
  1053. # is not true, since installing TclTk will install the default feature, which
  1054. # will cause pythonw.exe to be installed.
  1055. # REGISTRY.tcl is not associated with any feature, as it will be requested
  1056. # through a custom action
  1057. tcldata = []
  1058. if have_tcl:
  1059. tcldata = [(tcltk.id, "pythonw.exe")]
  1060. add_data(db, "FeatureComponents",
  1061. [(default_feature.id, "REGISTRY"),
  1062. (htmlfiles.id, "REGISTRY.doc"),
  1063. (ext_feature.id, "REGISTRY.def")] +
  1064. tcldata
  1065. )
  1066. # Extensions are not advertised. For advertised extensions,
  1067. # we would need separate binaries that install along with the
  1068. # extension.
  1069. pat = r"Software\Classes\%sPython.%sFile\shell\%s\command"
  1070. ewi = "Edit with IDLE"
  1071. pat2 = r"Software\Classes\%sPython.%sFile\DefaultIcon"
  1072. pat3 = r"Software\Classes\%sPython.%sFile"
  1073. pat4 = r"Software\Classes\%sPython.%sFile\shellex\DropHandler"
  1074. tcl_verbs = []
  1075. if have_tcl:
  1076. tcl_verbs=[
  1077. ("py.IDLE", -1, pat % (testprefix, "", ewi), "",
  1078. r'"[TARGETDIR]pythonw.exe" "[TARGETDIR]Lib\idlelib\idle.pyw" -n -e "%1"',
  1079. "REGISTRY.tcl"),
  1080. ("pyw.IDLE", -1, pat % (testprefix, "NoCon", ewi), "",
  1081. r'"[TARGETDIR]pythonw.exe" "[TARGETDIR]Lib\idlelib\idle.pyw" -n -e "%1"',
  1082. "REGISTRY.tcl"),
  1083. ]
  1084. add_data(db, "Registry",
  1085. [# Extensions
  1086. ("py.ext", -1, r"Software\Classes\."+ext, "",
  1087. "Python.File", "REGISTRY.def"),
  1088. ("pyw.ext", -1, r"Software\Classes\."+ext+'w', "",
  1089. "Python.NoConFile", "REGISTRY.def"),
  1090. ("pyc.ext", -1, r"Software\Classes\."+ext+'c', "",
  1091. "Python.CompiledFile", "REGISTRY.def"),
  1092. ("pyo.ext", -1, r"Software\Classes\."+ext+'o', "",
  1093. "Python.CompiledFile", "REGISTRY.def"),
  1094. # MIME types
  1095. ("py.mime", -1, r"Software\Classes\."+ext, "Content Type",
  1096. "text/plain", "REGISTRY.def"),
  1097. ("pyw.mime", -1, r"Software\Classes\."+ext+'w', "Content Type",
  1098. "text/plain", "REGISTRY.def"),
  1099. #Verbs
  1100. ("py.open", -1, pat % (testprefix, "", "open"), "",
  1101. r'"[TARGETDIR]python.exe" "%1" %*', "REGISTRY.def"),
  1102. ("pyw.open", -1, pat % (testprefix, "NoCon", "open"), "",
  1103. r'"[TARGETDIR]pythonw.exe" "%1" %*', "REGISTRY.def"),
  1104. ("pyc.open", -1, pat % (testprefix, "Compiled", "open"), "",
  1105. r'"[TARGETDIR]python.exe" "%1" %*', "REGISTRY.def"),
  1106. ] + tcl_verbs + [
  1107. #Icons
  1108. ("py.icon", -1, pat2 % (testprefix, ""), "",
  1109. r'[DLLs]py.ico', "REGISTRY.def"),
  1110. ("pyw.icon", -1, pat2 % (testprefix, "NoCon"), "",
  1111. r'[DLLs]py.ico', "REGISTRY.def"),
  1112. ("pyc.icon", -1, pat2 % (testprefix, "Compiled"), "",
  1113. r'[DLLs]pyc.ico', "REGISTRY.def"),
  1114. # Descriptions
  1115. ("py.txt", -1, pat3 % (testprefix, ""), "",
  1116. "Python File", "REGISTRY.def"),
  1117. ("pyw.txt", -1, pat3 % (testprefix, "NoCon"), "",
  1118. "Python File (no console)", "REGISTRY.def"),
  1119. ("pyc.txt", -1, pat3 % (testprefix, "Compiled"), "",
  1120. "Compiled Python File", "REGISTRY.def"),
  1121. # Drop Handler
  1122. ("py.drop", -1, pat4 % (testprefix, ""), "",
  1123. "{60254CA5-953B-11CF-8C96-00AA00B8708C}", "REGISTRY.def"),
  1124. ("pyw.drop", -1, pat4 % (testprefix, "NoCon"), "",
  1125. "{60254CA5-953B-11CF-8C96-00AA00B8708C}", "REGISTRY.def"),
  1126. ("pyc.drop", -1, pat4 % (testprefix, "Compiled"), "",
  1127. "{60254CA5-953B-11CF-8C96-00AA00B8708C}", "REGISTRY.def"),
  1128. ])
  1129. # Registry keys
  1130. prefix = r"Software\%sPython\PythonCore\%s" % (testprefix, short_version)
  1131. add_data(db, "Registry",
  1132. [("InstallPath", -1, prefix+r"\InstallPath", "", "[TARGETDIR]", "REGISTRY"),
  1133. ("InstallGroup", -1, prefix+r"\InstallPath\InstallGroup", "",
  1134. "Python %s" % short_version, "REGISTRY"),
  1135. ("PythonPath", -1, prefix+r"\PythonPath", "",
  1136. r"[TARGETDIR]Lib;[TARGETDIR]DLLs;[TARGETDIR]Lib\lib-tk", "REGISTRY"),
  1137. ("Documentation", -1, prefix+r"\Help\Main Python Documentation", "",
  1138. "[TARGETDIR]Doc\\"+docfile , "REGISTRY.doc"),
  1139. ("Modules", -1, prefix+r"\Modules", "+", None, "REGISTRY"),
  1140. ("AppPaths", -1, r"Software\Microsoft\Windows\CurrentVersion\App Paths\Python.exe",
  1141. "", r"[TARGETDIR]Python.exe", "REGISTRY.def"),
  1142. ("DisplayIcon", -1,
  1143. r"Software\Microsoft\Windows\CurrentVersion\Uninstall\%s" % product_code,
  1144. "DisplayIcon", "[TARGETDIR]python.exe", "REGISTRY")
  1145. ])
  1146. # Shortcuts, see "Shortcut Table"
  1147. add_data(db, "Directory",
  1148. [("ProgramMenuFolder", "TARGETDIR", "."),
  1149. ("MenuDir", "ProgramMenuFolder", "PY%s%s|%sPython %s.%s" % (major,minor,testprefix,major,minor))])
  1150. add_data(db, "RemoveFile",
  1151. [("MenuDir", "TARGETDIR", None, "MenuDir", 2)])
  1152. tcltkshortcuts = []
  1153. if have_tcl:
  1154. tcltkshortcuts = [
  1155. ("IDLE", "MenuDir", "IDLE|IDLE (Python GUI)", "pythonw.exe",
  1156. tcltk.id, r'"[TARGETDIR]Lib\idlelib\idle.pyw"', None, None, "python_icon.exe", 0, None, "TARGETDIR"),
  1157. ("PyDoc", "MenuDir", "MODDOCS|Module Docs", "pythonw.exe",
  1158. tcltk.id, r'"[TARGETDIR]Tools\scripts\pydocgui.pyw"', None, None, "python_icon.exe", 0, None, "TARGETDIR"),
  1159. ]
  1160. add_data(db, "Shortcut",
  1161. tcltkshortcuts +
  1162. [# Advertised shortcuts: targets are features, not files
  1163. ("Python", "MenuDir", "PYTHON|Python (command line)", "python.exe",
  1164. default_feature.id, None, None, None, "python_icon.exe", 2, None, "TARGETDIR"),
  1165. # Advertising the Manual breaks on (some?) Win98, and the shortcut lacks an
  1166. # icon first.
  1167. #("Manual", "MenuDir", "MANUAL|Python Manuals", "documentation",
  1168. # htmlfiles.id, None, None, None, None, None, None, None),
  1169. ## Non-advertised shortcuts: must be associated with a registry component
  1170. ("Manual", "MenuDir", "MANUAL|Python Manuals", "REGISTRY.doc",
  1171. "[#%s]" % docfile, None,
  1172. None, None, None, None, None, None),
  1173. ("Uninstall", "MenuDir", "UNINST|Uninstall Python", "REGISTRY",
  1174. SystemFolderName+"msiexec", "/x%s" % product_code,
  1175. None, None, None, None, None, None),
  1176. ])
  1177. db.Commit()
  1178. db = build_database()
  1179. try:
  1180. add_features(db)
  1181. add_ui(db)
  1182. add_files(db)
  1183. add_registry(db)
  1184. remove_old_versions(db)
  1185. db.Commit()
  1186. finally:
  1187. del db