1
0

bdist_msi.py 35 KB

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