o
    Ëý°jž>  ã                   @   st   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
T ddlmZ ddlmZ G d	d
„ d
eƒZdS )zzdistutils.command.bdist_wininst

Implements the Distutils 'bdist_wininst' command: create a windows installer
exe-program.é    N)ÚCommand)Úget_platform)Úremove_tree)Ú*)Úget_python_version)Úlogc                       s–   e Zd ZdZddddeƒ  fdddd	d
ddddddgZg d¢ZejdkZ	‡ fdd„Z
dd„ Zdd„ Zdd„ Zdd„ Zd$dd„Zd d!„ Zd"d#„ Z‡  ZS )%Úbdist_wininstz-create an executable installer for MS Windows)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)zbitmap=Úbz>bitmap to use for the installer instead of python-powered logo)ztitle=Útz?title to display on the installer background instead of default)ú
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)zuser-access-control=NzŠspecify Vista's UAC handling - 'none'/default=no handling, 'auto'=use UAC if target Python installed for all users, 'force'=always use UAC)r
   r   r   r   Úwin32c                    s$   t ƒ j|i |¤Ž t dtd¡ d S )Nz^bdist_wininst command is deprecated since Python 3.8, use bdist_wheel (wheel packages) insteadé   )ÚsuperÚ__init__ÚwarningsÚwarnÚDeprecationWarning)ÚselfÚargsÚkw©Ú	__class__© úž/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/setuptools/_distutils/command/bdist_wininst.pyr   ?   s   þzbdist_wininst.__init__c                 C   sR   d | _ d | _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ÚbitmapÚtitleÚ
skip_buildÚinstall_scriptÚpre_install_scriptÚuser_access_control)r   r    r    r!   Úinitialize_optionsE   s   
z bdist_wininst.initialize_optionsc                 C   sä   |   dd¡ | jd u r)| jr| jr| j d¡}| j|_|  d¡j}tj	 
|d¡| _| js/d| _| jsL| j ¡ rLtƒ }| jrI| j|krItd|f ƒ‚|| _|   ddd¡ | jrp| jjD ]}| jtj	 |¡krh d S qZtd| j ƒ‚d S )	NÚbdist)r+   r+   ÚwininstÚ zMtarget version can only be %s, or the '--skip-build' option must be specified)r(   r(   )r#   r#   z(install_script '%s' not found in scripts)Úset_undefined_optionsr"   r+   r#   ÚdistributionÚget_command_objÚget_finalized_commandÚ
bdist_baseÚosÚpathÚjoinr'   Úhas_ext_modulesr   ÚDistutilsOptionErrorr,   ÚscriptsÚbasename)r   r0   r7   Úshort_versionÚscriptr    r    r!   Úfinalize_optionsU   sB   
ÿÿþÿÿÿûzbdist_wininst.finalize_optionsc                 C   sî  t jdkr| j ¡ s| j ¡ rtdƒ‚| js|  d¡ | jddd�}| j	|_
| j|_d|_| j|_|  d¡}d|_d|_| j ¡ rm| j}|sV| jsMJ d	ƒ‚d
t jd d…  }d| j|f }|  d¡}tj |jd| ¡|_dD ]}| ¡ }|dkr}|d }t|d| |ƒ qot d| j	¡ | ¡  t j dtj | j	d¡¡ | ¡  t jd= ddlm} |ƒ }	| j  ¡ }
| j!|	d| j	d�}|  "||
| j#¡ | j ¡ rÎt$ƒ }nd}| jj% &d||  '|
¡f¡ t (d|¡ t )|¡ | j*sõt+| j	| j,d� d S d S )Nr   z^distribution contains extensions and/or C libraries; must be compiled on a Windows 32 platformÚbuildÚinstallé   )Úreinit_subcommandsr   Úinstall_libz Should have already checked thisz%d.%dr   z.%s-%sÚlib)ÚpurelibÚplatlibÚheadersr=   ÚdatarJ   z/Include/$dist_nameÚinstall_zinstalling to %sÚPURELIB)ÚmktempÚzip)Úroot_dirÚanyr   zremoving temporary file '%s')Údry_run)-ÚsysÚplatformr4   r;   Úhas_c_librariesÚDistutilsPlatformErrorr+   Úrun_commandÚreinitialize_commandr"   ÚrootÚwarn_dirr#   ÚcompileÚoptimizer'   Úversion_infor6   r8   r9   r:   Ú
build_baseÚ	build_libÚupperÚsetattrr   ÚinfoÚensure_finalizedÚinsertÚrunÚtempfilerN   Úget_fullnameÚmake_archiveÚ
create_exer)   r   Ú
dist_filesÚappendÚget_installer_filenameÚdebugÚremover$   r   rR   )r   rC   rF   r'   Úplat_specifierrB   ÚkeyÚvaluerN   Úarchive_basenameÚfullnameÚarcnameÚ	pyversionr    r    r!   re   {   sv   
ÿþÿ




