HEX
Server: Apache/2.4.65 (Debian)
System: Linux kubikelcreative 5.10.0-35-amd64 #1 SMP Debian 5.10.237-1 (2025-05-19) x86_64
User: www-data (33)
PHP: 8.4.13
Disabled: NONE
Upload Files
File: //usr/share/dh-python/dhpython/__pycache__/tools.cpython-39.pyc
a

��:`�/�@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�PIPEZdhpythonz/(.*?)(-py\d\.\d(?:-[^.]*)?)?(\.egg-info|\.pth)$zNEEDED.*libpython(\d\.\d)cCsR|�d�}|�d�}|r6|d|dkr6|d=|d=qd�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|�r:t|�d}t�|�D]}tt||�t||��qt|�rpt|t|�d�}tt�|�|�t�	|�nt�
||�dS)zCMove file to dstdir. Works with symlinks (including relative ones).���N)rrr�listdir�	move_filer
r	r�readlink�remove�rename)�fpath�dstdirZdname�fnZdstpathrrrr8sr�cCs�t�|�j}|r$t�|�j}|p"d}t�|�D]T\}}}|D]D}	t||	�}
||
�r<|durd|||
�}
t|t|
|��}t�|
|�q<q.dS)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)�srcZdst�patternr(�repl�match�root�dirs�	filenamesr#Zspath�dpathrrr�move_matching_filesGs	

r3c
CsBzt�|�}Wn4tyB}zt�d||�WYd}~dSd}~00|sf|jdkrfd}|jr�|d7}n|s�|jdkr�d|_t|�}|�r>t�d|�z6t	|d	��}|�
�}Wd�n1s�0YWn ty�t�d
|�YdS0t	|d��6}|�
d
|�d��|�|dd��Wd�n1�s40YdS)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)�InterpreterZ	from_file�	Exception�log�debug�version�path�repr�info�open�	readlines�IOError�error�write�encode�
writelines)r!Zreplacement�interpreter�err�fpZfcontentrrr�fix_shebang^s0
*2rJcCsVd|}t|tdd�}t��dp$d}t�t|j��|d��}|rRt	|�
�d�SdS)	zhReturn libpython version file is linked to or None.

    :rtype: tuple
    :returns: Python version
    zreadelf -Wd '%s'T)�stdout�shellrr7��encodingrN)rr
�localeZgetdefaultlocale�SHAREDLIB_REr'�strrK�read�Version�groups)r!�cmd�processrNr.rrr�so2pyver�srWcCs2t�|�}|r.|�d�dur.d�|�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_REr.�groupr
)�namer.rrr�clean_egg_name�s
r]c	Csdt|pg�}|D]N}t|ddd��,}|D]}|r(|�|���q(Wd�q1sT0Yq|S)z#Parse namespace_packages.txt files.�rr7rMN)�setr@�add�strip)Zfpaths�other�resultr!rI�linerrr�parse_ns�s0rec
Cs<t|t�st|�}t�}|D]f}|D]\}t|�||�g|�d��R�}t|d�}t|�sZq$t|�dkr$t�d|�|�	|�qq$q||}|D]�}|D]R}t|�||�g|�d��R�}	t|	d�}t|�r�t
�|�t
�|	�s�t
�
|	�q�td|dg|�d��R�}	t|	d�}t|�r�t
�|�t
�|	�s�t
�
|	�q�|S)z8Remove empty __init__.py files for requested namespaces.�.z__init__.pyrz)file not empty, cannot share %s namespaceZdebianzusr/share/pyshared)�
isinstancer_r
�sitedirrrrr:Zwarningr`rrr�rmdir)
rG�packageZ
namespaces�versionsZkeep�nsr<r!rcr2rrr�	remove_ns�s:








rmTc
Cs|||d�}d}|durnv|dur2|jttd�n^|r�t|t�rRd}t|ddd�}|�d	�t���	���|�d
�|��|�
�|j||d�t�d|�t
|fi|���L}|��\}}	|o�|��t|j|o�t|d�|	o�t|	d�d�Wd�S1�s0YdS)
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
    )rL�cwd�envFN)rK�stderrT�ar7rMz
# command executed on {}z
$ {}
zinvoking: %s)�
returncoderKrp)�updater
rgrQr@rD�formatrZnowZ	isoformat�flushr:r;rZcommunicate�close�dictrr)
ZcommandrnroZ
log_outputrL�argsrvrVrKrprrr�execute�s,

�ryc@seZdZdd�Zdd�ZdS)�memoizecCs||_i|_dS�N)�func�cache)�selfr|rrr�__init__�szmemoize.__init__cOs6t||f�}||jvr,|j|i|��|j|<|j|Sr{)rr}r|)r~rx�kwargs�keyrrr�__call__�s
zmemoize.__call__N)�__name__�
__module__�__qualname__rr�rrrrrz�srzcCs�d|}t|�sdS|j}t||�}t|dd�D�]H}|r0|�d�rFq0t�|�}|s`td|��|��}|dr�|d�	dd	�|d<|t||d
�@}|s�t
�d||�q0t|d�}	|	s�td
|d��|	D]�}
|
�
d�}
|dr�t|dt|
�d�}n|
�d��r|
dd�}n|
}|D]X}t|�||�|�}
t|
�d}t|��sTt�|�t|
��rht�|
�t�|
|
��qq�q0dS)zDInstall local files listed in pkg.pyinstall files as public modules.z./debian/%s.pyinstallNr7rM�#zunrecognized line: %s�modulerfr�vrangez.%s.pyinstall: no matching versions for line %sr,zmissing file(s): %sz/.rzdebian/�r)r�impl�get_requested_versionsr@�
startswith�
INSTALL_REr.�
ValueError�	groupdict�replacer:r;r�lstripr
rrhr�makedirsrr)rGrjr��srcfpathr�rkrd�details�myvers�filesr!Zdstnamer<Zdstfpathr"rrr�	pyinstall�sL

�




r�cCsd|}t|�sdS|j}t||�}t|dd�D]�}|r0|�d�rDq0t�|�}|sbtd||f��|��}|t||d�@}|s�t	�
d||�|D]f}	|�||	�}
|
�|�
||	��|
D]>}t|d	|d
�}|D] }
t|
�r�t|
�q�t�|
�q�q�q�q0dS)z2Remove public modules listed in pkg.pyremove file.z./debian/%s.pyremoveNr7rMr�zunrecognized line: %s: %sr�z-%s.pyremove: no matching versions for line %srr,)rr�r�r@r��	REMOVE_REr.r�r�r:r;Zold_sitedirs�appendrhrrrrr)rGrjr�r�r�rkrdr�r�r<Z	site_dirsZsdirr�r!rrr�pyremove(s4

�
r�)r8)rSr��
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$)N)N)NNNT)/Zloggingrr%rOrr�picklerZshutilr�os.pathrrrr	r
r�
subprocessrr
Z	getLoggerr:r&rZrPrrrr3rJrWr]rermryrzr�r�Zdhpython.interpreterr8Zdhpython.versionrSr�r��VERBOSEr�r�rrrr�<module>sJ 





#
&
"+����