o
    *‘siC=  ã                   @   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__© ú�C:\Users\PC\students\dividedattentionclub\pushnotificationexperiment\lib\python3.10\site-packages\setuptools/_distutils/command/bdist_wininst.pyr   Z   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_optionsc   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+   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)Zset_undefined_optionsr"   r+   r#   ÚdistributionZget_command_objÚget_finalized_commandÚ
bdist_baseÚosÚpathÚjoinr'   Úhas_ext_modulesr   ZDistutilsOptionErrorr,   ÚscriptsÚbasename)r   r0   r4   Zshort_versionÚscriptr    r    r!   Úfinalize_optionsr   s@   
ÿÿýÿÿû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é   )Zreinit_subcommandsr   Úinstall_libz Should have already checked thisz%d.%dr   z.%s-%sÚlib)ÚpurelibÚplatlibÚheadersr9   ÚdatarD   z/Include/$dist_nameZinstall_zinstalling to %sZPURELIB)ÚmktempÚzip)Úroot_dirÚanyr   zremoving temporary file '%s')Údry_run)-ÚsysÚplatformr2   r8   Zhas_c_librariesZDistutilsPlatformErrorr+   Úrun_commandZreinitialize_commandr"   ÚrootZwarn_dirr#   ÚcompileÚoptimizer'   Úversion_infor3   r5   r6   r7   Z
build_baseZ	build_libÚupperÚsetattrr   ÚinfoZensure_finalizedÚinsertÚrunÚtempfilerF   Úget_fullnameÚmake_archiveÚ
create_exer)   r   Z
dist_filesÚappendÚget_installer_filenameÚdebugÚremover$   r   rJ   )r   r>   r@   r'   Zplat_specifierr=   ÚkeyÚvaluerF   Zarchive_basenameÚfullnameÚarcnameZ	pyversionr    r    r!   rV   š   sh   
ÿÿÿ





ÿ
ÿ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]r1   Ú
c                 S   s   |   dd¡S )Nrc   z\n)Úreplace)Úsr    r    r!   Úescape÷   s   z)bdist_wininst.get_inidata.<locals>.escape)ÚauthorZauthor_emailÚdescriptionZ
maintainerZ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)r2   Úmetadatar[   Zlong_descriptionÚgetattrÚ
capitalizer,   r%   r&   r'   r.   r*   rX   ÚtimeÚ	distutilsÚctimeÚ__version__r7   )r   Úlinesrl   rT   rf   ri   rE   r*   ro   rp   Z
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)ÚstructZmkpathr(   rt   r\   ZannounceÚopenÚreadÚlenÚwriteÚget_exe_bytesÚ
isinstanceÚstrÚencoder-   Úpack)r   rb   ra   r)   r{   ZcfgdataÚinstaller_nameÚfZ
bitmapdataZ	bitmaplenÚfiler;   Zscript_dataÚheaderr    r    r!   rZ   "  sL   

ÿ



ÿ
ü
ÿÝ#"Ý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'   r5   r6   r7   r(   r#   )r   ra   r…   r    r    r!   r\   Y  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   é   Úwinr1   zwininst-%s%s.exeru   )r   r'   Úmsvcrtr‰   ÚImportErrorÚ	partitionr5   r6   ÚdirnameÚ__file__r#   r7   r|   r}   Úclose)	r   Zcur_versionZbvr‰   ÚmajorÚ	directoryZsfixÚfilenamer†   r    r    r!   r€   h  s:   	




þ
zbdist_wininst.get_exe_bytes)N)Ú__name__Ú
__module__Ú__qualname__rh   r   Zuser_optionsZboolean_optionsrK   rL   Z_unsupportedr   r/   r<   rV   rt   rZ   r\   r€   Ú__classcell__r    r    r   r!   r      s>    ÿýÎ;
	(P
87r   )Ú__doc__r5   rK   r   Zdistutils.corer   Zdistutils.utilr   Zdistutils.dir_utilr   Zdistutils.errorsÚdistutils.sysconfigr   rp   r   r   r    r    r    r!   Ú<module>   s    