B M��j�<�@spdZddlZddlZddlmZddlmZddlmZm Z ddl Tddl m Z ddl mZGd d �d e�ZdS) 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�eZdZdZdddde�fdddd d d d d dddg ZddddgZejdkZ dd�Z dd�Z dd�Z dd�Z d%dd �Zd!d"�Zd#d$�ZdS)&� 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))z keep-temp�kzPkeep the pseudo-installation tree around after creating the distribution archive)ztarget-version=Nz6require a specific python version on the target system)zno-target-compile�cz/do not compile .py to .pyc on the target system)zno-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)zbitmap=�bz>bitmap to use for the installer instead of python-powered logo)ztitle=�tz?title to display on the installer background instead of default)z skip-buildNz2skip rebuilding everything (for testing/debugging))zinstall-script=NzUbasename of installation script to be run after installation or before deinstallation)zpre-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)zuser-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 UACz keep-tempzno-target-compilezno-target-optimizez skip-build�win32cCsRd|_d|_d|_d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ d|_ dS)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�r �D/opt/alt/python37/lib64/python3.7/distutils/command/bdist_wininst.py�initialize_options=sz bdist_wininst.initialize_optionscCs�|�dd�|jdkrR|jr6|jr6|j�d�}|j|_|�d�j}tj � |d�|_|j s^d|_ |js�|j� �r�t �}|j r�|j |kr�td|f��||_ |�ddd�|jr�x2|jjD]}|jtj �|�kr�Pq�Wtd|j��dS) N�bdist)rrZwininst�zMtarget version can only be %s, or the '--skip-build' option must be specified)rr)rrz(install_script '%s' not found in scripts)Zset_undefined_optionsrrr� distributionZget_command_obj�get_finalized_command� bdist_base�os�path�joinr�has_ext_modulesrZDistutilsOptionErrorr�scripts�basename)rr#r'Z short_version�scriptr r r!�finalize_optionsMs4      zbdist_wininst.finalize_optionsc Cs�tjdkr&|j��s|j��r&td��|js6|�d�|jddd�}|j |_ |j|_d|_ |j |_ |�d�}d|_ d|_|j��r�|j}|s�|js�td ��d tjdd �}d |j |f}|�d�}tj�|jd |�|_x4dD],}|��}|dkr�|d}t|d||�q�Wt�d|j �|��tj�dtj�|j d��|��tjd=ddlm }|�} |j�!�} |j"| d|j d�} |�#| | |j$�|j���r�t%�} nd} |jj&�'d| |�(| �f�t�)d| �t�*| �|j+�s�t,|j |j-d�dS)Nrz^distribution contains extensions and/or C libraries; must be compiled on a Windows 32 platform�build�install�)Zreinit_subcommandsr� install_libz Should have already checked thisz%d.%d�z.%s-%s�lib)ZpurelibZplatlib�headersr,�datar6z/Include/$dist_nameZinstall_zinstalling to %sZPURELIB)�mktemp�zip)Zroot_dir�anyr zremoving temporary file '%s')�dry_run).�sys�platformr%r+Zhas_c_librariesZDistutilsPlatformErrorrZ run_commandZreinitialize_commandr�rootZwarn_dirr�compile�optimizer�AssertionError� version_infor&r(r)r*Z build_baseZ build_lib�upper�setattrr�infoZensure_finalized�insert�runZtempfiler8� get_fullnameZ make_archive� create_exerrZ dist_files�append�get_installer_filename�debug�removerrr;) rr1r3rZplat_specifierr0�key�valuer8Zarchive_basename�fullname�arcnameZ pyversionr r r!rGssf                  zbdist_wininst.runc Cs^g}|jj}|�d�|jpdd}dd�}xJdD]B}t||d�}|r2|d|��||�f}|�d|||�f�q2W|�d �|jr�|�d |j�|�d ||��|�d |j �|�d |j �|j r�|�d|j �|j r�|�d|j �|j �p |j� �}|�d||��ddl }ddl} d|�|� ��| jf} |�d| �d�|�S)Nz [metadata]r$� cSs |�dd�S)NrRz\n)�replace)�sr r r!�escape�sz)bdist_wininst.get_inidata.<locals>.escape)ZauthorZ author_email� descriptionZ maintainerZmaintainer_email�nameZurl�versionz %s: %sz%s=%sz [Setup]zinstall_script=%szinfo=%sztarget_compile=%dztarget_optimize=%dztarget_version=%szuser_access_control=%sztitle=%srzBuilt %s with distutils-%sz build_info=%s)r%�metadatarJZlong_description�getattr� capitalizerrrrrrrH�time� distutilsZctime� __version__r*) r�linesrYrErUrWr7rr\r]Z build_infor r r!� get_inidata�s:    zbdist_wininst.get_inidataNc Csddl}|�|j�|��}|�|�}|�d|�|rPt|d���}t|�}nd}t|d�} | � |� ��|rz| � |�t |t �r�|� d�}|d}|jr�t|jddd ��} | ��� d�} WdQRX|| d }n|d}| � |�|�d d t|�|�} | � | �| � t|d����dS) Nrz creating %s�rb�wb�mbcs��rzlatin-1)�encodings z<iiii{V4)�structZmkpathrr`rKZannounce�open�read�len�write� get_exe_bytes� isinstance�str�encoderZpack) rrQrPrrgZcfgdata�installer_nameZ bitmapdataZ bitmaplen�filer.Z script_data�headerr r r!rI�s:          zbdist_wininst.create_execCsD|jr&tj�|jd||j|jf�}ntj�|jd||jf�}|S)Nz%s.%s-py%s.exez %s.%s.exe)rr(r)r*rr)rrPrpr r r!rK's  z$bdist_wininst.get_installer_filenamec Cs t�}|jrl|j|krl|jdkr&d}q�|jdkr6d}q�|jdkrFd}q�|jdkrVd}q�|jdkrfd }q�d }n@yd d lm}Wntk r�d }YnX|�d �d }|d}tj�t �}|j dkr�|j dd�dkr�|j dd�}nd}tj� |d||f�}t |d�}z|� �S|��XdS)Nz2.4z6.0z7.1z2.5z8.0z3.2z9.0z3.4z10.0z14.0r)�CRT_ASSEMBLY_VERSION�.z.0r��winr$zwininst-%s%s.exera)rrZmsvcrtrs� ImportError� partitionr(r)�dirname�__file__rr*rhri�close) rZ cur_versionZbvrs�majorZ directoryZsfix�filename�fr r r!rl4s8         zbdist_wininst.get_exe_bytes)N)�__name__� __module__� __qualname__rVrZ user_optionsZboolean_optionsr<r=Z _unsupportedr"r/rGr`rIrKrlr r r r!r s4 &Q. 5 r )�__doc__r<r(Zdistutils.corerZdistutils.utilrZdistutils.dir_utilrrZdistutils.errorsZdistutils.sysconfigrr]rr r r r r!�<module>s