
][\                 @   s  d  Z  d d l Z d d l Z d d l m Z d d l m Z d d l m Z d d l	 m
 Z
 d d l m Z d d l m Z d d	 l m Z d d l Z d d
 l m Z m Z m Z d d l m Z m Z m Z m Z Gd d   d e  Z Gd d   d e  Z d S)z#
Implements the bdist_msi command.
    N)Command)remove_tree)get_python_version)StrictVersion)DistutilsOptionError)get_platform)log)schemasequencetext)	DirectoryFeatureDialogadd_datac               @   sp   e  Z d  Z d Z d d   Z d d   Z d d d d	  Z d
 d d d  Z d d d d  Z d d   Z	 d S)PyDialogzDialog class with a fixed layout: controls at the top, then a ruler,
    then a list of buttons: back, next, cancel. Optionally a bitmap at the
    left.c             O   sK   t  j |  |  |  j d } d | d } |  j d d | |  j d  d S)zbDialog(database, name, x, y, w, h, attributes, title, first,
        default, cancel, bitmap=true)$      iH  Z
BottomLiner   N)r   __init__hlinew)selfargskwZrulerZbmwidth r   1/usr/lib/python3.4/distutils/command/bdist_msi.pyr      s    zPyDialog.__init__c          	   C   s'   |  j  d d d d d d d |  d S)	z,Set the title text of the dialog at the top.Title   
   i@  <   i  z{\VerdanaBold10}%sN)r   )r   titler   r   r   r    #   s    zPyDialog.titleBack   c          	   C   s>   | r d } n d } |  j  | d |  j d d d | | |  S)zAdd a back button with a given title, the tab-next button,
        its name in the Control table, possibly initially disabled.

        Return the button, so that events can be associated   r"         8      )
pushbuttonr   )r   r    nextnameactiveflagsr   r   r   back*   s    	zPyDialog.backCancelc          	   C   s>   | r d } n d } |  j  | d |  j d d d | | |  S)zAdd a cancel button with a given title, the tab-next button,
        its name in the Control table, possibly initially disabled.

        Return the button, so that events can be associatedr#   r"   i0  r%   r&   r'   )r(   r   )r   r    r)   r*   r+   r,   r   r   r   cancel5   s    	zPyDialog.cancelNextc          	   C   s>   | r d } n d } |  j  | d |  j d d d | | |  S)zAdd a Next button with a given title, the tab-next button,
        its name in the Control table, possibly initially disabled.

        Return the button, so that events can be associatedr#   r"      r%   r&   r'   )r(   r   )r   r    r)   r*   r+   r,   r   r   r   r)   @   s    	zPyDialog.nextc          	   C   s:   |  j  | t |  j | d  |  j d d d d | |  S)zAdd a button with a given title, the tab-next button,
        its name in the Control table, giving its x position; the
        y-position is aligned with the other buttons.

        Return the button, so that events can be associated   r%   r&   r'   r#   )r(   intr   r   )r   r*   r    r)   Zxposr   r   r   xbuttonK   s    zPyDialog.xbuttonN)
__name__
__module____qualname____doc__r   r    r-   r/   r)   r4   r   r   r   r   r      s   
r   c               @   s]  e  Z d  Z d Z d d d f d d d e   f d d	 d
 d f d d d d f d d d f d d d f d d d f d d d f d d d f d d d f g
 Z d d d d g Z d d d  d! d" d# d$ d% d& d' d( d) d* d+ d, d- d. d/ d0 d1 g Z d2 Z d3 d4   Z	 d5 d6   Z
 d7 d8   Z d9 d:   Z d; d<   Z d= d>   Z d? d@   Z dA dB   Z d S)C	bdist_msiz7create a Microsoft Installer (.msi) binary distributionz
bdist-dir=Nz1temporary directory for creating the distributionz
plat-name=pz;platform name to embed in generated filenames (default: %s)z	keep-tempkz/keep the pseudo-installation tree around after z!creating the distribution archiveztarget-version=z!require a specific python versionz on the target systemzno-target-compilecz/do not compile .py to .pyc on the target systemzno-target-optimizeoz:do not compile .py to .pyo (optimized)on the target systemz	dist-dir=dz-directory to put final built distributions inz
skip-buildz2skip rebuilding everything (for testing/debugging)zinstall-script=zTbasename of installation script to be run afterinstallation or before deinstallationzpre-install-script=z{Fully qualified filename of a script to be run before any files are installed.  This script need not be in the distributionz2.0z2.1z2.2z2.3z2.4z2.5z2.6z2.7z2.8z2.9z3.0z3.1z3.2z3.3z3.4z3.5z3.6z3.7z3.8z3.9Xc             C   sg   d  |  _  d  |  _ d |  _ d |  _ d |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _	 d  |  _
 d  S)Nr   )	bdist_dir	plat_name	keep_tempZno_target_compileZno_target_optimizetarget_versiondist_dir
