PageRenderTime 56ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/lib-python/2.7/distutils/command/bdist_msi.py

https://bitbucket.org/quangquach/pypy
Python | 742 lines | 604 code | 52 blank | 86 comment | 53 complexity | 2e394cdb7f5f0c450c2da029df0f7c2f MD5 | raw file
  1. # -*- coding: iso-8859-1 -*-
  2. # Copyright (C) 2005, 2006 Martin von Löwis
  3. # Licensed to PSF under a Contributor Agreement.
  4. # The bdist_wininst command proper
  5. # based on bdist_wininst
  6. """
  7. Implements the bdist_msi command.
  8. """
  9. import sys, os
  10. from sysconfig import get_python_version
  11. from distutils.core import Command
  12. from distutils.dir_util import remove_tree
  13. from distutils.version import StrictVersion
  14. from distutils.errors import DistutilsOptionError
  15. from distutils import log
  16. from distutils.util import get_platform
  17. import msilib
  18. from msilib import schema, sequence, text
  19. from msilib import Directory, Feature, Dialog, add_data
  20. class PyDialog(Dialog):
  21. """Dialog class with a fixed layout: controls at the top, then a ruler,
  22. then a list of buttons: back, next, cancel. Optionally a bitmap at the
  23. left."""
  24. def __init__(self, *args, **kw):
  25. """Dialog(database, name, x, y, w, h, attributes, title, first,
  26. default, cancel, bitmap=true)"""
  27. Dialog.__init__(self, *args)
  28. ruler = self.h - 36
  29. #if kw.get("bitmap", True):
  30. # self.bitmap("Bitmap", 0, 0, bmwidth, ruler, "PythonWin")
  31. self.line("BottomLine", 0, ruler, self.w, 0)
  32. def title(self, title):
  33. "Set the title text of the dialog at the top."
  34. # name, x, y, w, h, flags=Visible|Enabled|Transparent|NoPrefix,
  35. # text, in VerdanaBold10
  36. self.text("Title", 15, 10, 320, 60, 0x30003,
  37. r"{\VerdanaBold10}%s" % title)
  38. def back(self, title, next, name = "Back", active = 1):
  39. """Add a back button with a given title, the tab-next button,
  40. its name in the Control table, possibly initially disabled.
  41. Return the button, so that events can be associated"""
  42. if active:
  43. flags = 3 # Visible|Enabled
  44. else:
  45. flags = 1 # Visible
  46. return self.pushbutton(name, 180, self.h-27 , 56, 17, flags, title, next)
  47. def cancel(self, title, next, name = "Cancel", active = 1):
  48. """Add a cancel button with a given title, the tab-next button,
  49. its name in the Control table, possibly initially disabled.
  50. Return the button, so that events can be associated"""
  51. if active:
  52. flags = 3 # Visible|Enabled
  53. else:
  54. flags = 1 # Visible
  55. return self.pushbutton(name, 304, self.h-27, 56, 17, flags, title, next)
  56. def next(self, title, next, name = "Next", active = 1):
  57. """Add a Next button with a given title, the tab-next button,
  58. its name in the Control table, possibly initially disabled.
  59. Return the button, so that events can be associated"""
  60. if active:
  61. flags = 3 # Visible|Enabled
  62. else:
  63. flags = 1 # Visible
  64. return self.pushbutton(name, 236, self.h-27, 56, 17, flags, title, next)
  65. def xbutton(self, name, title, next, xpos):
  66. """Add a button with a given title, the tab-next button,
  67. its name in the Control table, giving its x position; the
  68. y-position is aligned with the other buttons.
  69. Return the button, so that events can be associated"""
  70. return self.pushbutton(name, int(self.w*xpos - 28), self.h-27, 56, 17, 3, title, next)
  71. class bdist_msi (Command):
  72. description = "create a Microsoft Installer (.msi) binary distribution"
  73. user_options = [('bdist-dir=', None,
  74. "temporary directory for creating the distribution"),
  75. ('plat-name=', 'p',
  76. "platform name to embed in generated filenames "
  77. "(default: %s)" % get_platform()),
  78. ('keep-temp', 'k',
  79. "keep the pseudo-installation tree around after " +
  80. "creating the distribution archive"),
  81. ('target-version=', None,
  82. "require a specific python version" +
  83. " on the target system"),
  84. ('no-target-compile', 'c',
  85. "do not compile .py to .pyc on the target system"),
  86. ('no-target-optimize', 'o',
  87. "do not compile .py to .pyo (optimized)"
  88. "on the target system"),
  89. ('dist-dir=', 'd',
  90. "directory to put final built distributions in"),
  91. ('skip-build', None,
  92. "skip rebuilding everything (for testing/debugging)"),
  93. ('install-script=', None,
  94. "basename of installation script to be run after"
  95. "installation or before deinstallation"),
  96. ('pre-install-script=', None,
  97. "Fully qualified filename of a script to be run before "
  98. "any files are installed. This script need not be in the "
  99. "distribution"),
  100. ]
  101. boolean_options = ['keep-temp', 'no-target-compile', 'no-target-optimize',
  102. 'skip-build']
  103. all_versions = ['2.0', '2.1', '2.2', '2.3', '2.4',
  104. '2.5', '2.6', '2.7', '2.8', '2.9',
  105. '3.0', '3.1', '3.2', '3.3', '3.4',
  106. '3.5', '3.6', '3.7', '3.8', '3.9']
  107. other_version = 'X'
  108. def initialize_options (self):
  109. self.bdist_dir = None
  110. self.plat_name = None
  111. self.keep_temp = 0
  112. self.no_target_compile = 0
  113. self.no_target_optimize = 0
  114. self.target_version = None
  115. self.dist_dir = None
  116. self.skip_build = None
  117. self.install_script = None
  118. self.pre_install_script = None
  119. self.versions = None
  120. def finalize_options (self):
  121. self.set_undefined_options('bdist', ('skip_build', 'skip_build'))
  122. if self.bdist_dir is None:
  123. bdist_base = self.get_finalized_command('bdist').bdist_base
  124. self.bdist_dir = os.path.join(bdist_base, 'msi')
  125. short_version = get_python_version()
  126. if (not self.target_version) and self.distribution.has_ext_modules():
  127. self.target_version = short_version
  128. if self.target_version:
  129. self.versions = [self.target_version]
  130. if not self.skip_build and self.distribution.has_ext_modules()\
  131. and self.target_version != short_version:
  132. raise DistutilsOptionError, \
  133. "target version can only be %s, or the '--skip-build'" \
  134. " option must be specified" % (short_version,)
  135. else:
  136. self.versions = list(self.all_versions)
  137. self.set_undefined_options('bdist',
  138. ('dist_dir', 'dist_dir'),
  139. ('plat_name', 'plat_name'),
  140. )
  141. if self.pre_install_script:
  142. raise DistutilsOptionError, "the pre-install-script feature is not yet implemented"
  143. if self.install_script:
  144. for script in self.distribution.scripts:
  145. if self.install_script == os.path.basename(script):
  146. break
  147. else:
  148. raise DistutilsOptionError, \
  149. "install_script '%s' not found in scripts" % \
  150. self.install_script
  151. self.install_script_key = None
  152. # finalize_options()
  153. def run (self):
  154. if not self.skip_build:
  155. self.run_command('build')
  156. install = self.reinitialize_command('install', reinit_subcommands=1)
  157. install.prefix = self.bdist_dir
  158. install.skip_build = self.skip_build
  159. install.warn_dir = 0
  160. install_lib = self.reinitialize_command('install_lib')
  161. # we do not want to include pyc or pyo files
  162. install_lib.compile = 0
  163. install_lib.optimize = 0
  164. if self.distribution.has_ext_modules():
  165. # If we are building an installer for a Python version other
  166. # than the one we are currently running, then we need to ensure
  167. # our build_lib reflects the other Python version rather than ours.
  168. # Note that for target_version!=sys.version, we must have skipped the
  169. # build step, so there is no issue with enforcing the build of this
  170. # version.
  171. target_version = self.target_version
  172. if not target_version:
  173. assert self.skip_build, "Should have already checked this"
  174. target_version = sys.version[0:3]
  175. plat_specifier = ".%s-%s" % (self.plat_name, target_version)
  176. build = self.get_finalized_command('build')
  177. build.build_lib = os.path.join(build.build_base,
  178. 'lib' + plat_specifier)
  179. log.info("installing to %s", self.bdist_dir)
  180. install.ensure_finalized()
  181. # avoid warning of 'install_lib' about installing
  182. # into a directory not in sys.path
  183. sys.path.insert(0, os.path.join(self.bdist_dir, 'PURELIB'))
  184. install.run()
  185. del sys.path[0]
  186. self.mkpath(self.dist_dir)
  187. fullname = self.distribution.get_fullname()
  188. installer_name = self.get_installer_filename(fullname)
  189. installer_name = os.path.abspath(installer_name)
  190. if os.path.exists(installer_name): os.unlink(installer_name)
  191. metadata = self.distribution.metadata
  192. author = metadata.author
  193. if not author:
  194. author = metadata.maintainer
  195. if not author:
  196. author = "UNKNOWN"
  197. version = metadata.get_version()
  198. # ProductVersion must be strictly numeric
  199. # XXX need to deal with prerelease versions
  200. sversion = "%d.%d.%d" % StrictVersion(version).version
  201. # Prefix ProductName with Python x.y, so that
  202. # it sorts together with the other Python packages
  203. # in Add-Remove-Programs (APR)
  204. fullname = self.distribution.get_fullname()
  205. if self.target_version:
  206. product_name = "Python %s %s" % (self.target_version, fullname)
  207. else:
  208. product_name = "Python %s" % (fullname)
  209. self.db = msilib.init_database(installer_name, schema,
  210. product_name, msilib.gen_uuid(),
  211. sversion, author)
  212. msilib.add_tables(self.db, sequence)
  213. props = [('DistVersion', version)]
  214. email = metadata.author_email or metadata.maintainer_email
  215. if email:
  216. props.append(("ARPCONTACT", email))
  217. if metadata.url:
  218. props.append(("ARPURLINFOABOUT", metadata.url))
  219. if props:
  220. add_data(self.db, 'Property', props)
  221. self.add_find_python()
  222. self.add_files()
  223. self.add_scripts()
  224. self.add_ui()
  225. self.db.Commit()
  226. if hasattr(self.distribution, 'dist_files'):
  227. tup = 'bdist_msi', self.target_version or 'any', fullname
  228. self.distribution.dist_files.append(tup)
  229. if not self.keep_temp:
  230. remove_tree(self.bdist_dir, dry_run=self.dry_run)
  231. def add_files(self):
  232. db = self.db
  233. cab = msilib.CAB("distfiles")
  234. rootdir = os.path.abspath(self.bdist_dir)
  235. root = Directory(db, cab, None, rootdir, "TARGETDIR", "SourceDir")
  236. f = Feature(db, "Python", "Python", "Everything",
  237. 0, 1, directory="TARGETDIR")
  238. items = [(f, root, '')]
  239. for version in self.versions + [self.other_version]:
  240. target = "TARGETDIR" + version
  241. name = default = "Python" + version
  242. desc = "Everything"
  243. if version is self.other_version:
  244. title = "Python from another location"
  245. level = 2
  246. else:
  247. title = "Python %s from registry" % version
  248. level = 1
  249. f = Feature(db, name, title, desc, 1, level, directory=target)
  250. dir = Directory(db, cab, root, rootdir, target, default)
  251. items.append((f, dir, version))
  252. db.Commit()
  253. seen = {}
  254. for feature, dir, version in items:
  255. todo = [dir]
  256. while todo:
  257. dir = todo.pop()
  258. for file in os.listdir(dir.absolute):
  259. afile = os.path.join(dir.absolute, file)
  260. if os.path.isdir(afile):
  261. short = "%s|%s" % (dir.make_short(file), file)
  262. default = file + version
  263. newdir = Directory(db, cab, dir, file, default, short)
  264. todo.append(newdir)
  265. else:
  266. if not dir.component:
  267. dir.start_component(dir.logical, feature, 0)
  268. if afile not in seen:
  269. key = seen[afile] = dir.add_file(file)
  270. if file==self.install_script:
  271. if self.install_script_key:
  272. raise DistutilsOptionError(
  273. "Multiple files with name %s" % file)
  274. self.install_script_key = '[#%s]' % key
  275. else:
  276. key = seen[afile]
  277. add_data(self.db, "DuplicateFile",
  278. [(key + version, dir.component, key, None, dir.logical)])
  279. db.Commit()
  280. cab.commit(db)
  281. def add_find_python(self):
  282. """Adds code to the installer to compute the location of Python.
  283. Properties PYTHON.MACHINE.X.Y and PYTHON.USER.X.Y will be set from the
  284. registry for each version of Python.
  285. Properties TARGETDIRX.Y will be set from PYTHON.USER.X.Y if defined,
  286. else from PYTHON.MACHINE.X.Y.
  287. Properties PYTHONX.Y will be set to TARGETDIRX.Y\\python.exe"""
  288. start = 402
  289. for ver in self.versions:
  290. install_path = r"SOFTWARE\Python\PythonCore\%s\InstallPath" % ver
  291. machine_reg = "python.machine." + ver
  292. user_reg = "python.user." + ver
  293. machine_prop = "PYTHON.MACHINE." + ver
  294. user_prop = "PYTHON.USER." + ver
  295. machine_action = "PythonFromMachine" + ver
  296. user_action = "PythonFromUser" + ver
  297. exe_action = "PythonExe" + ver
  298. target_dir_prop = "TARGETDIR" + ver
  299. exe_prop = "PYTHON" + ver
  300. if msilib.Win64:
  301. # type: msidbLocatorTypeRawValue + msidbLocatorType64bit
  302. Type = 2+16
  303. else:
  304. Type = 2
  305. add_data(self.db, "RegLocator",
  306. [(machine_reg, 2, install_path, None, Type),
  307. (user_reg, 1, install_path, None, Type)])
  308. add_data(self.db, "AppSearch",
  309. [(machine_prop, machine_reg),
  310. (user_prop, user_reg)])
  311. add_data(self.db, "CustomAction",
  312. [(machine_action, 51+256, target_dir_prop, "[" + machine_prop + "]"),
  313. (user_action, 51+256, target_dir_prop, "[" + user_prop + "]"),
  314. (exe_action, 51+256, exe_prop, "[" + target_dir_prop + "]\\python.exe"),
  315. ])
  316. add_data(self.db, "InstallExecuteSequence",
  317. [(machine_action, machine_prop, start),
  318. (user_action, user_prop, start + 1),
  319. (exe_action, None, start + 2),
  320. ])
  321. add_data(self.db, "InstallUISequence",
  322. [(machine_action, machine_prop, start),
  323. (user_action, user_prop, start + 1),
  324. (exe_action, None, start + 2),
  325. ])
  326. add_data(self.db, "Condition",
  327. [("Python" + ver, 0, "NOT TARGETDIR" + ver)])
  328. start += 4
  329. assert start < 500
  330. def add_scripts(self):
  331. if self.install_script:
  332. start = 6800
  333. for ver in self.versions + [self.other_version]:
  334. install_action = "install_script." + ver
  335. exe_prop = "PYTHON" + ver
  336. add_data(self.db, "CustomAction",
  337. [(install_action, 50, exe_prop, self.install_script_key)])
  338. add_data(self.db, "InstallExecuteSequence",
  339. [(install_action, "&Python%s=3" % ver, start)])
  340. start += 1
  341. # XXX pre-install scripts are currently refused in finalize_options()
  342. # but if this feature is completed, it will also need to add
  343. # entries for each version as the above code does
  344. if self.pre_install_script:
  345. scriptfn = os.path.join(self.bdist_dir, "preinstall.bat")
  346. f = open(scriptfn, "w")
  347. # The batch file will be executed with [PYTHON], so that %1
  348. # is the path to the Python interpreter; %0 will be the path
  349. # of the batch file.
  350. # rem ="""
  351. # %1 %0
  352. # exit
  353. # """
  354. # <actual script>
  355. f.write('rem ="""\n%1 %0\nexit\n"""\n')
  356. f.write(open(self.pre_install_script).read())
  357. f.close()
  358. add_data(self.db, "Binary",
  359. [("PreInstall", msilib.Binary(scriptfn))
  360. ])
  361. add_data(self.db, "CustomAction",
  362. [("PreInstall", 2, "PreInstall", None)
  363. ])
  364. add_data(self.db, "InstallExecuteSequence",
  365. [("PreInstall", "NOT Installed", 450)])
  366. def add_ui(self):
  367. db = self.db
  368. x = y = 50
  369. w = 370
  370. h = 300
  371. title = "[ProductName] Setup"
  372. # see "Dialog Style Bits"
  373. modal = 3 # visible | modal
  374. modeless = 1 # visible
  375. # UI customization properties
  376. add_data(db, "Property",
  377. # See "DefaultUIFont Property"
  378. [("DefaultUIFont", "DlgFont8"),
  379. # See "ErrorDialog Style Bit"
  380. ("ErrorDialog", "ErrorDlg"),
  381. ("Progress1", "Install"), # modified in maintenance type dlg
  382. ("Progress2", "installs"),
  383. ("MaintenanceForm_Action", "Repair"),
  384. # possible values: ALL, JUSTME
  385. ("WhichUsers", "ALL")
  386. ])
  387. # Fonts, see "TextStyle Table"
  388. add_data(db, "TextStyle",
  389. [("DlgFont8", "Tahoma", 9, None, 0),
  390. ("DlgFontBold8", "Tahoma", 8, None, 1), #bold
  391. ("VerdanaBold10", "Verdana", 10, None, 1),
  392. ("VerdanaRed9", "Verdana", 9, 255, 0),
  393. ])
  394. # UI Sequences, see "InstallUISequence Table", "Using a Sequence Table"
  395. # Numbers indicate sequence; see sequence.py for how these action integrate
  396. add_data(db, "InstallUISequence",
  397. [("PrepareDlg", "Not Privileged or Windows9x or Installed", 140),
  398. ("WhichUsersDlg", "Privileged and not Windows9x and not Installed", 141),
  399. # In the user interface, assume all-users installation if privileged.
  400. ("SelectFeaturesDlg", "Not Installed", 1230),
  401. # XXX no support for resume installations yet
  402. #("ResumeDlg", "Installed AND (RESUME OR Preselected)", 1240),
  403. ("MaintenanceTypeDlg", "Installed AND NOT RESUME AND NOT Preselected", 1250),
  404. ("ProgressDlg", None, 1280)])
  405. add_data(db, 'ActionText', text.ActionText)
  406. add_data(db, 'UIText', text.UIText)
  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", 15, 70, 320, 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", 15, 155, 320, 20, 0x30003,
  417. "Click the Finish button to exit the Installer.")
  418. c=fatal.next("Finish", "Cancel", name="Finish")
  419. c.event("EndDialog", "Exit")
  420. user_exit=PyDialog(db, "UserExit", x, y, w, h, modal, title,
  421. "Finish", "Finish", "Finish")
  422. user_exit.title("[ProductName] Installer was interrupted")
  423. user_exit.back("< Back", "Finish", active = 0)
  424. user_exit.cancel("Cancel", "Back", active = 0)
  425. user_exit.text("Description1", 15, 70, 320, 80, 0x30003,
  426. "[ProductName] setup was interrupted. Your system has not been modified. "
  427. "To install this program at a later time, please run the installation again.")
  428. user_exit.text("Description2", 15, 155, 320, 20, 0x30003,
  429. "Click the Finish button to exit the Installer.")
  430. c = user_exit.next("Finish", "Cancel", name="Finish")
  431. c.event("EndDialog", "Exit")
  432. exit_dialog = PyDialog(db, "ExitDialog", x, y, w, h, modal, title,
  433. "Finish", "Finish", "Finish")
  434. exit_dialog.title("Completing the [ProductName] Installer")
  435. exit_dialog.back("< Back", "Finish", active = 0)
  436. exit_dialog.cancel("Cancel", "Back", active = 0)
  437. exit_dialog.text("Description", 15, 235, 320, 20, 0x30003,
  438. "Click the Finish button to exit the Installer.")
  439. c = exit_dialog.next("Finish", "Cancel", name="Finish")
  440. c.event("EndDialog", "Return")
  441. #####################################################################
  442. # Required dialog: FilesInUse, ErrorDlg
  443. inuse = PyDialog(db, "FilesInUse",
  444. x, y, w, h,
  445. 19, # KeepModeless|Modal|Visible
  446. title,
  447. "Retry", "Retry", "Retry", bitmap=False)
  448. inuse.text("Title", 15, 6, 200, 15, 0x30003,
  449. r"{\DlgFontBold8}Files in Use")
  450. inuse.text("Description", 20, 23, 280, 20, 0x30003,
  451. "Some files that need to be updated are currently in use.")
  452. inuse.text("Text", 20, 55, 330, 50, 3,
  453. "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.")
  454. inuse.control("List", "ListBox", 20, 107, 330, 130, 7, "FileInUseProcess",
  455. None, None, None)
  456. c=inuse.back("Exit", "Ignore", name="Exit")
  457. c.event("EndDialog", "Exit")
  458. c=inuse.next("Ignore", "Retry", name="Ignore")
  459. c.event("EndDialog", "Ignore")
  460. c=inuse.cancel("Retry", "Exit", name="Retry")
  461. c.event("EndDialog","Retry")
  462. # See "Error Dialog". See "ICE20" for the required names of the controls.
  463. error = Dialog(db, "ErrorDlg",
  464. 50, 10, 330, 101,
  465. 65543, # Error|Minimize|Modal|Visible
  466. title,
  467. "ErrorText", None, None)
  468. error.text("ErrorText", 50,9,280,48,3, "")
  469. #error.control("ErrorIcon", "Icon", 15, 9, 24, 24, 5242881, None, "py.ico", None, None)
  470. error.pushbutton("N",120,72,81,21,3,"No",None).event("EndDialog","ErrorNo")
  471. error.pushbutton("Y",240,72,81,21,3,"Yes",None).event("EndDialog","ErrorYes")
  472. error.pushbutton("A",0,72,81,21,3,"Abort",None).event("EndDialog","ErrorAbort")
  473. error.pushbutton("C",42,72,81,21,3,"Cancel",None).event("EndDialog","ErrorCancel")
  474. error.pushbutton("I",81,72,81,21,3,"Ignore",None).event("EndDialog","ErrorIgnore")
  475. error.pushbutton("O",159,72,81,21,3,"Ok",None).event("EndDialog","ErrorOk")
  476. error.pushbutton("R",198,72,81,21,3,"Retry",None).event("EndDialog","ErrorRetry")
  477. #####################################################################
  478. # Global "Query Cancel" dialog
  479. cancel = Dialog(db, "CancelDlg", 50, 10, 260, 85, 3, title,
  480. "No", "No", "No")
  481. cancel.text("Text", 48, 15, 194, 30, 3,
  482. "Are you sure you want to cancel [ProductName] installation?")
  483. #cancel.control("Icon", "Icon", 15, 15, 24, 24, 5242881, None,
  484. # "py.ico", None, None)
  485. c=cancel.pushbutton("Yes", 72, 57, 56, 17, 3, "Yes", "No")
  486. c.event("EndDialog", "Exit")
  487. c=cancel.pushbutton("No", 132, 57, 56, 17, 3, "No", "Yes")
  488. c.event("EndDialog", "Return")
  489. #####################################################################
  490. # Global "Wait for costing" dialog
  491. costing = Dialog(db, "WaitForCostingDlg", 50, 10, 260, 85, modal, title,
  492. "Return", "Return", "Return")
  493. costing.text("Text", 48, 15, 194, 30, 3,
  494. "Please wait while the installer finishes determining your disk space requirements.")
  495. c = costing.pushbutton("Return", 102, 57, 56, 17, 3, "Return", None)
  496. c.event("EndDialog", "Exit")
  497. #####################################################################
  498. # Preparation dialog: no user input except cancellation
  499. prep = PyDialog(db, "PrepareDlg", x, y, w, h, modeless, title,
  500. "Cancel", "Cancel", "Cancel")
  501. prep.text("Description", 15, 70, 320, 40, 0x30003,
  502. "Please wait while the Installer prepares to guide you through the installation.")
  503. prep.title("Welcome to the [ProductName] Installer")
  504. c=prep.text("ActionText", 15, 110, 320, 20, 0x30003, "Pondering...")
  505. c.mapping("ActionText", "Text")
  506. c=prep.text("ActionData", 15, 135, 320, 30, 0x30003, None)
  507. c.mapping("ActionData", "Text")
  508. prep.back("Back", None, active=0)
  509. prep.next("Next", None, active=0)
  510. c=prep.cancel("Cancel", None)
  511. c.event("SpawnDialog", "CancelDlg")
  512. #####################################################################
  513. # Feature (Python directory) selection
  514. seldlg = PyDialog(db, "SelectFeaturesDlg", x, y, w, h, modal, title,
  515. "Next", "Next", "Cancel")
  516. seldlg.title("Select Python Installations")
  517. seldlg.text("Hint", 15, 30, 300, 20, 3,
  518. "Select the Python locations where %s should be installed."
  519. % self.distribution.get_fullname())
  520. seldlg.back("< Back", None, active=0)
  521. c = seldlg.next("Next >", "Cancel")
  522. order = 1
  523. c.event("[TARGETDIR]", "[SourceDir]", ordering=order)
  524. for version in self.versions + [self.other_version]:
  525. order += 1
  526. c.event("[TARGETDIR]", "[TARGETDIR%s]" % version,
  527. "FEATURE_SELECTED AND &Python%s=3" % version,
  528. ordering=order)
  529. c.event("SpawnWaitDialog", "WaitForCostingDlg", ordering=order + 1)
  530. c.event("EndDialog", "Return", ordering=order + 2)
  531. c = seldlg.cancel("Cancel", "Features")
  532. c.event("SpawnDialog", "CancelDlg")
  533. c = seldlg.control("Features", "SelectionTree", 15, 60, 300, 120, 3,
  534. "FEATURE", None, "PathEdit", None)
  535. c.event("[FEATURE_SELECTED]", "1")
  536. ver = self.other_version
  537. install_other_cond = "FEATURE_SELECTED AND &Python%s=3" % ver
  538. dont_install_other_cond = "FEATURE_SELECTED AND &Python%s<>3" % ver
  539. c = seldlg.text("Other", 15, 200, 300, 15, 3,
  540. "Provide an alternate Python location")
  541. c.condition("Enable", install_other_cond)
  542. c.condition("Show", install_other_cond)
  543. c.condition("Disable", dont_install_other_cond)
  544. c.condition("Hide", dont_install_other_cond)
  545. c = seldlg.control("PathEdit", "PathEdit", 15, 215, 300, 16, 1,
  546. "TARGETDIR" + ver, None, "Next", None)
  547. c.condition("Enable", install_other_cond)
  548. c.condition("Show", install_other_cond)
  549. c.condition("Disable", dont_install_other_cond)
  550. c.condition("Hide", dont_install_other_cond)
  551. #####################################################################
  552. # Disk cost
  553. cost = PyDialog(db, "DiskCostDlg", x, y, w, h, modal, title,
  554. "OK", "OK", "OK", bitmap=False)
  555. cost.text("Title", 15, 6, 200, 15, 0x30003,
  556. "{\DlgFontBold8}Disk Space Requirements")
  557. cost.text("Description", 20, 20, 280, 20, 0x30003,
  558. "The disk space required for the installation of the selected features.")
  559. cost.text("Text", 20, 53, 330, 60, 3,
  560. "The highlighted volumes (if any) do not have enough disk space "
  561. "available for the currently selected features. You can either "
  562. "remove some files from the highlighted volumes, or choose to "
  563. "install less features onto local drive(s), or select different "
  564. "destination drive(s).")
  565. cost.control("VolumeList", "VolumeCostList", 20, 100, 330, 150, 393223,
  566. None, "{120}{70}{70}{70}{70}", None, None)
  567. cost.xbutton("OK", "Ok", None, 0.5).event("EndDialog", "Return")
  568. #####################################################################
  569. # WhichUsers Dialog. Only available on NT, and for privileged users.
  570. # This must be run before FindRelatedProducts, because that will
  571. # take into account whether the previous installation was per-user
  572. # or per-machine. We currently don't support going back to this
  573. # dialog after "Next" was selected; to support this, we would need to
  574. # find how to reset the ALLUSERS property, and how to re-run
  575. # FindRelatedProducts.
  576. # On Windows9x, the ALLUSERS property is ignored on the command line
  577. # and in the Property table, but installer fails according to the documentation
  578. # if a dialog attempts to set ALLUSERS.
  579. whichusers = PyDialog(db, "WhichUsersDlg", x, y, w, h, modal, title,
  580. "AdminInstall", "Next", "Cancel")
  581. whichusers.title("Select whether to install [ProductName] for all users of this computer.")
  582. # A radio group with two options: allusers, justme
  583. g = whichusers.radiogroup("AdminInstall", 15, 60, 260, 50, 3,
  584. "WhichUsers", "", "Next")
  585. g.add("ALL", 0, 5, 150, 20, "Install for all users")
  586. g.add("JUSTME", 0, 25, 150, 20, "Install just for me")
  587. whichusers.back("Back", None, active=0)
  588. c = whichusers.next("Next >", "Cancel")
  589. c.event("[ALLUSERS]", "1", 'WhichUsers="ALL"', 1)
  590. c.event("EndDialog", "Return", ordering = 2)
  591. c = whichusers.cancel("Cancel", "AdminInstall")
  592. c.event("SpawnDialog", "CancelDlg")
  593. #####################################################################
  594. # Installation Progress dialog (modeless)
  595. progress = PyDialog(db, "ProgressDlg", x, y, w, h, modeless, title,
  596. "Cancel", "Cancel", "Cancel", bitmap=False)
  597. progress.text("Title", 20, 15, 200, 15, 0x30003,
  598. "{\DlgFontBold8}[Progress1] [ProductName]")
  599. progress.text("Text", 35, 65, 300, 30, 3,
  600. "Please wait while the Installer [Progress2] [ProductName]. "
  601. "This may take several minutes.")
  602. progress.text("StatusLabel", 35, 100, 35, 20, 3, "Status:")
  603. c=progress.text("ActionText", 70, 100, w-70, 20, 3, "Pondering...")
  604. c.mapping("ActionText", "Text")
  605. #c=progress.text("ActionData", 35, 140, 300, 20, 3, None)
  606. #c.mapping("ActionData", "Text")
  607. c=progress.control("ProgressBar", "ProgressBar", 35, 120, 300, 10, 65537,
  608. None, "Progress done", None, None)
  609. c.mapping("SetProgress", "Progress")
  610. progress.back("< Back", "Next", active=False)
  611. progress.next("Next >", "Cancel", active=False)
  612. progress.cancel("Cancel", "Back").event("SpawnDialog", "CancelDlg")
  613. ###################################################################
  614. # Maintenance type: repair/uninstall
  615. maint = PyDialog(db, "MaintenanceTypeDlg", x, y, w, h, modal, title,
  616. "Next", "Next", "Cancel")
  617. maint.title("Welcome to the [ProductName] Setup Wizard")
  618. maint.text("BodyText", 15, 63, 330, 42, 3,
  619. "Select whether you want to repair or remove [ProductName].")
  620. g=maint.radiogroup("RepairRadioGroup", 15, 108, 330, 60, 3,
  621. "MaintenanceForm_Action", "", "Next")
  622. #g.add("Change", 0, 0, 200, 17, "&Change [ProductName]")
  623. g.add("Repair", 0, 18, 200, 17, "&Repair [ProductName]")
  624. g.add("Remove", 0, 36, 200, 17, "Re&move [ProductName]")
  625. maint.back("< Back", None, active=False)
  626. c=maint.next("Finish", "Cancel")
  627. # Change installation: Change progress dialog to "Change", then ask
  628. # for feature selection
  629. #c.event("[Progress1]", "Change", 'MaintenanceForm_Action="Change"', 1)
  630. #c.event("[Progress2]", "changes", 'MaintenanceForm_Action="Change"', 2)
  631. # Reinstall: Change progress dialog to "Repair", then invoke reinstall
  632. # Also set list of reinstalled features to "ALL"
  633. c.event("[REINSTALL]", "ALL", 'MaintenanceForm_Action="Repair"', 5)
  634. c.event("[Progress1]", "Repairing", 'MaintenanceForm_Action="Repair"', 6)
  635. c.event("[Progress2]", "repairs", 'MaintenanceForm_Action="Repair"', 7)
  636. c.event("Reinstall", "ALL", 'MaintenanceForm_Action="Repair"', 8)
  637. # Uninstall: Change progress to "Remove", then invoke uninstall
  638. # Also set list of removed features to "ALL"
  639. c.event("[REMOVE]", "ALL", 'MaintenanceForm_Action="Remove"', 11)
  640. c.event("[Progress1]", "Removing", 'MaintenanceForm_Action="Remove"', 12)
  641. c.event("[Progress2]", "removes", 'MaintenanceForm_Action="Remove"', 13)
  642. c.event("Remove", "ALL", 'MaintenanceForm_Action="Remove"', 14)
  643. # Close dialog when maintenance action scheduled
  644. c.event("EndDialog", "Return", 'MaintenanceForm_Action<>"Change"', 20)
  645. #c.event("NewDialog", "SelectFeaturesDlg", 'MaintenanceForm_Action="Change"', 21)
  646. maint.cancel("Cancel", "RepairRadioGroup").event("SpawnDialog", "CancelDlg")
  647. def get_installer_filename(self, fullname):
  648. # Factored out to allow overriding in subclasses
  649. if self.target_version:
  650. base_name = "%s.%s-py%s.msi" % (fullname, self.plat_name,
  651. self.target_version)
  652. else:
  653. base_name = "%s.%s.msi" % (fullname, self.plat_name)
  654. installer_name = os.path.join(self.dist_dir, base_name)
  655. return installer_name