U
    +|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ddddg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 UACr
   r   r   r   Úwin32c                    s    t ƒ j||Ž 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__© úsC:\Users\snmko\Desktop\web_content\django_cbt\venv\Lib\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 krR| jr6| jr6| j d¡}| j|_|  d¡j}tj	 
|d¡| _| js^d| _| js˜| j ¡ r˜tƒ }| jr’| j|kr’td|f ƒ‚|| _|   ddd¡ | jrÞ| jjD ]}| jtj	 |¡kr´ qÞq´td| j ƒ‚d S )	NÚbdist)r+   r+   Z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   r6   Zshort_versionÚscriptr    r    r!   Úfinalize_optionsU   s>    
ÿÿþÿÿzbdist_wininst.finalize_optionsc                 C   sî  t jdkr&| j ¡ s| j ¡ r&tdƒ‚| js6|  d¡ | jddd�}| j	|_
| j|_d|_| j|_|  d¡}d|_d|_| j ¡ rÚ| j}|s¬| jsštd	ƒ‚d
t jd d…  }d| j|f }|  d¡}tj |jd| ¡|_dD ],}| ¡ }|dkrú|d }t|d| |ƒ qÞt 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 )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<   ÚdatarH   z/Include/$dist_nameÚinstall_zinstalling to %sZPURELIB)ÚmktempÚzip)Úroot_dirÚanyr   zremoving temporary file '%s')Údry_run).ÚsysÚplatformr3   r:   Úhas_c_librariesÚDistutilsPlatformErrorr+   Úrun_commandÚreinitialize_commandr"   ÚrootÚwarn_dirr#   ÚcompileÚoptimizer'   ÚAssertionErrorÚversion_infor5   r7   r8   r9   Ú
build_baseÚ	build_libÚupperÚsetattrr   ÚinfoÚensure_finalizedÚinsertÚrunÚtempfilerK   Úget_fullnameÚmake_archiveÚ
create_exer)   r   Ú
dist_filesÚappendÚget_installer_filenameÚdebugÚremover$   r   rO   )r   rA   rD   r'   Úplat_specifierr@   ÚkeyÚvaluerK   Zarchive_basenameÚfullnameÚarcnameZ	pyversionr    r    r!   rc   {   st    
ÿþÿ




ÿþ
ÿÿ
zbdist_wininst.runc                 C   sZ  g }| j j}| d¡ |jpdd }dd„ }dD ]B}t||dƒ}|r0|d| ¡ ||ƒf  }| d|||ƒf ¡ q0| d	¡ | jr”| d
| j ¡ | d||ƒ ¡ | d| j  ¡ | d| j  ¡ | j	rà| d| j	 ¡ | j
rö| d| j
 ¡ | j�p| j  ¡ }| d||ƒ ¡ dd l}dd l}	d| | ¡ ¡|	jf }
| d|
 ¡ d |¡S )Nz
[metadata]r1   Ú
c                 S   s   |   dd¡S )Nrr   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)r3   Úmetadatari   Úlong_descriptionÚgetattrÚ
capitalizer,   r%   r&   r'   r.   r*   re   ÚtimeÚ	distutilsÚctimeÚ__version__r9   )r   Úlinesr~   r`   ru   r{   rI   r*   r‚   rƒ   Z
build_infor    r    r!   Úget_inidataÌ   s>    
ÿ
ÿzbdist_wininst.get_inidataNc              
   C   sH  dd l }|  | j¡ |  ¡ }|  |¡}|  d| ¡ |r`t|dƒ�}| ¡ }W 5 Q R X t|ƒ}	nd}	t|dƒ�Ð}
|
 	|  
¡ ¡ |rŒ|
 	|¡ t|tƒr | d¡}|d }| jræt| jddd	��}| ¡  d¡}W 5 Q R X || d
 }n|d }|
 	|¡ | ddt|ƒ|	¡}|
 	|¡ t|dƒ�}|
 	| ¡ ¡ W 5 Q R X W 5 Q R X d S )Nr   zcreating %sÚrbÚwbÚmbcsó    Úrzlatin-1)Úencodings   
 z<iiii{V4)ÚstructÚmkpathr(   r‡   rj   ÚannounceÚopenÚreadÚlenÚwriteÚget_exe_bytesÚ
isinstanceÚstrÚencoder-   Úpack)r   rq   rp   r)   rŽ   ZcfgdataÚinstaller_nameÚfZ
bitmapdataZ	bitmaplenÚfiler>   Zscript_dataÚheaderr    r    r!   rg   ú   sD    




ÿ
ý
zbdist_wininst.create_exec                 C   sD   | j r&tj | jd|| j| j f ¡}ntj | jd|| jf ¡}|S )Nz%s.%s-py%s.exez	%s.%s.exe)r'   r7   r8   r9   r(   r#   )r   rp   rš   r    r    r!   rj   1  s    
ÿÿ
ÿz$bdist_wininst.get_installer_filenamec           	      C   s$  t ƒ }| jrl| j|k rl| jdk r&d}q¬| jdkr6d}q¬| jdkrFd}q¬| jdkrVd}q¬| jdkrfd	}q¬d
}n@zddlm} W n tk
r”   d
}Y nX | d¡d }|d }tj t	¡}| j
dkrä| j
d d… dkrä| j
dd … }nd}tj |d||f ¡}t|dƒ}z| ¡ W ¢S | ¡  X d S )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   é   Úwinr1   zwininst-%s%s.exerˆ   )r   r'   Úmsvcrtrž   ÚImportErrorÚ	partitionr7   r8   ÚdirnameÚ__file__r#   r9   r‘   Úcloser’   )	r   Zcur_versionZbvrž   ÚmajorÚ	directoryZsfixÚfilenamer›   r    r    r!   r•   >  s8    	






zbdist_wininst.get_exe_bytes)N)Ú__name__Ú
__module__Ú__qualname__rx   r   Úuser_optionsÚboolean_optionsrP   rQ   Z_unsupportedr   r/   r?   rc   r‡   rg   rj   r•   Ú__classcell__r    r    r   r!   r      s>   ÿÿá%ÿ
&Q.
7r   )Ú__doc__r7   rP   r   Údistutils.corer   Údistutils.utilr   Údistutils.dir_utilr   Údistutils.errorsÚdistutils.sysconfigr   rƒ   r   r   r    r    r    r!   Ú<module>   s   