o
    ãýðcûŠ  ã                   @   sÈ   d Z ddl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 G dd„ deƒZG d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                   @   sF   e Zd ZdZdd„ Zdd„ Zddd	„Zddd„Zddd„Zdd„ Z	dS )ÚPyDialogz™Dialog 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   s@   t j| g|¢R Ž  | jd }d| d }|  dd|| jd¡ dS )zbDialog(database, name, x, y, w, h, attributes, title, first,
        default, cancel, bitmap=true)é$   é˜   iH  Ú
BottomLiner   N)r   Ú__init__ÚhÚlineÚw)ÚselfÚargsÚkwÚrulerÚbmwidth© r   úT/opt/certbot/lib/python3.10/site-packages/setuptools/_distutils/command/bdist_msi.pyr      s   
zPyDialog.__init__c              
   C   s   |   ddddddd| ¡ dS )	z,Set the title text of the dialog at the top.ÚTitleé   é
   é@  é<   é  z{\VerdanaBold10}%sN)r   )r   Útitler   r   r   r%   %   s   ÿzPyDialog.titleÚBacké   c              
   C   ó,   |rd}nd}|   |d| jd dd|||¡S )z»Add 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,   ó   zPyDialog.backÚCancelc              
   C   r(   )z½Add 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.   r0   r   r   r   Úcancel7   r6   zPyDialog.cancelÚNextc              
   C   r(   )z»Add 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.   r0   r   r   r   r1   B   r6   zPyDialog.nextc              
   C   s,   |   |t| j| d ƒ| jd ddd||¡S )zêAdd 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   r2   r%   r1   Úxposr   r   r   ÚxbuttonM   s   ,zPyDialog.xbuttonN)r&   r'   )r7   r'   )r9   r'   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r%   r5   r8   r1   r>   r   r   r   r   r      s    



r   c                
       s˜   e Zd ZdZddddeƒ  fdddd	d
dddg
Zg d¢Zg d¢ZdZ‡ fdd„Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Z‡  ZS )#Ú	bdist_msiz7create a Microsoft Installer (.msi) binary distribution)z
bdist-dir=Nz1temporary directory for creating the distributionz
plat-name=Úpz;platform name to embed in generated filenames (default: %s))ú	keep-tempÚkzPkeep the pseudo-installation tree around after creating the distribution archive)ztarget-version=Nz6require a specific python version on the target system)úno-target-compileÚcz/do not compile .py to .pyc on the target system)úno-target-optimizeÚoz;do not compile .py to .pyo (optimized) on the target system)z	dist-dir=Údz-directory to put final built distributions in)ú
skip-buildNz2skip rebuilding everything (for testing/debugging))zinstall-script=NzUbasename of installation script to be run after installation or before deinstallation)zpre-install-script=Nz{Fully qualified filename of a script to be run before any files are installed.  This script need not be in the distribution)rE   rG   rI   rL   )z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                    s$   t ƒ j|i |¤Ž t dtd¡ d S )NzZbdist_msi command is deprecated since Python 3.9, use bdist_wheel (wheel packages) insteadé   )Úsuperr   ÚwarningsÚwarnÚDeprecationWarning)r   r   r   ©Ú	__class__r   r   r      s   þzbdist_msi.__init__c                 C   sF   d | _ d | _d| _d| _d| _d | _d | _d | _d | _d | _	d | _
d S )Nr   )Ú	bdist_dirÚ	plat_nameÚ	keep_tempÚno_target_compileÚ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   sò   |   dd¡ | jd u r|  d¡j}tj |d¡| _tƒ }| js'| j	 
¡ r'|| _| jrD| jg| _| jsC| j	 
¡ rC| j|krCtd|f ƒ‚nt| jƒ| _|   ddd¡ | jrXtdƒ‚| jrt| j	jD ]}| jtj |¡krl nq_td| j ƒ‚d | _d S )	NÚbdist)r\   r\   ÚmsizMtarget version can only be %s, or the '--skip-build' option must be specified)r[   r[   )rV   rV   z5the pre-install-script feature is not yet implementedz(install_script '%s' not found in scripts)Úset_undefined_optionsrU   Úget_finalized_commandÚ
bdist_baseÚosÚpathÚjoinr   rZ   ÚdistributionÚhas_ext_modulesr_   r\   r   ÚlistÚall_versionsr^   r]   ÚscriptsÚbasenameÚinstall_script_key)r   re   Úshort_versionÚscriptr   r   r   Úfinalize_options’   sL   

