3
]<                 @   sp   d Z ddlZddlZddlmZ ddlmZ ddlmZ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)create_treeremove_tree)*)get_python_version)logc               @   s   e Zd ZdZd4ddde  fd6d8d9d:d;d<d=d>d?d@dAgZddddgZd&d' Zd(d) Zd*d+ Z	d,d- Z
dBd.d/Zd0d1 Zd2d3 ZdS )Cbdist_wininstz-create an executable installer for MS Windows
bdist-dir=N1temporary directory for creating the distributionz
plat-name=pz;platform name to embed in generated filenames (default: %s)	keep-tempkz/keep the pseudo-installation tree around after z!creating the distribution archivetarget-version=z!require a specific python versionz on the target systemno-target-compilec/do not compile .py to .pyc on the target systemno-target-optimizeo;do not compile .py to .pyo (optimized) on the target system	dist-dir=d-directory to put final built distributions inbitmap=b>bitmap to use for the installer instead of python-powered logotitle=t?title to display on the installer background instead of default
skip-build2skip rebuilding everything (for testing/debugging)install-script=Ubasename of installation script to be run after installation or before deinstallationpre-install-script={Fully qualified filename of a script to be run before any files are installed.  This script need not be in the distributionuser-access-control=specify Vista's UAC handling - 'none'/default=no handling, 'auto'=use UAC if target Python installed for all users, 'force'=always use UACc             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)self r5   5/usr/lib/python3.6/distutils/command/bdist_wininst.pyinitialize_options:   s    z bdist_wininst.initialize_optionsc             C   s   | j dd	 | jd krR| jr6| jr6| jjd}| j|_| jdj}tj	j
|d| _| js^d| _| j r| jj rt }| jr| j|krtd|f || _| j dd
d | jrx2| jjD ]}| jtj	j|krP qW td| j d S )Nbdistr0   Zwininst zMtarget version can only be %s, or the '--skip-build' option must be specifiedr-   r(   z(install_script '%s' not found in scripts)r0   r0   )r-   r-   )r(   r(   )Zset_undefined_optionsr'   r0   r(   distributionZget_command_objget_finalized_command
bdist_baseospathjoinr,   has_ext_modulesr   ZDistutilsOptionErrorr1   scriptsbasename)r4   r8   r<   Zshort_versionscriptr5   r5   r6   finalize_optionsJ   s4    

zbdist_wininst.finalize_optionsc             C   s  t jdkr&| jj s| jj r&td| js6| jd | jddd}| j	|_
| j|_d|_| j|_| jd}d|_d|_| jj r| j}|s| jstd	d
t jd d  }d| j|f }| jd}tjj|jd| |_x6dD ].}|j }|dk r|d }t|d| | qW tjd| j	 |j  t jjdtjj| j	d |j  t jd= ddlm } | }	| jj! }
| j"|	d| j	d}| j#||
| j$ | jj rt% }nd}| jj&j'd|| j(|
f tj)d| tj*| | j+st,| j	| j-d d S )Nwin32z^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.%d   z.%s-%sZlibpurelibplatlibheadersrA   dataz/Include/$dist_nameZinstall_zinstalling to %sZPURELIB)mktempzip)Zroot_diranyr	   zremoving temporary file '%s')dry_run)rK   rL   rM   rA   rN   ).sysplatformr:   r@   Zhas_c_librariesZDistutilsPlatformErrorr0   Zrun_commandZreinitialize_commandr'   rootZwarn_dirr(   compileoptimizer,   AssertionErrorversion_infor;   r=   r>   r?   Z
build_baseZ	build_libuppersetattrr   infoZensure_finalizedinsertrunZtempfilerO   get_fullnameZmake_archive
create_exer.   r   Z
dist_filesappendget_installer_filenamedebugremover)   r   rR   )r4   rG   rI   r,   Zplat_specifierrF   keyvaluerO   Zarchive_basenamefullnamearcnameZ	pyversionr5   r5   r6   r^   p   sf    













zbdist_wininst.runc             C   s`  g }| j j}|jd |jpdd }dd }xJdD ]B}t||d}|r2|d|j ||f  }|jd|||f  q2W |jd | jr|jd| j  |jd||  |jd| j   |jd| j   | j	r|jd| j	  | j
 r|jd| j
  | jp| j j }|jd||  dd l}dd l}	d|j|j |	jf }
|jd|
  dj|S )Nz
[metadata]r9   
c             S   s   | j ddS )Nri   z\n)replace)sr5   r5   r6   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)rm   rn   ro   rp   rq   rr   rs   rt   )r:   metadatara   Zlong_descriptiongetattr
capitalizer1   r*   r+   r,   r3   r/   r_   time	distutilsZctime__version__r?   )r4   linesru   r\   rl   rr   rN   r/   rx   ry   Z
build_infor5   r5   r6   get_inidata   s<    

zbdist_wininst.get_inidatac             C   s  dd l }| j| j | j }| j|}| jd|  |rPt|dj }t|}nd}t|d}	|	j	| j
  |rz|	j	| t|tr|jd}|d }| jrt| jddd	}
|
j jd}W d Q R X || d
 }n|d }|	j	| |jddt||}|	j	| |	j	t|dj  d S )Nr   zcreating %srbwbmbcs    rzlatin-1)encodings   
 z<iiii{V4)structZmkpathr-   r|   rb   Zannounceopenreadlenwriteget_exe_bytes
isinstancestrencoder2   Zpack)r4   rh   rg   r.   r   Zcfgdatainstaller_nameZ
bitmapdataZ	bitmaplenfilerC   Zscript_dataheaderr5   r5   r6   r`      s:    








zbdist_wininst.create_exec             C   sD   | j r&tjj| jd|| j| j f }ntjj| jd|| jf }|S )Nz%s.%s-py%s.exez	%s.%s.exe)r,   r=   r>   r?   r-   r(   )r4   rg   r   r5   r5   r6   rb   $  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@yddlm} W n tk
r   d
}Y nX |jdd }|d }tjjt	}| j
dkr| j
d d dkr| j
dd  }nd}tjj|d||f }yt|d}W n8 tk
rD }	 ztt|	d|  W Y d d }	~	X nX z|j S |j  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.0rE      winr9   zwininst-%s%s.exer}   z), %s not included in the Debian packages.)r   r,   Zmsvcrtr   ImportError	partitionr=   r>   dirname__file__r(   r?   r   IOErrorZDistutilsFileErrorr   r   close)
r4   Zcur_versionZbvr   majorZ	directoryZsfixfilenamefer5   r5   r6   r   1  s>    	





&zbdist_wininst.get_exe_bytes)r
   Nr   Pkeep the pseudo-installation tree around after creating the distribution archive)r   r   r   6require a specific python version on the target system)r   Nr   )r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   Nr    )r!   Nr"   )r#   Nr$   )r%   Nr&   )N)__name__
__module____qualname__ro   r   Zuser_optionsZboolean_optionsr7   rD   r^   r|   r`   rb   r   r5   r5   r5   r6   r	      sN                 &Q.
5r	   )__doc__rS   r=   Zdistutils.corer   Zdistutils.utilr   Zdistutils.dir_utilr   r   Zdistutils.errorsZdistutils.sysconfigr   ry   r   r	   r5   r5   r5   r6   <module>   s   