HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/share/dh-python/dhpython/__pycache__/fs.cpython-310.pyc
o

O�IbBY�@sddlZddlZddlZddlZddlZddlZddlmZddl	m	Z	ddl
mZmZm
Z
mZmZmZmZmZmZmZddlmZddlmZmZmZmZddlmZddlmZm Z dd	l!m"Z"e�#d
�Z$dd�Z%d
d�Z&dd�Z'dd�Z(dd�Z)dd�Z*dd�Z+Gdd�d�Z,dS)�N)�cmp)�glob)
�lexists�exists�getsize�isdir�islink�join�realpath�relpath�split�splitext)�rmtree)�ST_MODE�S_IXUSR�S_IXGRP�S_IXOTH)�MULTIARCH_DIR_TPL)�fix_shebang�clean_egg_name)�Interpreter�dhpythonc
CsPt|�}|D]�}||_|�|�}|�|�D]%}t|�r:t�d||�t||||�zt�	|�Wqt
y9Yqwq|j|dd�}|j|dd�D]%}t|�rnt�d||�t||||�zt�	|�WqIt
ymYqIwqI|jr�d||jf}|r�t|�r�d||jf}t�d||�t||||�zt�	|�Wqt
y�YqwqdS)z!Move files to the right location.zmoving files from %s to %sT)�gdbzdebian/%s%sN)
r�version�sitedir�old_sitedirsr�log�debug�share_files�os�
removedirs�OSError�symlinked_include_dir�include_dir)�package�interpreter�versions�optionsr�dstdir�srcdir�r*�#/usr/share/dh-python/dhpython/fs.py�
fix_locations(sL
��
��	���r,c
sg}t���D�]^}t�|�}t|�sq|�d�rt�|�q|jsBt|�ddkrB|���}|rB|durBt	�
|||�}t|�d}��d�r�|dksP|�d�r_t�|�|�
t|gff�qt|�r�|dkr�|�
t�fd	d
�tt�|d��D�ff�t|�qt||�}t|�s�t|�s�t�||�qt|�r�t|�s�t�||�qt|�t|�kr�t�|�qt|�r�t||||�qt||dd
�r�t�|�q|�d�r�|���r�t�d|��t�|�q��d��r|dkr�t||�r�|�
tdf�t�|�q|dk�rt||�t�|�qt�d|�qt�d||�|j�rf|�d��sft|��}	|	� �}
Wd�n	1�s:wYt|��}|� �}Wd�n	1�sSwYt!�"|
|||�}
t#j$�%|
�q|D]
\}}||g|�R��qizt�&��WdSt'�y�YdSw)z<Try to move as many files from srcdir to dstdir as possible.z.pyc���z.soT�
.dist-info�LICENSEzLICENSE.�
license_filescsg|]}t|���qSr*)r)�.0�license�r)r*r+�
<listcomp>ls��zshare_files.<locals>.<listcomp>z**F)�shallow)z.abi3.soz.abi4.soz2%s differs from previous one, removing anyway (%s)�WHEELr*�RECORDz%No merge driver for dist-info file %szPaths differ: %s and %sN)(r�listdirr	r�endswith�remove�
no_ext_renamer
�parse_public_dir�Scan�
rename_extr�
startswith�append�remove_from_RECORDrrrr�renamesrr
r�cmpfiler�warning�merge_WHEEL�fix_merged_RECORD�merge_RECORD�warn�verbose�open�	readlines�difflib�unified_diff�sys�stderr�
writelinesr r!)r)r(r%r'�cleanup_actions�i�fpath1r�fpath2�fp1�	fromlines�fp2�tolines�diff�action�argsr*r3r+rSs�






��

�




�

���rcCs�t|��}dd�|��D�}Wd�n1swYg}t|��}|��D]}||vr3|�|�q(Wd�|S1s?wY|S)z;Find all the lines in the text file src that are not in dstcSsi|]}|d�qS�Nr*)r1�kr*r*r+�
<dictcomp>�sz!missing_lines.<locals>.<dictcomp>N)rJrKr@)�src�dst�fh�current�missing�liner*r*r+�
missing_lines�s
�

