
(h>                 @   s   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
 Td d l m Z d d l m Z Gd	 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 d7 d d d e   f d d	 d
 d f d d d d f d8 d9 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/ d0   Z d d1 d2  Z d3 d4   Z d5 d6   Z   S)A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)z	keep-tempkz/keep the pseudo-installation tree around after z!creating the distribution archivez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 UACwin32c                s*   t    j | |   t j 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__ Q/tmp/pip-build-kmztzv_d/setuptools/setuptools/_distutils/command/bdist_wininst.pyr'   ?   s    	zbdist_wininst.__init__c             C   sy   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/   r0   initialize_optionsE   s    												z bdist_wininst.initialize_optionsc             C   sG  |  j  d d	  |  j d  k ry |  j rO |  j rO |  j j d  } |  j | _ |  j d  j } t j	 j
 | d  |  _ |  j s d |  _ |  j r |  j j   r t   } |  j r |  j | k r t d | f   | |  _ |  j  d d
 d  |  j rCxC |  j j D]" } |  j t j	 j |  k r
Pq
Wt d |  j   d  S)Nbdistr:   Zwininst zMtarget version can only be %s, or the '--skip-build' option must be specifiedr7   r2   z(install_script '%s' not found in scripts)
skip_buildrA   )dist_dirrB   )	plat_namerC   )set_undefined_optionsr1   r:   r2   distributionget_command_objget_finalized_command
bdist_baseospathjoinr6   has_ext_modulesr   DistutilsOptionErrorr;   scriptsbasename)r+   r?   rH   Zshort_versionscriptr/   r/   r0   finalize_optionsU   s4    						zbdist_wininst.finalize_optionsc             C   s  t  j d k r9 |  j j   s- |  j j   r9 t d   |  j sO |  j d  |  j d d d } |  j	 | _
 |  j | _ d | _ |  j | _ |  j d  } d | _ d | _ |  j j   r=|  j } | s |  j s t d	   d
 t  j d  d  } d |  j | f } |  j d  } t j j | j d |  | _ xD d D]< } | j   } | d k rl| d } t | d | |  qDWt 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 d |  j	 } |  j# | |
 |  j$  |  j j   rNt%   } n d } |  j j& j' d | |  j( |
  f  t j) d |  t j* |  |  j+ st, |  j	 d |  j- d  S)Nr$   z^distribution contains extensions and/or C libraries; must be compiled on a Windows 32 platformbuildinstallreinit_subcommands   r   install_libz Should have already checked thisz%d.%dr%   z.%s-%slibpurelibplatlibheadersrN   dataz/Include/$dist_nameinstall_zinstalling to %sZPURELIB)mktempziproot_diranyr   zremoving temporary file '%s'dry_run)zpurelibzplatlibzheaderszscriptszdata).sysplatformrE   rL   has_c_librariesDistutilsPlatformErrorr:   run_commandreinitialize_commandr1   rootwarn_dirr2   compileoptimizer6   AssertionErrorversion_inforG   rI   rJ   rK   
build_base	build_libuppersetattrr   infoensure_finalizedinsertruntempfiler]   get_fullnamemake_archive
create_exer8   r   
dist_filesappendget_installer_filenamedebugremover3   r   ra   )r+   rS   rV   r6   plat_specifierrR   keyvaluer]   Zarchive_basenamefullnamearcnameZ	pyversionr/   r/   r0   ru   {   sf    						

%

		zbdist_wininst.runc             C   s  g  } |  j  j } | j d  | j p+ d d } d d   } x{ d d d d	 d
 d d d g D][ } t | | d  } | r] | d | j   | |  f } | j d | | |  f  q] W| j d  |  j r | j d |  j  | j d | |   | j d |  j  | j d |  j  |  j	 rD| j d |  j	  |  j
 ra| j d |  j
  |  j pv|  j  j   } | j d | |   d d  l } d d  l }	 d | j | j    |	 j f }
 | j d |
  d j |  S)Nz
[metadata]r@   
c             S   s   |  j  d d  S)Nr   z\n)replace)sr/   r/   r0   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)rE   metadatar{   long_descriptiongetattr
capitalizer;   r4   r5   r6   r=   r9   rw   time	distutilsctime__version__rK   )r+   linesr   rr   r   r   r[   r9   r   r   Z
build_infor/   r/   r0   get_inidata   s<    !			zbdist_wininst.get_inidatac             C   s  d d  l  } |  j |  j  |  j   } |  j |  } |  j d |  | r t | d   } | j   } Wd  QRXt |  }	 n d }	 t | d  }
 |
 j	 |  j
    | r |
 j	 |  t | t  r | j d  } | d } |  j r9t |  j d d d	  } | j   j d	  } Wd  QRX| | d
 } n
 | d } |
 j	 |  | j d d t |  |	  } |
 j	 |  t | d   } |
 j	 | j    Wd  QRXWd  QRXd  S)Nr   zcreating %srbwbmbcss    rencodingzlatin-1s   
 z<iiii{V4)structmkpathr7   r   r|   announceopenreadlenwriteget_exe_bytes
isinstancestrencoder<   pack)r+   r   r   r8   r   Zcfgdatainstaller_namefZ
bitmapdataZ	bitmaplenfilerP   Zscript_dataheaderr/   r/   r0   ry      s>    
	
			zbdist_wininst.create_exec             C   s`   |  j  r7 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)r6   rI   rJ   rK   r7   r2   )r+   r   r   r/   r/   r0   r|   1  s    	z$bdist_wininst.get_installer_filenamec       	      C   s  t    } |  j r |  j | k  r |  j d k  r9 d } q |  j d k rQ d } q |  j d k ri d } q |  j d k r d } q |  j d k r d	 } q d
 } nL y d d l m } Wn t k
 r d
 } Yn 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  } t | d  } z | j   SWd  | j   Xd  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$      winr@   zwininst-%s%s.exer   )r   r6   msvcrtr   ImportError	partitionrI   rJ   dirname__file__r2   rK   r   r   close)	r+   Zcur_versionZbvr   major	directoryZsfixfilenamer   r/   r/   r0   r   >  s8    								
(zbdist_wininst.get_exe_bytes)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#   )__name__
__module____qualname__r   r   user_optionsboolean_optionsrb   rc   Z_unsupportedr'   r>   rQ   ru   r   ry   r|   r   r/   r/   )r.   r0   r      sR    
         			&Q.7r   )__doc__rI   rb   r(   distutils.corer   distutils.utilr   distutils.dir_utilr   Zdistutils.errorsdistutils.sysconfigr   r   r   r   r/   r/   r/   r0   <module>   s   