skip_buildinstall_scriptpre_install_scriptversions)r   r   r   r   initialize_options}   s    										zbdist_msi.initialize_optionsc             C   sr  |  j  d d	  |  j d  k rL |  j d  j } t j j | d  |  _ n  t   } |  j rz |  j	 j
   rz | |  _ n  |  j r |  j g |  _ |  j r |  j	 j
   r |  j | k r t d | f   q n t |  j  |  _ |  j  d d
 d  |  j rt d   n  |  j rexI |  j	 j D]% } |  j t j j |  k r&Pq&q&Wt d |  j   n  d  |  _ d  S)NZbdistrE   ZmsizMtarget version can only be %s, or the '--skip-build' option must be specifiedrD   rA   z5the pre-install-script feature is not yet implementedz(install_script '%s' not found in scripts)
skip_buildrJ   )dist_dirrK   )	plat_namerL   )Zset_undefined_optionsr@   get_finalized_command
bdist_baseospathjoinr   rC   distributionhas_ext_modulesrH   rE   r   listall_versionsrG   rF   Zscriptsbasenameinstall_script_key)r   rN   Zshort_versionZscriptr   r   r   finalize_options   s:    					zbdist_msi.finalize_optionsc             C   s  |  j  s |  j d  n  |  j d d d } |  j | _ |  j  | _  d | _ |  j d  } d | _ d | _ |  j j	   r |  j
 } | s |  j  s t d   t j d d  } n  d	 |  j | f } |  j d  } t j j | j d
 |  | _ n  t j d |  j  | j   t j j d t j j |  j d   | j   t j d =|  j |  j  |  j j   } |  j |  } t j j |  } t j j |  rt j  |  n  |  j j! } | j" }	 |	 s| j# }	 n  |	 sd }	 n  | j$   }
 d t% |
  j } |  j j   } |  j
 r8d |  j
 | f } n
 d | } t& j' | t( | t& j)   | |	  |  _* t& j+ |  j* t,  d |
 f g } | j- p| j. } | r| j/ d | f  n  | j0 r| j/ d | j0 f  n  | rt1 |  j* d |  n  |  j2   |  j3   |  j4   |  j5   |  j* j6   t7 |  j d  rld |  j
 pMd | f } |  j j8 j/ |  n  |  j9 st: |  j d |  j; n  d  S)NbuildinstallZreinit_subcommandsr"   r   install_libz Should have already checked thisr#   z.%s-%sZlibzinstalling to %sZPURELIBZUNKNOWNz%d.%d.%dzPython %s %sz	Python %sZDistVersionZ
ARPCONTACTZARPURLINFOABOUTProperty
dist_filesr9   anydry_run)<rE   Zrun_commandZreinitialize_commandr@   prefixZwarn_dircompileoptimizerR   rS   rC   AssertionErrorsysversionrA   rM   rO   rP   rQ   Z
build_baseZ	build_libr   infoZensure_finalizedinsertrunZmkpathrD   get_fullnameget_installer_filenameabspathexistsunlinkmetadataauthorZ
maintainerZget_versionr   msilibZinit_databaser	   Zgen_uuiddbZ
add_tablesr
   Zauthor_emailZmaintainer_emailappendZurlr   add_find_python	add_filesadd_scriptsadd_uiCommithasattrr]   rB   r   r_   )r   rZ   r[   rC   Zplat_specifierrY   fullnameinstaller_namern   ro   re   ZsversionZproduct_nameZpropsZemailtupr   r   r   rh      s~    					
%

 			
	



	zbdist_msi.runc          
   C   s  |  j  } t j d  } t j j |  j  } t | | d  | d d  } t | d d d d d d d } | | d	 f g } x |  j	 |  j
 g D] } d | } d | }	 }
 d } | |  j
 k r d
 } d } n d | } d } t | |	 | | d | d | } t | | | | | |
  } | j | | | f  q W| j   i  } x| D]\ } } } | g } xg| r| j   } xNt j | j  D]:} t j j | j |  } t j j |  rd | j |  | f } | | }
 t | | | | |
 |  } | j |  q| j s.| j | j | d  n  | | k r| j |  } | | <| |  j k r|  j r|t d |   n  d | |  _ qq| | } t |  j  d | | | j | d  | j f g  qWqiW| j   qNW| j |  d  S)NZ	distfiles	TARGETDIRZ	SourceDirPythonZ