��
��recCs|t�d||�t||�}t|d��!}|D]}|�d�r!|�|�qt�d|�qWd�t|�S1s5wYt|�S)z�Merge the source .dist-info/WHEEL file into the destination

    Note that after editing the WHEEL file, the sha256 included in
    the .dist-info/RECORD file will be incorrect and will need fixing
    using the fix_merged_RECORD() function.
    zMerging WHEEL file %s into %s�atzTag: zWHEEL merge discarded line %sN)rrrerJr?�writerH�len�r_r`rcrardr*r*r+rE�s

�
��rEcCsdt�d||�t||�}t|d��}|D]}|�|�qWd�t|�S1s)wYt|�S)z<Merge the source .dist-info/RECORD file into the destinationzMerging RECORD file %s into %srfN)rrrerJrgrhrir*r*r+rG�s
�
��rGc
Cst�d|�t|d�}t|d�}tt|�d�d}t|d�}t|d��}t�|�����}Wd�n1s8wYt	|�}dj
|||d	�g}t|��}|��D]}	|	�|�s_|�
|	�qSWd�n1sjwYt|d
��}|�t|��Wd�dS1s�wYdS)aUpdate the checksum for .dist-info/WHEEL in .dist-info/RECORD

    After merging the .dist-info/WHEEL file, the sha256 recorded for it will be
    wrong in .dist-info/RECORD, so edit that file to ensure that it is fixed.
    The output is sorted for reproducibility.
    zFixing RECORD file in %sr7r6r��rbNz!{name},sha256={sha256sum},{size}
)�name�	sha256sum�size�wt)rrr	rrJ�hashlib�sha256�read�	hexdigestr�formatrKr?r@rP�sorted)
�distdir�record_path�
wheel_path�	wheel_dir�
wheel_relpathra�wheel_sha256�
wheel_size�contentsrdr*r*r+rF�s2


���


���"�rFcs�t�d||�t|d�}t|�d��fdd�|D��g}t|��}|��}Wd�n1s0wY�fdd�|D�}||krIt�d||�t|d	��}|�t|��Wd�dS1sawYdS)
z0Remove all specified dist-info files from RECORDzRemoving %r from RECORD in %sr7rjcsg|]}t�|��qSr*)r	)r1rl)�
parent_dirr*r+r4��z&remove_from_RECORD.<locals>.<listcomp>Ncs$g|]}|�dd�d�vr|�qS)�,rjr)r)r1rd)�namesr*r+r4�s$z0Unable to remove %r from RECORD in %s, not foundro)	rrr	rrJrKrHrPru)rv�files�record�linesra�filteredr*)r�r~r+rA�s 


��"�rAc@s�eZdZe�d�Ze�d�Zd*dd�Zedd��Z	dd	�Z
d
d�Zedd
��Zedd��Z
dd�Zed+dd��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�ZdS),r=z.*/__pycache__(/.*)?$z.*\.py[co]$NcCs||_|j|_||_|sd|j|_n
|�d�}td|j|�|_||_~||_t�t�t�t�t�t�idt�t�d�
|_	t
�|j�D�]�\}}}|�|�rT|dd�=qCd|_
|_|�|�}|rod|_|durkd}n||_nd|_|jr�|�d�r�|dur�|j	d�|�|D]}	|	d	vs�|	�d
�r�t�d|	�tt||	��|�|	�q�n|�|�|_
|j
s�|�|�r�|�||�nqC|D]}	t||	�}|�|�r�t|�|�|	�q�q�|�|�r�|�||�qC|�|�r�|�||�qCt |�D]�}
t||
�}|�!|��rt�d|�t
�|�q�|�"|��r|�#|�q�t$|��s6t%|��r5d
t&|�dv�r5t�'d|�t
�|�q�t(|
�ddd�}|dk�ru|jj)�sQ|�*|||�}|�+|�}
|
�pZ|}
|
�rj|j,�-dt���|
�n|j,�-dt���|�|j
�r�t$|��r�|dk�r�t
�.|�t/}|t0@�s�|t1@�s�|t2@�r�|j3�s�t4||jj5��r�|jj6�s�zt7�8|�}Wnt9�y�}z
t�d||�WYd}~nd}~ww|j,�-dt���|�|dk�r�|�:|�du�r�d|j,d<q�|�s|j
�szt
�;|�WqCt<�yYqCwqCt�d||j	�dS)Nz	debian/%s�/�debianF)
�requires.txt�egg-info�	dist-info�nsp.txt�shebangs�public_vers�private_dirs�compile�ext_vers�ext_no_versionTz	-packagesr�)�test�tests�.zremoving dist-packages/%szremoving unwanted: %s�.so.r-zremoving dangling symlink: %srj�sor�r��cannot parse shebang %s: %sr��pyr�zpackage %s details = %s)=r%�implr$�proot�stripr	�dpathr'�set�resultr�walk�
should_ignore�current_private_dir�current_pub_versionr<�current_dir_is_publicr9�addr?rrrr:�check_private_dir�
is_bin_dir�handle_bin_dir�is_unwanted_dir�is_dist_dir�handle_dist_dir�
is_egg_dir�handle_egg_dirru�is_unwanted_file�is_egg_file�handle_egg_filerrr�infor
r;r>�
handle_ext�current_result�
setdefault�statrrrr�no_shebang_rewriter�shebang�ignore_shebangsr�	from_file�	Exception�handle_public_moduler r!)�selfr%r$r�r'�root�dirs�
file_namesrrl�fn�fpath�fext�ver�mode�res�er*r*r+�__init__
s�
�




�



�










����
���z
Scan.__init__cCs |jr
|jd�|ji�S|jS)Nr�)r�r�r��r�r*r*r+r��szScan.current_resultcCs|jj�|�Sr\)�	__class__�
UNWANTED_DIRS�match)r�r�r*r*r+r��szScan.is_unwanted_dircCsR|jj�|�r	dS|jr!|jr#|jjr%t|�ddd�dvr'dSdSdSdSdS)NTr-rj)r��h)r��UNWANTED_FILESr�r��is_dbg_packager'�
clean_dbg_pkgr
�r�r�r*r*r+r��s��zScan.is_unwanted_filecs6�jr�jgS�jdurg}|S�fdd�dD�}|S)NFcsg|]}|�j�qSr*)r$)r1rRr�r*r+r4�rz.Scan.private_dirs_to_check.<locals>.<listcomp>)z
usr/lib/%szusr/lib/games/%szusr/share/%szusr/share/games/%s)r�)r�r�r*r�r+�private_dirs_to_check�s
�zScan.private_dirs_to_checkcCs|j�d�S)Nz-dbg)r$r9r�r*r*r+r��szScan.is_dbg_packagecCs0|jD]}|�td|j|��rd|SqdS)z0Return private dir's root if it's a private dir.r�r�N)r�r?r	r$)r�r�rRr*r*r+r��s

��zScan.check_private_dirc
Cs
|�dd�\}}|durSt|�rS|}t�}t|�r*|�|�t|t�|��}t|�st|�rSdt|�dvrS|D]
}t	�
d|�t�|�q8t	�
d||�t�||�t
�|�rZ|S|�||�}|r�t||�}	t|	�rtt	�d||�|	St	�
d||�t�||	�|	S|S)	z�Add multiarch triplet, etc. Return new name.

        This method is invoked for all .so files in public or private directories.
        r�rjNr�r-zremoving symlink: %s�renaming %s to %sz.destination file exist, cannot rename %s to %s)�rsplitrr�r�r	r�readlinkrrrr�r:�renamerr��
check_extnamerH)
r�r%r��path�fname�dstfpath�links�lpath�new_fn�	new_fpathr*r*r+r>�s8	
�

��zScan.rename_extcCsdS)z0Handle .so file, return its version if detected.Nr*r�r*r*r+r��szScan.handle_extcCsdSr\r*r�r*r*r+r��szScan.handle_public_modulecCs4|�d��dd�}t|�dkrdS|�d�rdSdS)z#Check if dir is one from PATH ones.r��F)z/sbinz/binz
/usr/gamesTN)r�rrhr9)r�r��spathr*r*r+r��s
�zScan.is_bin_dircCs�|jjs|jjr
dS|D]7}t||�}t||jj�rCzt�|�}Wnty:}z
t	�
d||�WYd}~qd}~ww|jd�|�qdS)Nr�r�)
r'r�r�r	rr�rr�r�rrr�r�)r�r�r�r�r�r�r�r*r*r+r��s
����zScan.handle_bin_dircC�
|�d�S)z+Check if given directory contains egg-info.�	.egg-info�r9�r��dnamer*r*r+r��
zScan.is_egg_dircCs�|�dd�\}}|jr|jjrt|�dSt|�}||krHtt||��r1t�	d||�t|�dSt�	d||�t
�|t||��|}t||�}|r{d|vrY|jd�
t|d��d|vrh|jd�
t|d��d|vr}t
�t|d��|�d�dSdSdS)	Nr�rj�%removing %s (%s is already available)r�r�znamespace_packages.txtr�zSOURCES.txt)r�r�r'r�rrrr	rr�rr�r�r�r:)r�r�r�r�r��
clean_namer*r*r+r�s0
�zScan.handle_egg_dircCr�)z&Check if given file contains egg-info.r�r�r�r*r*r+r�"r�zScan.is_egg_filecCs�|�dd�\}}t|�}||kr4tt||��r$t�d||�t�|�nt�d||�t�|t||��|j	d�
t||��dS)Nr�rjr�r�r�)r�rrr	rr�rr:r�r�r�)r�r�r�rlr�r*r*r+r�&s�zScan.handle_egg_filecCr�)z,Check if given directory contains dist-info.r.r�r�r*r*r+r�3r�zScan.is_dist_dircCsX|�dd�\}}|jr|jjrt|�dS|r(d|vr*|jd�t|d��dSdSdS)Nr�rj�METADATAr�)r�r�r'r�rr�r�r	)r�r�r�r�r�r*r*r+r�7s�zScan.handle_dist_dirc	Csl|jr0|jjr2|jd}tj|dd�D] \}}}d|vr/|s/zt�|�Wqty.YqwqdSdSdS)Nz/usr/libF)�topdownz
-packages/)r�r'r�r�rr�r r�)r�r�r�r�r�r*r*r+�cleanupAs
���zScan.cleanup)NNr\)�__name__�
__module__�__qualname__�rer�r�r�r��propertyr�r�r�r�r�r��staticmethodr>r�r�r�r�r�r�r�r�r�r�r�r*r*r*r+r=s6





)



r=)-rLrp�loggingrr�rN�filecmprrCr�os.pathrrrrrr	r
rrr
�shutilrr�rrrrrr�dhpython.toolsrr�dhpython.interpreterr�	getLoggerrr,rrerErGrFrAr=r*r*r*r+�<module>s.0
+R