o
    5‘ðiá  ã                   @   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
mZ ddlmZ dd	lmZ e d
¡Z	 eZG dd„ deƒZdS )zRdistutils.command.build_scripts

Implements the Distutils 'build_scripts' command.é    N)Úlog)ÚST_MODE)ÚClassVaré   )Únewer)ÚCommand)Úconvert_pathz^#!.*python[0-9.]*([ 	].*)?$c                   @   s–   e Zd ZU dZg d¢Zeeeeeef   e	d< dgZ
eee  e	d< dd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zedd„ ƒZdS )Úbuild_scriptsz("build" scripts (copy and fixup #! line)))z
build-dir=Údzdirectory to "build" (copy) to)ÚforceÚfz1forcibly build everything (ignore file timestamps)zexecutable=Úez*specify final destination interpreter pathÚuser_optionsr   Úboolean_optionsc                 C   s   d | _ d | _d | _d | _d S ©N)Ú	build_dirÚscriptsr   Ú
executable©Úself© r   új/root/parts/websockify/install/lib/python3.10/site-packages/setuptools/_distutils/command/build_scripts.pyÚinitialize_options$   s   
z build_scripts.initialize_optionsc                 C   s   |   dddd¡ | jj| _d S )NÚbuild)r	   r   )r   r   )r   r   )Úset_undefined_optionsÚdistributionr   r   r   r   r   Úfinalize_options*   s   üzbuild_scripts.finalize_optionsc                 C   s   | j S r   )r   r   r   r   r   Úget_source_files3   s   zbuild_scripts.get_source_filesc                 C   s   | j sd S |  ¡  d S r   )r   Úcopy_scriptsr   r   r   r   Úrun6   s   zbuild_scripts.runc                 C   s@   |   | j¡ g }g }| jD ]	}|  |||¡ q|  |¡ ||fS )a2  
        Copy each script listed in ``self.scripts``.

        If a script is marked as a Python script (first line matches
        'shebang_pattern', i.e. starts with ``#!`` and contains
        "python"), then adjust in the copy the first line to refer to
        the current Python interpreter.
        )Úmkpathr   r   Ú_copy_scriptÚ_change_modes)r   ÚoutfilesÚupdated_filesÚscriptr   r   r   r   ;   s   	

zbuild_scripts.copy_scriptsc                 C   sF  d }t |ƒ}tj | jtj |¡¡}| |¡ | js't||ƒs't	 
d|¡ d S t |¡}| ¡ }|s<|  |› d�¡ d S t |¡}| |¡ |r•t	 d|| j¡ | d¡pVd}d| j | d }	|  |	|j¡ t|d|jd	��}
|
 |	¡ |
 | ¡ ¡ W d   ƒ n1 s†w   Y  |r“| ¡  d S d S |r›| ¡  |  ||¡ d S )
Nznot copying %s (up-to-date)z is an empty file (skipping)zcopying and adjusting %s -> %sé   Ú z#!Ú
Úw)Úencoding)r   ÚosÚpathÚjoinr   ÚbasenameÚappendr   r   r   ÚdebugÚtokenizeÚopenÚreadlineÚwarnÚshebang_patternÚmatchÚinfoÚgroupr   Ú_validate_shebangr*   ÚwriteÚ
writelinesÚ	readlinesÚcloseÚ	copy_file)r   r%   r#   r$   Úshebang_matchÚoutfiler   Ú
first_lineÚpost_interpÚshebangÚoutfr   r   r   r!   N   s:   




þÿzbuild_scripts._copy_scriptc                 C   s&   t jdkrd S |D ]}|  |¡ q	d S )NÚposix)r+   ÚnameÚ_change_mode)r   r#   Úfiler   r   r   r"   s   s
   
ÿzbuild_scripts._change_modesc                 C   sJ   t  |¡t d@ }|dB d@ }||kr#t d|||¡ t  ||¡ d S d S )Niÿ  im  z!changing mode of %s from %o to %o)r+   Ústatr   r   r7   Úchmod)r   rH   ÚoldmodeÚnewmoder   r   r   rG   z   s   þzbuild_scripts._change_modec              	   C   sd   z|   d¡ W n ty   td| ›d�ƒ‚w z|   |¡ W d S  ty1   td| ›d|› d�ƒ‚w )Nzutf-8zThe shebang (z) is not encodable to utf-8z+) is not encodable to the script encoding (ú))ÚencodeÚUnicodeEncodeErrorÚ
ValueError)rC   r*   r   r   r   r9   �   s   ÿÿÿÿzbuild_scripts._validate_shebangN)Ú__name__Ú
__module__Ú__qualname__Údescriptionr   r   ÚlistÚtupleÚstrÚ__annotations__r   r   r   r   r   r   r!   r"   rG   Ústaticmethodr9   r   r   r   r   r	      s   
 "	%r	   )Ú__doc__r+   Úrer1   Údistutils._logr   rI   r   Útypingr   Ú	_modifiedr   Úcorer   Úutilr   Úcompiler5   Úfirst_line_rer	   r   r   r   r   Ú<module>   s    