Everythingr   r"   Z	directory zPython from another location   zPython %s from registryz%s|%szMultiple files with name %sz[#%s]ZDuplicateFile)rq   rp   ZCABrO   rP   rk   r@   r   r   rH   other_versionrr   rw   poplistdirZabsoluterQ   isdirZ
make_shortZ	componentZstart_componentZlogicalZadd_filerF   rW   r   r   Zcommit)r   rq   ZcabZrootdirrootfitemsre   targetr*   defaultZdescr    leveldirseenZfeatureZtodofileZafileZshortZnewdirkeyr   r   r   rt     s\    	
	
!
		
		
+zbdist_msi.add_filesc             C   s  d } x|  j  D]} d | } d | } d | } d | } d | } d | } d | }	 d	 | }
 d
 | } d | } t j r d  } n d } t |  j d | d | d | f | d | d | f g  t |  j d | | f | | f g  t |  j d | d! | d | d f |	 d" | d | d f |
 d# | d | d f g  t |  j d | | | f |	 | | d f |
 d | d f g  t |  j d | | | f |	 | | d f |
 d | d f g  t |  j d d | d d | f g  | d 7} | d k  s t  q Wd S)$as  Adds code to the installer to compute the location of Python.

        Properties PYTHON.MACHINE.X.Y and PYTHON.USER.X.Y will be set from the
        registry for each version of Python.

        Properties TARGETDIRX.Y will be set from PYTHON.USER.X.Y if defined,
        else from PYTHON.MACHINE.X.Y.

        Properties PYTHONX.Y will be set to TARGETDIRX.Y\python.exei  z)SOFTWARE\Python\PythonCore\%s\InstallPathzpython.machine.zpython.user.zPYTHON.MACHINE.zPYTHON.USER.ZPythonFromMachineZPythonFromUserZ	PythonExer|   PYTHONr      Z
RegLocatorNr"   Z	AppSearchCustomAction3      []z]\python.exeInstallExecuteSequenceInstallUISequenceZ	Conditionr}   r   zNOT TARGETDIR   i     i3  i3  i3  )rH   rp   ZWin64r   rq   rc   )r   startverZinstall_pathZmachine_regZuser_regZmachine_propZ	user_propZmachine_actionZuser_actionZ
exe_actionZtarget_dir_propexe_propZTyper   r   r   rs   C  sJ    









			
zbdist_msi.add_find_pythonc             C   sQ  |  j  r d } x |  j |  j g D]l } d | } d | } t |  j d | d | |  j f g  t |  j d | d | | f g  | d 7} q# Wn  |  j rMt j j	 |  j
 d	  } t | d
  } | j d  | j t |  j  j    | j   t |  j d d t j |  f g  t |  j d d g  t |  j d d g  n  d  S)Ni  zinstall_script.r   r   2   r   z&Python%s=3r"   zpreinstall.batr   zrem ="""