ÿÿÿ€þÿÿÿÿ
zbdist_msi.finalize_optionsc                 C   s~  | j s|  d¡ | jddd}| j|_| j |_ d|_|  d¡}d|_d|_| j 	¡ rV| j
}|s?| j s6J dƒ‚dtjd d	…  }d
| j|f }|  d¡}tj |jd| ¡|_t d| j¡ | ¡  tj dtj | jd¡¡ | ¡  tjd= |  | j¡ | j ¡ }|  |¡}tj |¡}tj |¡r—t |¡ | jj }|j!}	|	s£|j"}	|	s§d}	| #¡ }
dt$|
ƒj% }| j ¡ }| j
rÂd| j
|f }nd| }t& '|t(|t& )¡ ||	¡| _*t& +| j*t,¡ d|
fg}|j-pä|j.}|rî| /d|f¡ |j0rù| /d|j0f¡ |rt1| j*d|ƒ |  2¡  |  3¡  |  4¡  |  5¡  | j* 6¡  t7| jdƒr/d| j
p%d|f}| jj8 /|¡ | j9s=t:| j| j;d d S d S )NÚbuildÚinstallr'   )Úreinit_subcommandsr   Úinstall_libz Should have already checked thisz%d.%drN   z.%s-%sÚlibzinstalling to %sÚPURELIBÚUNKNOWNz%d.%d.%dzPython %s %sz	Python %sÚDistVersionÚ
ARPCONTACTÚARPURLINFOABOUTÚPropertyÚ
dist_filesrC   Úany)Údry_run)<r\   Úrun_commandÚreinitialize_commandrU   ÚprefixÚwarn_dirÚcompileÚoptimizeri   rj   rZ   ÚsysÚversion_inforV   rd   rf   rg   rh   Ú
build_baseÚ	build_libr   ÚinfoÚensure_finalizedÚinsertÚrunÚmkpathr[   Úget_fullnameÚget_installer_filenameÚabspathÚexistsÚunlinkÚmetadataÚauthorÚ
maintainerÚget_versionr   ÚversionÚmsilibÚinit_databaser	   Úgen_uuidÚdbÚ
add_tablesr
   Úauthor_emailÚmaintainer_emailÚappendÚurlr   Úadd_find_pythonÚ	add_filesÚadd_scriptsÚadd_uiÚCommitÚhasattrr~   rW   r   r€   )r   rt   rv   rZ   Úplat_specifierrs   ÚfullnameÚinstaller_namer•   r–   r™   ÚsversionÚproduct_nameÚpropsÚemailÚtupr   r   r   rŽ   º   s‚   




ÿ


þ

ÿzbdist_msi.runc              
   C   s  | j }t d¡}tj | j¡}t||d |ddƒ}t|ddddddd}||d	fg}| j	| j
g D ]:}d| }d|  }	}
d}|| j
u rHd
}d}nd| }d}t||	||d||d}t||||||
ƒ}| |||f¡ q0| ¡  i }|D ]ˆ\}}}|g}|r÷| ¡ }t |j¡D ]m}tj |j|¡}tj |¡r³d| |¡|f }|| }
t|||||
|ƒ}| |¡ q‡|js¾| |j|d¡ ||vrß| |¡ }||< || jkrÞ| jrÙtd| ƒ‚d| | _q‡|| }t| j d|| |j|d |jfgƒ q‡|s}| ¡  qs| |¡ d S )NÚ	distfilesÚ	TARGETDIRÚ	SourceDirÚPythonÚ
Everythingr   r'   )Ú	directoryÚ zPython from another locationrN   zPython %s from registryz%s|%szMultiple files with name %sz[#%s]ÚDuplicateFile)r   rš   ÚCABrf   rg   r’   rU   r   r   r_   Úother_versionr¡   r§   ÚpopÚlistdirÚabsoluterh   ÚisdirÚ
make_shortÚ	componentÚstart_componentÚlogicalÚadd_filer]   ro   r   r   Úcommit)r   r   ÚcabÚrootdirÚrootÚfÚitemsr™   Útargetr2   ÚdefaultÚdescr%   ÚlevelÚdirÚseenÚfeatureÚtodoÚfileÚafileÚshortÚnewdirÚkeyr   r   r   r¤     sf   

ÿ