ÿþ
ÿ
ÿ
ÿzbdist_wininst.runc                 C   sX  g }| j j}| d¡ |jpdd }dd„ }dD ]!}t||dƒ}|r9|d| ¡ ||ƒf  }| d|||ƒf ¡ q| d	¡ | jrJ| d
| j ¡ | d||ƒ ¡ | d| j  ¡ | d| j  ¡ | j	rp| d| j	 ¡ | j
r{| d| j
 ¡ | jp‚| j  ¡ }| d||ƒ ¡ dd l}dd l}	d| | ¡ ¡|	jf }
| d|
 ¡ d |¡S )Nz
[metadata]r2   Ú
c                 S   s   |   dd¡S )Nrv   z\n)Úreplace)Úsr    r    r!   ÚescapeÙ   s   z)bdist_wininst.get_inidata.<locals>.escape)ÚauthorÚauthor_emailÚdescriptionÚ
maintainerÚmaintainer_emailÚnameÚurlÚversionz
    %s: %sz%s=%sz
[Setup]zinstall_script=%szinfo=%sztarget_compile=%dztarget_optimize=%dztarget_version=%szuser_access_control=%sztitle=%sr   zBuilt %s with distutils-%szbuild_info=%s)r4   Úmetadatark   Úlong_descriptionÚgetattrÚ
capitalizer,   r%   r&   r'   r.   r*   rg   ÚtimeÚ	distutilsÚctimeÚ__version__r:   )r   Úlinesr‚   rb   ry   r   rK   r*   r†   r‡   Ú
build_infor    r    r!   Úget_inidataÌ   s@   
ÿ€
ÿ
zbdist_wininst.get_inidataNc              	   C   sª  dd l }|  | j¡ |  ¡ }|  |¡}|  d| ¡ |r:t|dƒ�}| ¡ }W d   ƒ n1 s0w   Y  t|ƒ}	nd}	t|dƒ�Š}
|
 	|  
¡ ¡ |rP|
 	|¡ t|tƒrZ| d¡}|d }| jr‡t| jddd	��}| ¡  d¡}W d   ƒ n1 s{w   Y  || d
 }n|d }|
 	|¡ | ddt|ƒ|	¡}|
 	|¡ t|dƒ�}|
 	| ¡ ¡ W d   ƒ n1 s¶w   Y  W d   ƒ d S W d   ƒ d S 1 sÎw   Y  d S )Nr   zcreating %sÚrbÚwbÚmbcsó    Úrzlatin-1)Úencodings   
 z<iiii{V4)ÚstructÚmkpathr(   rŒ   rl   ÚannounceÚopenÚreadÚlenÚwriteÚget_exe_bytesÚ
isinstanceÚstrÚencoder-   Úpack)r   rt   rs   r)   r“   ÚcfgdataÚinstaller_nameÚfÚ
bitmapdataÚ	bitmaplenÚfiler@   Úscript_dataÚheaderr    r    r!   ri   ú   sP   

ÿ



ÿþ
ý
ÿÝ#"Ýzbdist_wininst.create_exec                 C   sF   | j rtj | jd|| j| j f ¡}|S tj | jd|| jf ¡}|S )Nz%s.%s-py%s.exez	%s.%s.exe)r'   r8   r9   r:   r(   r#   )r   rs   r    r    r    r!   rl   1  s   
ÿÿ
þÿz$bdist_wininst.get_installer_filenamec           	      C   s$  t ƒ }| jr6| j|k r6| jdk rd}nB| jdkrd}n:| jdkr#d}n2| jdkr+d}n*| jdkr3d	}n"d
}nzddlm} W n tyI   d
}Y nw | d¡d }|d }tj t	¡}| j
dkrq| j
d d… dkrq| j
dd … }nd}tj |d||f ¡}t|dƒ}z	| ¡ W | ¡  S | ¡  w )Nz2.4z6.0z7.1z2.5z8.0z3.2z9.0z3.4z10.0z14.0r   )ÚCRT_ASSEMBLY_VERSIONÚ.z.0r   é   Úwinr2   zwininst-%s%s.exer�   )r   r'   Úmsvcrtr§   ÚImportErrorÚ	partitionr8   r9   ÚdirnameÚ__file__r#   r:   r–   r—   Úclose)	r   Úcur_versionÚbvr§   ÚmajorÚ	directoryÚsfixÚfilenamer¡   r    r    r!   rš   >  s:   	




þ
zbdist_wininst.get_exe_bytes)N)Ú__name__Ú
__module__Ú__qualname__r|   r   Úuser_optionsÚboolean_optionsrS   rT   Ú_unsupportedr   r/   rA   re   rŒ   ri   rl   rš   Ú__classcell__r    r    r   r!   r      s<    ÿÿá%
&Q
.7r   )Ú__doc__r8   rS   r   Údistutils.corer   Údistutils.utilr   Údistutils.dir_utilr   Údistutils.errorsÚdistutils.sysconfigr   r‡   r   r   r    r    r    r!   Ú<module>   s    