
][\:                 @   s   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
 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)create_treeremove_tree)*)get_python_version)logc               @   s   e  Z d  Z d Z d4 d d d e   f d d	 d
 d f d d d d f d5 d6 d7 d8 d9 d: d; d< d= g Z d d d d g Z d& d'   Z d( d)   Z d* d+   Z	 d, d-   Z
 d d. d/  Z d0 d1   Z d2 d3   Z d S)>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=Tbasename of installation script to be run afterinstallation 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   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)self r3   5/usr/lib/python3.4/distutils/command/bdist_wininst.pyinitialize_options:   s    												z bdist_wininst.initialize_optionsc             C   s\  |  j  d d	  |  j d  k r |  j rR |  j rR |  j j d  } |  j | _ n  |  j d  j } t j	 j
 | d  |  _ n  |  j s d |  _ n  |  j r |  j j   r t   } |  j r |  j | k r t d | f   n  | |  _ n  |  j  d d
 d  |  j rXxI |  j j D]% } |  j t j	 j |  k rPqqWt d |  j   n  d  S)Nbdistr.   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)
skip_buildr8   )dist_dirr9   )	plat_namer:   )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)r2   r6   r=   Zshort_versionscriptr3   r3   r4   finalize_optionsJ   s4    				zbdist_wininst.finalize_optionsc             C   s  t  j d k r< |  j j   s- |  j j   r< t d   n  |  j sU |  j d  n  |  j d d d } |  j	 | _
 |  j | _ d | _ |  j | _ |  j d  } d | _ d | _ |  j j   rE|  j } | s|  j s t d	   t  j d d
  } n  d |  j | f } |  j d  } t j j | j d |  | _ n  xG d D]? } | j   } | d k rw| d } n  t | d | |  qL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   rYt%   } n d } |  j j& j' d | |  j( |
  f  t j) d |  t j* |  |  j+ st, |  j	 d |  j- n  d  S)Nwin32z^distribution contains extensions and/or C libraries; must be compiled on a Windows 32 platformbuildinstallZreinit_subcommands   r   install_libz Should have already checked this   z.%s-%sZlibpurelibplatlibheadersrB   dataz/Include/$dist_nameZinstall_zinstalling to %sZPURELIB)mktempzipZroot_diranyr	   zremoving temporary file '%s'dry_run)rL   rM   rN   zscriptszdata).sysplatformr;   rA   Zhas_c_librariesZDistutilsPlatformErrorr.   Zrun_commandZreinitialize_commandr%   rootZwarn_dirr&   compileoptimizer*   AssertionErrorversionr<   r>   r?   r@   Z
build_baseZ	build_libuppersetattrr   infoZensure_finalizedinsertrunZtempfilerP   get_fullnameZmake_archive
create_exer,   r   Z
dist_filesappendget_installer_filenamedebugremover'   r   rS   )r2   rH   rJ   r*   Zplat_specifierrG   keyvaluerP   Zarchive_basenamefullnamearcnameZ	pyversionr3   r3   r4   r_   p   sd    					
%

		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] q] W| j d  |  j r | j d |  j  n  | j d | |   | j d |  j  | j d |  j  |  j	 rM| j d |  j	  n  |  j
 rm| j d |  j
  n  |  j p|  j  j   } | j d | |   d d  l } d d  l }	 d | j | j    |	 j f }
 | j d |
  d j |  S)Nz
[metadata]r7   
c             S   s   |  j  d d  S)Nrj   z\n)replace)sr3   r3   r4   escape   s    z)bdist_wininst.get_inidata.<locals>.escapeZauthorZauthor_emaildescriptionZ
maintainerZmaintainer_emailnameZurlrZ   z
    %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)r;   metadatarb   Zlong_descriptiongetattr
capitalizer/   r(   r)   r*   r1   r-   r`   time	distutilsZctime__version__r@   )r2   linesrp   r]   rm   ro   rO   r-   rs   rt   Z
build_infor3   r3   r4   get_inidata   s<    $			zbdist_wininst.get_inidatac             C   s  d d  l  } |  j |  j  |  j   } |  j |  } |  j d |  | rr t | d  j   } t |  } n d } t | d  }	 |	 j	 |  j
    | r |	 j	 |  n  t | t  r | j d  } n  | d } |  j r+t |  j d d d	  }
 |
 j   j d	  } Wd  QX| | d
 } n
 | d } |	 j	 |  | j d d t |  |  } |	 j	 |  |	 j	 t | d  j    d  S)Nr   zcreating %srbwbmbcss    rencodingzlatin-1s   
 z<iiii{V4)structZmkpathr+   rw   rc   Zannounceopenreadlenwriteget_exe_bytes
isinstancestrencoder0   Zpack)r2   ri   rh   r,   r}   Zcfgdatainstaller_nameZ
bitmapdataZ	bitmaplenfilerD   Zscript_dataheaderr3   r3   r4   ra      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)r*   r>   r?   r@   r+   r&   )r2   rh   r   r3   r3   r4   rc   $  s    	z$bdist_wininst.get_installer_filenamec       	      C   s`  d d l  m } t   } |  j rm |  j | k rm |  j | k rL |   } qv |  j d k  rd d } qv d } n	 |   } 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  } Wn? t k
 r?} z t t |  d |   WYd  d  } ~ Xn Xz | j   SWd  | j   Xd  S)Nr   )get_build_versionz2.4g      @gffffff@rF   rK   winr7   zwininst-%.1f%s.exerx   z), %s not included in the Debian packages.)Zdistutils.msvccompilerr   r   r*   r>   r?   dirname__file__r&   r@   r~   IOErrorZDistutilsFileErrorr   r   close)	r2   r   Zcur_versionZbvZ	directoryZsfixfilenamefer3   r3   r4   r   1  s*    					(-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__rn   r   Zuser_optionsZboolean_optionsr5   rE   r_   rw   ra   rc   r   r3   r3   r3   r4   r	      sN    
         			&Q.5r	   )__doc__rT   r>   Zdistutils.corer   Zdistutils.utilr   Zdistutils.dir_utilr   r   Zdistutils.errorsZdistutils.sysconfigr   rt   r   r	   r3   r3   r3   r4   <module>   s   