%1 %0
exit
"""
Binary
PreInstallr   NOT Installed  )r   r   r   N)r   r   r   )rF   rH   r   r   rq   rW   rG   rO   rP   rQ   r@   openwritereadcloserp   r   )r   r   r   Zinstall_actionr   Zscriptfnr   r   r   r   ru   y  s,    	

		

zbdist_msi.add_scriptsc             C   sG  |  j  } d } } d } d } d } d } d } d }	 t | d d d d d d d g  t | d d d d d g  t | d  d d d d d g  t | d/ t j  t | d0 t j  t | d1 | | | | | | d2 d2 d2  }
 |
 j d3  |
 j d4 d2 d5 d |
 j d6 d7 d5 d |
 j d8 d9 d: d; d< d= d>  |
 j d? d9 d@ d; dA d= dB  |
 j	 d2 d6 dC d2 } | j
 dD dE  t | dF | | | | | | d2 d2 d2  } | j dG  | j d4 d2 d5 d | j d6 d7 d5 d | j d8 d9 d: d; d< d= dH  | j d? d9 d@ d; dA d= dB  | j	 d2 d6 dC d2 } | j
 dD dE  t | dI | | | | | | d2 d2 d2  } | j dJ  | j d4 d2 d5 d | j d6 d7 d5 d | j dK d9 dL d; dA d= dB  | j	 d2 d6 dC d2 } | j
 dD dM  t | dN | | | | dO | dP dP dP dQ dR } | j dS d9 dT dU d9 d= dV  | j dK dA dW dX dA d= dY  | j dZ dA d[ d\ d d d]  | j d^ d_ dA d` d\ da db dc d  d  d   | j dE dd dC dE } | j
 dD dE  | j	 dd dP dC dd } | j
 dD dd  | j dP dE dC dP } | j
 dD dP  t | d d d d\ de df | dg d  d   } | j dg d d dX dh d di  | j dj dk dl dm dn d do d   j
 dD dp  | j dq dr dl dm dn d ds d   j
 dD dt  | j du d dl dm dn d dv d   j
 dD dw  | j dx dy dl dm dn d d6 d   j
 dD dz  | j d{ dm dl dm dn d dd d   j
 dD d|  | j d} d~ dl dm dn d d d   j
 dD d  | j d d dl dm dn d dP d   j
 dD d  t | d d d d d d | do do do  } | j dZ dh d9 d d d d  | j ds dl d d d d ds do  } | j
 dD dE  | j do d d d d d do ds  } | j
 dD dM  t | d d d d d | | dM dM dM  } | j dZ dh d9 d d d d  | j dM d d d d d dM d   } | j
 dD dE  t | d! | | | | | | d6 d6 d6  } | j dK d9 d: d; d d= d  | j d  | j d/ d9 d d; dA d= d  } | j d/ dZ  | j d d9 d d; d d= d   } | j d dZ  | j d7 d  d5 d | j	 d d  d5 d | j d6 d   } | j
 d d  t | d' | | | | | | d d d6  } | j d  | j d d9 d d dA d d |  j j    | j d4 d  d5 d | j	 d d6  } d } | j
 d d d | xF |  j |  j g D]1 } | d 7} | j
 d d | d | d | qW| j
 d d d | d | j
 dD dM d | d | j d6 d  } | j
 d d  | j d d d9 d d dk d d d  d d   } | j
 d d  |  j } d | } d | } | j d d9 dU d d9 d d  } | j d |  | j d |  | j d |  | j d |  | j d d d9 d d d d d | d  d d   } | j d |  | j d |  | j d |  | j d |  t | d | | | | | | d d d dQ dR } | j dS d9 dT dU d9 d= d  | j dK dA dA dX dA d= d  | j dZ dA d d\ d d d  | j d d dA d d\ d d d  d d  d   | j d d d  d  j
 dD dM  t | d$ | | | | | | d d d6  } | j d  | j d d9 d d d d d di d 	 } | j d d d d dA d  | j d d d d dA d  | j d7 d  d5 d | j	 d d6  } | j
 d d d d  | j
 dD dM d d | j d6 d  } | j
 d d  t | d- | | | | | | d6 d6 d6 dQ dR } | j dS dA d9 dU d9 d= d  | j dZ d d d d d d  | j d d d d dA d d  | j d/ d: d | d: dA d d  } | j d/ dZ  | j d d d dk d d d d  d d  d   } | j d d  | j d4 d d5 dR | j	 d d6 d5 dR | j d6 d7  j
 d d  t | d* | | | | | | d d d6  } | j d  | j d d9 d d\ dy d d  | j d d9 d d\ d d d di d 	 } | j d d d dU d d  | j d d d dU d d  | j d4 d  d5 dR | j	 d2 d6  } | j
 d d d d  | j
 d d d dT  | j
 d d d db  | j
 d d d d  | j
 d d d d  | j
 d d d d  | j
 d d d d  | j
 d d d d  | j
 dD dM d dA  | j d6 d  j
 d d  d  S(  Nr   ir  i,  z[ProductName] Setupr#   r"       r\   DefaultUIFontDlgFont8ErrorDialogErrorDlg	Progress1Install	Progress2installsMaintenanceForm_ActionRepair
WhichUsersALLZ	TextStyleTahoma	   r   DlgFontBold8   VerdanaBold10Verdanar   VerdanaRed9   r   
PrepareDlg(Not Privileged or Windows9x or Installed   WhichUsersDlg.Privileged and not Windows9x and not Installed   SelectFeaturesDlgNot Installed  MaintenanceTypeDlg,Installed AND NOT RESUME AND NOT Preselected  ProgressDlg   
ActionTextUITextZ
FatalErrorZFinishz)[ProductName] Installer ended prematurelyz< Backr+   r.   r!   ZDescription1r   F   i@  P   i  z[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.ZDescription2      z.Click the Finish button to exit the Installer.r*   Z	EndDialogZExitZUserExitz'[ProductName] Installer was interruptedz[ProductName] setup was interrupted.  Your system has not been modified.  To install this program at a later time, please run the installation again.Z
ExitDialogz&Completing the [ProductName] InstallerZDescription   ZReturnZ
FilesInUse   ZRetryZbitmapFr         z{\DlgFontBold8}Files in Use   i  z8Some files that need to be updated are currently in use.ZText7   iJ  zThe 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.ZListZListBoxk         ZFileInUseProcessIgnoree   i  Z	ErrorText0   r~   Nx   H   Q      ZNoZErrorNoY   ZYesZErrorYesAZAbortZ
ErrorAbortC*   ZErrorCancelIZErrorIgnoreO   ZOkZErrorOkR   Z
ErrorRetryZ	CancelDlgi  U         z;Are you sure you want to cancel [ProductName] installation?9   r&   r'      ZWaitForCostingDlgzRPlease wait while the installer finishes determining your disk space requirements.f   (   zOPlease wait while the Installer prepares to guide you through the installation.z&Welcome to the [ProductName] Installern   zPondering...Z
ActionData   r0   ZSpawnDialogzSelect Python InstallationsZHintz9Select the Python locations where %s should be installed.zNext >z[TARGETDIR]z[SourceDir]Zorderingz[TARGETDIR%s]z FEATURE_SELECTED AND &Python%s=3ZSpawnWaitDialogr   ZFeaturesZSelectionTreer   ZFEATUREZPathEditz[FEATURE_SELECTED]1z!FEATURE_SELECTED AND &Python%s<>3ZOtherz$Provide an alternate Python locationZEnableZShowZDisableZHide   r   r|   ZDiskCostDlgZOKz&{\DlgFontBold8}Disk Space RequirementszFThe disk space required for the installation of the selected features.5   a  The highlighted volumes (if any) do not have enough disk space available for the currently selected features.  You can either remove some files from the highlighted volumes, or choose to install less features onto local drive(s), or select different destination drive(s).Z
VolumeListZVolumeCostListd      i  z{120}{70}{70}{70}{70}g      ?ZAdminInstallzGSelect whether to install [ProductName] for all users of this computer.   zInstall for all usersZJUSTME   zInstall just for mez
[ALLUSERS]zWhichUsers="ALL"z({\DlgFontBold8}[Progress1] [ProductName]#   A   zYPlease wait while the Installer [Progress2] [ProductName]. This may take several minutes.ZStatusLabelzStatus:ZProgressBari  zProgress doneZSetProgressZProgressz)Welcome to the [ProductName] Setup WizardZBodyText?   z:Select whether you want to repair or remove [ProductName].ZRepairRadioGroupl   r   z&Repair [ProductName]ZRemover   zRe&move [ProductName]z[REINSTALL]zMaintenanceForm_Action="Repair"z[Progress1]Z	Repairingz[Progress2]ZrepairsZ	Reinstallz[REMOVE]zMaintenanceForm_Action="Remove"   ZRemoving   Zremoves      z MaintenanceForm_Action<>"Change")r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   r   Nr   )r   r   r   Nr"   )r   r   r   Nr"   )r   r   r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   Nr   )rq   r   r   r   r   r   r    r-   r/   r)   ZeventZcontrolr   r(   mappingrR   ri   rH   r   Z	conditionr4   Z
radiogroupadd)r   rq   xyr   r   r    ZmodalZmodelessZtrack_disk_spaceZfatalr<   Z	user_exitZexit_dialogZinuseerrorr/   ZcostingZprepZseldlgZorderre   r   Zinstall_other_condZdont_install_other_condZcostZ
whichusersgZprogressZmaintr   r   r   rv     s   	
	
	
	
		.......$$$!!

	

	"%zbdist_msi.add_uic             C   sT   |  j  r% d | |  j |  j  f } n d | |  j f } t j j |  j |  } | S)Nz%s.%s-py%s.msiz	%s.%s.msi)rC   rA   rO   rP   rQ   rD   )r   ry   Z	base_namerz   r   r   r   rj     s    	z bdist_msi.get_installer_filename)r5   r6   r7   Zdescriptionr   Zuser_optionsZboolean_optionsrU   r   rI   rX   rh   rt   rs   ru   rv   rj   r   r   r   r   r9   S   sP   
		([66& ?r9   )r8   rd   rO   Zdistutils.corer   Zdistutils.dir_utilr   Zdistutils.sysconfigr   Zdistutils.versionr   Zdistutils.errorsr   Zdistutils.utilr   Z	distutilsr   rp   r	   r
   r   r   r   r   r   r   r9   r   r   r   r   <module>   s   ">