U
    Ha>                     @   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=Nzspecify 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__ O/tmp/pip-unpacked-wheel-i11yjail/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 rt }| jr| j|krtd|f || _|  ddd | jr| jjD ]}| jtj	|kr qqt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std	d
t jd d  }d| j|f }| d}tj|jd| |_dD ],}| }|dkr|d }t|d| | qtd| j	 |  t jdtj| j	d |  t jd= ddlm } | }	| j! }
| j"|	d| j	d}| #||
| j$ | j rt% }nd}| jj&'d|| (|
f t)d| t*| | j+st,| 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rt| 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	}qd
}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   