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__/tools.cpython-310.pyc
o

O�Ib�/�@s\ddlZddlZddlZddlZddlmZddlmZddlmZddlm	Z	ddl
mZmZm
Z
mZmZmZddlmZmZe�d�Ze�d	�Ze�d
�Zdd�Zd
d�Zdd�Zd+dd�Zd,dd�Zdd�Zdd�Zd,dd�Z dd�Z!d-dd �Z"Gd!d"�d"�Z#d#d$�Z$d%d&�Z%dd'l&m'Z'dd(l(m)Z)m*Z*m+Z+e�d)e+ej,�Z-e�d*e+ej,�Z.dS).�N)�datetime)�glob)�dumps)�rmtree)�exists�getsize�isdir�islink�join�split)�Popen�PIPE�dhpythonz/(.*?)(-py\d\.\d(?:-[^.]*)?)?(\.egg-info|\.pth)$zNEEDED.*libpython(\d\.\d)cCsd|�d�}|�d�}|r$|d|dkr$|d=|d=|r$|d|dksd�dgt|�d|�S)z~Return relative path.

    >>> relpath('/usr/share/python-foo/foo.py', '/usr/bin/foo', )
    '../share/python-foo/foo.py'
    �/rz..�)rr
�len)�target�link�t�l�r�&/usr/share/dh-python/dhpython/tools.py�relpath&s

�rcCst�t||�|�S)zCreate relative symlink.)�os�symlinkr)rrrrr�relative_symlink3srcCs�t|�rt|�d}t�|�D]
}tt||�t||��qt|�r9t|t|�d�}tt�|�|�t�	|�dSt�
||�dS)zCMove file to dstdir. Works with symlinks (including relative ones).���N)rrr�listdir�	move_filer
r	r�readlink�remove�rename)�fpath�dstdir�dname�fn�dstpathrrrr8sr�cCs�t�|�j}|rt�|�j}|pd}t�|�D]*\}}}|D]"}	t||	�}
||
�r@|dur2|||
�}
t|t|
|��}t�|
|�qqdS)a>Move files (preserving path) that match given pattern.

    move_matching_files('foo/bar/', 'foo/baz/', 'spam/.*\.so$')
    will move foo/bar/a/b/c/spam/file.so to foo/baz/a/b/c/spam/file.so

    :param sub: regular expression for path part that will be replaced with `repl`
    :param repl: replacement for `sub`
    r'N)	�re�compile�search�subr�walkr
r�renames)�src�dst�patternr+�repl�match�root�dirs�	filenamesr%�spath�dpathrrr�move_matching_filesGs	

���r8c
Cs@zt�|�}Wnty!}zt�d||�WYd}~dSd}~ww|s3|jdkr3d}|jr2|d7}n|sA|jdkrAd|_t|�}|r�t�d|�zt	|d	��}|�
�}Wd�n1s^wYWntytt�d
|�YdSwt	|d��}|�
d
|�d��|�|dd��Wd�dS1s�wYdS)zmNormalize file's shebang.

    :param replacement: new shebang command (path to interpreter and options)
    zfix_shebang (%s): %sN�2z/usr/bin/python2z-dbgz	/usr/bin/z/usr/binzreplacing shebang in %s�rbzcannot open %sF�wbz#! %s
�utf-8rT)�Interpreter�	from_file�	Exception�log�debug�version�path�repr�info�open�	readlines�IOError�error�write�encode�
writelines)r"�replacement�interpreter�err�fp�fcontentrrr�fix_shebang^sB���
���
��rRcCsVd|}t|tdd�}t��dpd}t�t|j��|d��}|r)t	|�
�d�SdS)	zhReturn libpython version file is linked to or None.

    :rtype: tuple
    :returns: Python version
    zreadelf -Wd '%s'T)�stdout�shellrr<��encodingrN)rr
�locale�getdefaultlocale�SHAREDLIB_REr*�strrS�read�Version�groups)r"�cmd�processrVr2rrr�so2pyver�s�r`cCs2t�|�}|r|�d�durd�|�dd��S|S)aRemove Python version and platform name from Egg files/dirs.

    >>> clean_egg_name('python_pipeline-0.1.3_py3k-py3.1.egg-info')
    'python_pipeline-0.1.3_py3k.egg-info'
    >>> clean_egg_name('Foo-1.2-py2.7-linux-x86_64.egg-info')
    'Foo-1.2.egg-info'
    �Nr'r�)�
EGGnPTH_REr2�groupr
)�namer2rrr�clean_egg_name�s
rfc	Csdt|pg�}|D]'}t|ddd��}|D]}|r|�|���qWd�n1s*wYq|S)z#Parse namespace_packages.txt files.�rr<rUN)�setrF�add�strip)�fpaths�other�resultr"rP�linerrr�parse_ns�s����roc
Cs<t|t�s	t|�}t�}|D]3}|D].}t|�||�g|�d��R�}t|d�}t|�s-qt|�dkr@t�d|�|�	|�nqq||}|D]S}|D])}t|�||�g|�d��R�}	t|	d�}t|�rut
�|�t
�|	�sut
�
|	�qLtd|dg|�d��R�}	t|	d�}t|�r�t
�|�t
�|	�s�t
�
|	�qH|S)z8Remove empty __init__.py files for requested namespaces.�.z__init__.pyrz)file not empty, cannot share %s namespace�debianzusr/share/pyshared)�
isinstancerhr
�sitedirrrrr@�warningrirr r�rmdir)
rN�package�
namespaces�versions�keep�nsrBr"rmr7rrr�	remove_ns�sB


��



�



�r{Tc
Cs|||d�}d}|dur
n;|dur|jttd�n/|rHt|t�r)d}t|ddd�}|�d	�t���	���|�d
�|��|�
�|j||d�t�d|�t
|fi|���&}|��\}}	|ob|��t|j|olt|d�|	ort|	d�d�Wd�S1swYdS)
a<Execute external shell commad.

    :param cdw: currennt working directory
    :param env: environment
    :param log_output:
        * opened log file or path to this file, or
        * None if output should be included in the returned dict, or
        * False if output should be redirectored to stdout/stderr
    )rT�cwd�envFN)rS�stderrT�ar<rUz
# command executed on {}z
$ {}
zinvoking: %s)�
returncoderSr~)�updater
rrrZrFrJ�formatr�now�	isoformat�flushr@rAr�communicate�close�dictr�)
�commandr|r}�
log_outputrT�argsr�r_rSr~rrr�execute�s0


��$�r�c@seZdZdd�Zdd�ZdS)�memoizecCs||_i|_dS�N)�func�cache)�selfr�rrr�__init__�s
zmemoize.__init__cOs6t||f�}||jvr|j|i|��|j|<|j|Sr�)rr�r�)r�r��kwargs�keyrrr�__call__�s

zmemoize.__call__N)�__name__�
__module__�__qualname__r�r�rrrrr��sr�cCsvd|}t|�s
dS|j}t||�}t|dd�D]�}|r!|�d�r"qt�|�}|s/td|��|��}|drA|d�	dd	�|d<|t||d
�@}|sTt
�d||�qt|d�}	|	sdtd
|d��|	D]Q}
|
�
d�}
|dr}t|dt|
�d�}n|
�d�r�|
dd�}n|
}|D])}t|�||�|�}
t|
�d}t|�s�t�|�t|
�r�t�|
�t�|
|
�q�qfqdS)zDInstall local files listed in pkg.pyinstall files as public modules.z./debian/%s.pyinstallNr<rU�#zunrecognized line: %s�modulerpr�vrangez.%s.pyinstall: no matching versions for line %sr0zmissing file(s): %sz/.rzdebian/�r)r�impl�get_requested_versionsrF�
startswith�
INSTALL_REr2�
ValueError�	groupdict�replacer@rAr�lstripr
rrsr�makedirsr r)rNrvr��srcfpathr�rxrn�details�myvers�filesr"�dstnamerB�dstfpathr#rrr�	pyinstall�sR

�



���r�cCsd|}t|�s
dS|j}t||�}t|dd�D]e}|r!|�d�r"qt�|�}|s1td||f��|��}|t||d�@}|sGt	�
d||�|D]3}	|�||	�}
|
�|�
||	��|
D]}t|d	|d
�}|D]}
t|
�rut|
�qjt�|
�qjq\qIqdS)z2Remove public modules listed in pkg.pyremove file.z./debian/%s.pyremoveNr<rUr�zunrecognized line: %s: %sr�z-%s.pyremove: no matching versions for line %srr0)rr�r�rFr��	REMOVE_REr2r�r�r@rA�old_sitedirs�appendrsrrrrr )rNrvr�r�r�rxrnr�r�rB�	site_dirs�sdirr�r"rrr�pyremove(s<

�
����r�)r=)r\r��
RANGE_PATTERNz�
    (?P<pattern>.+?)  # file pattern
    (?:\s+  # optional Python module name:
    (?P<module>[A-Za-z][A-Za-z0-9_.]*)?
    )?
    \s*  # optional version range:
    (?P<vrange>%s)?$
z^
    (?P<pattern>.+?)  # file pattern
    \s*  # optional version range:
    (?P<vrange>%s)?$
)Nr'r�)NNNT)/�loggingrr(rWrr�pickler�shutilr�os.pathrrrr	r
r�
subprocessrr
�	getLoggerr@r)rcrYrrrr8rRr`rfror{r�r�r�r��dhpython.interpreterr=�dhpython.versionr\r�r��VERBOSEr�r�rrrr�<module>sL 





#

&"+����