o
    c>                     @   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g d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 UAC)r
   r   r   r   win32c                    s$   t  j|i | 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__ X/opt/certbot/lib/python3.10/site-packages/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 u r)| jr| jr| jd}| j|_| dj}tj	
|d| _| js/d| _| jsL| j rLt }| jrI| j|krItd|f || _|  ddd | jrp| jjD ]}| jtj	|krh d S qZtd| j d S )	Nbdist)r+   r+   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   r7   short_versionscriptr    r    r!   finalize_optionsU   sB   
zbdist_wininst.finalize_optionsc                 C   s  t jdkr| j s| j rtd| js| d | jddd}| j	|_
| j|_d|_| j|_| d}d|_d|_| j rm| j}|sV| jsMJ d	d
t jd d  }d| j|f }| d}tj|jd| |_dD ]}| }|dkr}|d }t|d| | qot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 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=   datarJ   z/Include/$dist_nameinstall_zinstalling to %sPURELIB)mktempzip)root_diranyr   zremoving temporary file '%s')dry_run)-sysplatformr4   r;   has_c_librariesDistutilsPlatformErrorr+   run_commandreinitialize_commandr"   rootwarn_dirr#   compileoptimizer'   version_infor6   r8   r9   r:   
build_base	build_libuppersetattrr   infoensure_finalizedinsertruntempfilerN   get_fullnamemake_archive
create_exer)   r   
dist_filesappendget_installer_filenamedebugremover$   r   rR   )r   rC   rF   r'   plat_specifierrB   keyvaluerN   archive_basenamefullnamearcname	pyversionr    r    r!   re   {   sv   








zbdist_wininst.runc                 C   sX  g }| j j}|d |jpdd }dd }dD ]!}t||d}|r9|d| ||f  }|d|||f  q|d	 | jrJ|d
| j  |d||  |d| j   |d| j   | j	rp|d| j	  | j
r{|d| j
  | jp| j  }|d||  dd l}dd l}	d|| |	jf }
|d|
  d|S )Nz
[metadata]r2   
c                 S   s   |  ddS )Nrv   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)r4   metadatark   long_descriptiongetattr
capitalizer,   r%   r&   r'   r.   r*   rg   time	distutilsctime__version__r:   )r   linesr   rb   ry   r   rK   r*   r   r   
build_infor    r    r!   get_inidata   s@   


zbdist_wininst.get_inidataNc              	   C   s  dd l }| | j |  }| |}| d|  |r:t|d}| }W d    n1 s0w   Y  t|}	nd}	t|d}
|
	| 
  |rP|
	| t|trZ|d}|d }| jrt| jddd	}| d}W d    n1 s{w   Y  || d
 }n|d }|
	| |ddt||	}|
	| t|d}|
	|  W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )Nr   zcreating %srbwbmbcs    rzlatin-1)encodings   
 z<iiii{V4)structmkpathr(   r   rl   announceopenreadlenwriteget_exe_bytes
isinstancestrencoder-   pack)r   rt   rs   r)   r   cfgdatainstaller_namef
bitmapdata	bitmaplenfiler@   script_dataheaderr    r    r!   ri      sP   







#"zbdist_wininst.create_exec                 C   sF   | j rtj| jd|| j| j f }|S tj| jd|| jf }|S )Nz%s.%s-py%s.exez	%s.%s.exe)r'   r8   r9   r:   r(   r#   )r   rs   r   r    r    r!   rl   1  s   

z$bdist_wininst.get_installer_filenamec           	      C   s$  t  }| jr6| j|k r6| jdk rd}nB| jdkrd}n:| jdkr#d}n2| jdkr+d}n*| jdkr3d	}n"d
}nzddlm} W n tyI   d
}Y nw |dd }|d }tjt	}| j
dkrq| j
d d dkrq| j
dd  }nd}tj|d||f }t|d}z	| W |  S |  w )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      winr2   zwininst-%s%s.exer   )r   r'   msvcrtr   ImportError	partitionr8   r9   dirname__file__r#   r:   r   r   close)	r   cur_versionbvr   major	directorysfixfilenamer   r    r    r!   r   >  s:   	





zbdist_wininst.get_exe_bytes)N)__name__
__module____qualname__r|   r   user_optionsboolean_optionsrS   rT   _unsupportedr   r/   rA   re   r   ri   rl   r   __classcell__r    r    r   r!   r      s<    %
&Q
.7r   )__doc__r8   rS   r   distutils.corer   distutils.utilr   distutils.dir_utilr   distutils.errorsdistutils.sysconfigr   r   r   r   r    r    r    r!   <module>   s    