ÿ
€ÿë
zbdist_msi.add_filesc                 C   s†  d}| j D ]»}d| }d| }d| }d| }d| }d| }d| }	d	| }
d
| }d| }tjr5d}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ÀJ ‚qd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.ÚPythonFromMachineÚPythonFromUserÚ	PythonExer²   ÚPYTHONé   rN   Ú
RegLocatorNr'   Ú	AppSearchÚCustomActioni3  ú[ú]z]\python.exeÚInstallExecuteSequenceÚInstallUISequenceÚ	Conditionr´   r   zNOT TARGETDIRé   iô  )r_   rš   ÚWin64r   r   )r   ÚstartÚverÚinstall_pathÚmachine_regÚuser_regÚmachine_propÚ	user_propÚmachine_actionÚuser_actionÚ
exe_actionÚtarget_dir_propÚexe_propÚTyper   r   r   r£   K  sb   
ÿÿÿÿþÿþÿþÿÿØzbdist_msi.add_find_pythonc              	   C   s.  | j r5d}| j| jg D ](}d| }d| }t| jd|d|| jfgƒ t| jd|d| |fgƒ |d7 }q| jr•tj 	| j
d	¡}t|d
ƒ)}| d¡ t| jƒ}| | ¡ ¡ W d   ƒ n1 sbw   Y  W d   ƒ n1 sqw   Y  t| jddt |¡fgƒ t| jddgƒ t| jddgƒ d S d S )Ni  zinstall_script.rÚ   rÞ   é2   rá   z&Python%s=3r'   zpreinstall.batr   zrem ="""
%1 %0
exit
"""
ÚBinaryÚ
PreInstall)rõ   rN   rõ   N)rõ   zNOT InstallediÂ  )r]   r_   rº   r   r   ro   r^   rf   rg   rh   rU   ÚopenÚwriteÚreadrš   rô   )r   ræ   rç   Úinstall_actionrñ   ÚscriptfnrÈ   Úfinr   r   r   r¥     s>   ÿÿ

	ÿ€öÿÿÿìzbdist_msi.add_scriptsc                 C   s¶
  | j }d }}d}d}d}d}d}d}	t|dg d	¢ƒ t|d
g d¢ƒ t|dg d¢ƒ t|dtjƒ t|dtjƒ t|d||||||dddƒ}
|
 d¡ |
jdddd |
jdddd |
 ddddddd¡ |
 ddd dd!dd"¡ |
j	dddd#}| 
d$d%¡ t|d&||||||dddƒ}| d'¡ |jdddd |jdddd | ddddddd(¡ | ddd dd!dd"¡ |j	dddd#}| 
d$d%¡ t|d)||||||dddƒ}| d*¡ |jdddd |jdddd | d+dd,dd!dd"¡ |j	dddd#}| 
d$d-¡ t|d.||||d/|d0d0d0d1d2}| d3dd4d5ddd6¡ | d+d!d7d8d!dd9¡ | d:d!d;d<ddd=¡ | d>d?d!d@d<dAdBdCd d d ¡ |jd%dDd%d#}| 
d$d%¡ |j	dDd0dDd#}| 
d$dD¡ |jd0d%d0d#}| 
d$d0¡ t|dEddFd<dGdH|dId d ƒ}| dIddJd8dKddL¡ | dMdNdOdPdQddRd ¡ 
d$dS¡ | dTdUdOdPdQddVd ¡ 
d$dW¡ | dXddOdPdQddYd ¡ 
d$dZ¡ | d[d\dOdPdQddd ¡ 
d$d]¡ | d^dPdOdPdQddDd ¡ 
d$d_¡ | d`dadOdPdQddbd ¡ 
d$dc¡ | dddedOdPdQdd0d ¡ 
d$df¡ t|dgddFdhdid|dRdRdRƒ}| d:dKddjdkddl¡ | dVdOdmdndoddVdR¡}| 
d$d%¡ | dRdpdmdndoddRdV¡}| 
d$d-¡ t|dqddFdhdi||d-d-d-ƒ}| d:dKddjdkddr¡ | d-dsdmdndodd-d ¡}| 
d$d%¡ t|dt||||||dddƒ}| d+dddduddv¡ | dw¡ | dddxdd!ddy¡}| dd:¡ | dzdd{ddkdd ¡}| dzd:¡ |jdd dd |j	d|d dd | dd ¡}| 
d}dg¡ t|d~||||||d|d|dƒ}| d¡ | d€ddkdd!dd| j ¡  ¡ |jdd dd | 	d‚d¡}d}|j
dƒd„|d… | j| jg D ]}|d7 }|j
dƒd†| d‡| |d… qü|j
dˆdq|d d… |j
d$d-|d‰ d… | ddŠ¡}| 
d}dg¡ | dŠd‹ddŒddNddd dŽd ¡}| 
dd¡ | j}d‡| }d‘| }| d’dd5dddd“¡}| d”|¡ | d•|¡ | d–|¡ | d—|¡ | dŽdŽdd˜dd™ddš| d d|d ¡}| d”|¡ | d•|¡ | d–|¡ | d—|¡ t|d›||||||dœdœdœd1d2}| d3dd4d5ddd¡ | d+d!d!d8d!ddž¡ | d:d!dŸd<dŒdd ¡ | d¡d¢d!d£d<d¤d¥d d¦d d ¡ | dœdbd d§¡ 
d$d-¡ t|d¨||||||d©d|dƒ}| dª¡ | d©ddŒdhddd«dLd|¡	}| d¬dd­d¤d!d®¡ | d¯dd°d¤d!d±¡ |jdd dd | 	d‚d¡}| 
d²dd³d¡ |j
d$d-d‰d… | dd©¡}| 
d}dg¡ t|d´||||||dddd1d2}| d3d!dd5dddµ¡ | d:d¶d·ddkdd¸¡ | d¹d¶d£d¶d!ddº¡ | ddd£|d d!ddy¡}| dd:¡ | d»d»d¶dNddFd¼d d½d d ¡}| d¾d¿¡ |jdd|d1d |j	d‚dd1d | dd¡ 
d}dg¡ t|dÀ||||||d|d|dƒ}| dÁ¡ | dÂddÃd<d\ddÄ¡ | dÅddÆd<dŒddÇdLd|¡	}| dÈddÉd5dodÊ¡ | dËddÌd5dodÍ¡ |jdd d1d | 	dd¡}| 
dÎd¬dÏd­¡ | 
dÐdÑdÏd4¡ | 
dÒdÓdÏdB¡ | 
dÔd¬dÏdÕ¡ | 
dÖd¬d×dØ¡ | 
dÐdÙd×dÚ¡ | 
dÒdÛd×dÜ¡ | 
dËd¬d×dÝ¡ | 
d$d-dÞd!¡ | ddÅ¡ 
d}dg¡ d S )ßNró   ir  i,  z[ProductName] Setupr)   r'   é    r}   ))ÚDefaultUIFontÚDlgFont8)ÚErrorDialogÚErrorDlg)Ú	Progress1ÚInstall)Ú	Progress2Úinstalls)ÚMaintenanceForm_ActionÚRepair)Ú
WhichUsersÚALLÚ	TextStyle))rþ   ÚTahomaé	   Nr   )ÚDlgFontBold8r
  é   Nr'   )ÚVerdanaBold10ÚVerdanar!   Nr'   )ÚVerdanaRed9r  r  éÿ   r   râ   ))Ú
PrepareDlgz(Not Privileged or Windows9x or InstalledéŒ   )ÚWhichUsersDlgz.Privileged and not Windows9x and not Installedé   )ÚSelectFeaturesDlgzNot InstallediÎ  )ÚMaintenanceTypeDlgz,Installed AND NOT RESUME AND NOT Preselectediâ  )ÚProgressDlgNi   Ú
ActionTextÚUITextÚ
FatalErrorÚFinishz)[ProductName] Installer ended prematurelyz< Backr   )r3   r7   r&   ÚDescription1r    éF   r"   éP   r$   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.ÚDescription2é›   é   z.Click the Finish button to exit the Installer.)r2   Ú	EndDialogÚExitÚ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.Ú
ExitDialogz&Completing the [ProductName] InstallerÚDescriptionéë   ÚReturnÚ
FilesInUseé   ÚRetryF)Úbitmapr   é   éÈ   z{\DlgFontBold8}Files in Useé   i  z8Some files that need to be updated are currently in use.ÚTexté7   iJ  z²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.ÚListÚListBoxék   é‚   é   ÚFileInUseProcessÚIgnorer   r!   ée   i  Ú	ErrorTextr  é0   r·   ÚNéx   éH   éQ   é   ÚNoÚErrorNoÚYéð   ÚYesÚErrorYesÚAÚAbortÚ
ErrorAbortÚCé*   ÚErrorCancelÚIÚErrorIgnoreÚOéŸ   ÚOkÚErrorOkÚRéÆ   Ú
ErrorRetryÚ	CancelDlgi  éU   éÂ   é   z;Are you sure you want to cancel [ProductName] installation?é9   r,   r-   é„   ÚWaitForCostingDlgzRPlease wait while the installer finishes determining your disk space requirements.éf   r  é(   zOPlease wait while the Installer prepares to guide you through the installation.z&Welcome to the [ProductName] Installerén   zPondering...Ú
ActionDataé‡   r9   ÚSpawnDialogr  zSelect Python InstallationsÚHintz9Select the Python locations where %s should be installed.zNext >z[TARGETDIR]z[SourceDir])Úorderingz[TARGETDIR%s]z FEATURE_SELECTED AND &Python%s=3ÚSpawnWaitDialogrN   ÚFeaturesÚSelectionTreer#   ÚFEATUREÚPathEditz[FEATURE_SELECTED]Ú1z!FEATURE_SELECTED AND &Python%s<>3ÚOtherz$Provide an alternate Python locationÚEnableÚShowÚDisableÚHideé×   é   r²   ÚDiskCostDlgÚ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).Ú
VolumeListÚVolumeCostListéd   é–   i  z{120}{70}{70}{70}{70}g      à?r  ÚAdminInstallzGSelect whether to install [ProductName] for all users of this computer.r  r  é   zInstall for all usersÚJUSTMEé   zInstall just for mez
[ALLUSERS]zWhichUsers="ALL"r  z({\DlgFontBold8}[Progress1] [ProductName]é#   éA   zYPlease wait while the Installer [Progress2] [ProductName]. This may take several minutes.ÚStatusLabelzStatus:ÚProgressBari  zProgress doneÚSetProgressÚProgressr  z)Welcome to the [ProductName] Setup WizardÚBodyTexté?   z:Select whether you want to repair or remove [ProductName].ÚRepairRadioGroupél   r  r  rÛ   z&Repair [ProductName]ÚRemover   zRe&move [ProductName]z[REINSTALL]zMaintenanceForm_Action="Repair"z[Progress1]Ú	Repairingz[Progress2]ÚrepairsÚ	Reinstallr  z[REMOVE]zMaintenanceForm_Action="Remove"é   ÚRemovingé   Úremovesé   é   z MaintenanceForm_Action<>"Change")r   r   r   r  r  r   r%   r5   r8   r1   ÚeventÚcontrolr   r/   Úmappingri   r   r_   rº   Ú	conditionr>   Ú
radiogroupÚadd)r   r   ÚxÚyr   r   r%   ÚmodalÚmodelessÚtrack_disk_spaceÚfatalrH   Ú	user_exitÚexit_dialogÚinuseÚerrorr8   ÚcostingÚprepÚseldlgÚorderr™   rç   Úinstall_other_condÚdont_install_other_condÚcostÚ
whichusersÚgÚprogressÚmaintr   r   r   r¦   §  sî  þÿ	ÿ
ÿ
ÿÿÿ
ÿÿÿ
ÿüÿÿÿÿü       ÿÿÿÿÿÿ
ÿ
ÿÿ
þÿÿÿÿÿÿÿÿÿ
ÿÿÿÿÿÿ
ÿÿzbdist_msi.add_uic                 C   s<   | j rd|| j| j f }nd|| jf }tj | j|¡}|S )Nz%s.%s-py%s.msiz	%s.%s.msi)rZ   rV   rf   rg   rh   r[   )r   rª   Ú	base_namer«   r   r   r   r‘   å  s   ÿz bdist_msi.get_installer_filename)r?   r@   rA   Údescriptionr   Úuser_optionsÚboolean_optionsrl   rº   r   r`   rr   rŽ   r¤   r£   r¥   r¦   r‘   Ú__classcell__r   r   rS   r   rC   U   s>    ÿÿé([66&  @rC   )rB   rf   r‡   rP   Údistutils.corer   Údistutils.dir_utilr   Údistutils.sysconfigr   Údistutils.versionr   Údistutils.errorsr   Údistutils.utilr   Ú	distutilsr   rš   r	   r
   r   r   r   r   r   r   rC   r   r   r   r   Ú<module>   s    >