HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/apport/__pycache__/packaging_impl.cpython-38.pyc
U

��h��@s*dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
Z
e
�dde�ddlZz4ddlZddlmZmZmZeeeefeZeZWnHek
r�ddlmZmZddlmZdd	lmZmZddlZYnXddlZdd
lm Z Gdd�de �Z!e!�Z"dS)
zyapport.PackageInfo class implementation for python-apt and dpkg.

This is used on Debian and derivatives such as Ubuntu.
�N)�closing�ignorezapt API not stable yet)�urlopen�quote�unquote)�URLError�	HTTPError)r)rr)�PackageInfoc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd_d%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd`d4d5�Zed6d7��Zd8d9�Zd:d;�Z dad<d=�Z!d>d?�Z"d@dA�Z#dbdCdD�Z$dEdF�Z%edGdH��Z&dIdJ�Z'edKdL��Z(dMdN�Z)dOdP�Z*dQdR�Z+edSdT��Z,edUdV��Z-edWdX��Z.dYdZ�Z/d3Z0d[d\�Z1d3Z2d]d^�Z3d3S)c�__AptDpkgPackageInfoz�Concrete apport.PackageInfo class implementation for python-apt and
    dpkg, as found on Debian and derivatives such as Ubuntu.cCsFd|_d|_d|_d|_d|_d|_d|_d|_|jd|_d|_	dS)Nzhttps://api.launchpad.net/develz*/~%(user)s/+archive/%(distro)s/%(ppaname)sF)
�
_apt_cache�_sandbox_apt_cache�_sandbox_apt_cache_arch�
_contents_dir�_mirror�_virtual_mapping_obj�_contents_mapping_objZ_launchpad_base�_ppa_archive_url�_contents_update��self�r�7/usr/lib/python3/dist-packages/apport/packaging_impl.py�__init__-sz__AptDpkgPackageInfo.__init__cCs0z|jrt�|j�Wntk
r*YnXdS)N)r�shutil�rmtree�AttributeErrorrrrr�__del__9s
z__AptDpkgPackageInfo.__del__c	CsZ|jdk	r|jStj�|d�}tj�|�rNt|d��}t�|�|_W5QRXni|_|jS)N�virtual_mapping.pickle�rb)r�os�path�join�exists�open�pickle�load�r�	configdir�mapping_file�fprrr�_virtual_mapping@s
z%__AptDpkgPackageInfo._virtual_mappingc	Cs@tj�|d�}|jdk	r<t|d��}t�|j|�W5QRXdS)Nr�wb)rr r!rr#r$�dumpr&rrr�_save_virtual_mappingMs
z*__AptDpkgPackageInfo._save_virtual_mappingc	Cs�|jr(|jd|kr(|jd|kr(|jStj�|d||f�}tj�|�rdt�|�jdkrdt�|�tj�|�r�t|d��}t	�
|�|_W5QRXn||d�|_|jS)N�release�arch�contents_mapping-%s-%s.picklerr)r.r/)rrr r!r"�stat�st_size�remover#r$r%�rr'r.r/r(r)rrr�_contents_mappingSs ��
�
z&__AptDpkgPackageInfo._contents_mappingc	Csbtj�|d||f�}|jdk	r^z(t|d��}t�|j|�W5QRXWntk
r\YnXdS)Nr0r+)rr r!rr#r$r,�MemoryErrorr4rrr�_save_contents_mappinges
�
z+__AptDpkgPackageInfo._save_contents_mappingcCsVd|_|jsPz tjj��}tj|dd�|_Wn"tk
rNtjdd�|_YnX|jS)z(Return apt.Cache() (initialized lazily).N�/��rootdir)rr�apt�progress�baseZ
OpProgress�Cacher)rr<rrr�_cacheqsz__AptDpkgPackageInfo._cachec

Cs�d|_|jr||jkr�|�|||||�tj�|�}tj|d�|_||_z|j�	|�Wn2tj
jk
r�}	ztt
|	���W5d}	~	XYnX|j��n
|j��|jS)z�Build apt sandbox and return apt.Cache(rootdir=) (initialized lazily).

        Clear the package selection on subsequent calls.
        Nr9)rrr
�_build_apt_sandboxrr �abspathr;r>�update�cache�FetchFailedException�SystemError�strr#�clear)
r�aptroot�apt_sources�
fetchProgress�distro_name�release_codename�originsr/r:�errr�_sandbox_caches 
�
z#__AptDpkgPackageInfo._sandbox_cachecCs4z|��|WStk
r.td|��YnXdS)zuReturn apt.Cache()[package] (initialized lazily).

        Throw a ValueError if the package does not exist.
        �package %s does not existN)r?�KeyError�
ValueError�r�packagerrr�_apt_pkg�sz__AptDpkgPackageInfo._apt_pkgcCs&|�|�}|j}|s td|��|jS)z*Return the installed version of a package.rP)rU�	installedrR�version)rrT�pkg�instrrr�get_version�s

z __AptDpkgPackageInfo.get_versioncCs|�|�jjS)z1Return the latest available version of a package.)rU�	candidaterWrSrrr�get_available_version�sz*__AptDpkgPackageInfo.get_available_versioncCsJ|�|�jj}|sgSdd�|j�dg�|j�dg�|j�dg�D�S)z/Return a list of packages a package depends on.cSsg|]}|djj�qS�r)Z
target_pkg�name)�.0�drrr�
<listcomp>�sz9__AptDpkgPackageInfo.get_dependencies.<locals>.<listcomp>ZDependsZ
PreDependsZ
Recommends)rUZ_pkgZcurrent_verZdepends_list�get)rrTZcur_verrrr�get_dependencies�s���z%__AptDpkgPackageInfo.get_dependenciescCsD|�|�jr|�|�jjS|�|�jr4|�|�jjStd|��dS)z-Return the source package name for a package.rPN)rUrV�source_namer[rRrSrrr�
get_source�s
z__AptDpkgPackageInfo.get_sourcecCs8|�|�j}|std��|jD]}|jr|jSqdS)z�Return package origin.

        Return the repository name from which a package was installed, or None
        if it cannot be determined.

        Throw ValueError if package is not installed.
        zpackage is not installedN)rUrVrRrM�origin)rrTrXrfrrr�get_package_origin�s
z'__AptDpkgPackageInfo.get_package_origincCs�|�|�}|jr |jjdkr dS|��d}|jrX|jjrX|jjD]}|j|krBdSqBtdd�|jjD��tdg�kr�tj	�
d�r�dSdS)	z�Check if a package is a genuine distro package.

        Return True for a native distro package, False if it comes from a
        third-party source.
        NFrTcSsg|]
}|j�qSr)rf)r_�orrrra�sz:__AptDpkgPackageInfo.is_distro_package.<locals>.<listcomp>�z/etc/system-image/channel.ini)rUrVrW�get_os_versionr[rMrf�setrr r")rrTrXrKrhrrr�is_distro_package�s

 
�z&__AptDpkgPackageInfo.is_distro_packagec
Cs�|�|�}|jr |jjdkr dSg}t�d�D]R}z8t|��&}|D]}|��}|rB|�|�qBW5QRXWq.tk
r~Yq.Xq.|jr�|jj	r�|jj	D]}|j
|kr�dSq�dS)z�Check if a package originated from a native location

        Return True for a package which came from an origin which is listed in
        native-origins.d, False if it comes from a third-party source.
        NFz/etc/apport/native-origins.d/*T)rUrVrW�globr#�strip�append�IOErrorr[rMrf)rrTrXZnative_origins�f�fd�linerhrrr�is_native_origin_package�s$


z-__AptDpkgPackageInfo.is_native_origin_packagecCs�tjj�dd�ddlm}|jdddd�}|jd	}|j|�	�d
d�}	|	j
|d�}
|jd
d�}|j|||
ddd�}|s~dSd}
|D]D}|j
dkr�q�|js�|jdd�}
q�q�|j�|�r�|jdd�}
q�q�|
s�dS|
D]}|d|dfSdS)NzAPT::Get::AllowUnauthenticated�Truer��	Launchpad�apport-retrace�
production�devel�rW�ubuntu���)Zname_or_version)Zarchtag�primary�r^FT)Zbinary_namerWZdistro_arch_seriesZordered�exact_match)NNri�Deleted)Zinclude_meta�urlZsha1)r;�apt_pkg�configrk�launchpadlib.launchpadrw�login_anonymously�
distributionsZ	getSeries�splitZgetDistroArchSeries�
getArchiveZgetPublishedBinaries�statusZarchitecture_specificZbinaryFileUrlsZdistro_arch_series_link�endswith)r�	distro_idr.rTrWr/rw�	launchpadr|ZseriesZdasr~ZbpphZbf_urlsZbpZbfrrr�get_lp_binary_package	s<�
�
z*__AptDpkgPackageInfo.get_lp_binary_packageFc	Cs�z(t|�}|��dkr&td|����Wn,ttfk
rTt�dt|��YdSXz|��}Wn(tk
r�t�dt|��YdSXt	|t
�r�|�d�}|r�t�
|�dSt�
|�SdS)z�Open, read and parse the json of a url

        Set entries to True when the json data returned by Launchpad
        has a dictionary with an entries key which contains the data
        desired.
        ��%uzcannot connect to: %sNzfailure reading data at: %szutf-8�entries)r�getcoderr�apport�warningr�readrp�
isinstance�bytes�decode�json�loads)rr�r��responseZcontentrrr�json_request+s"

z!__AptDpkgPackageInfo.json_requestc
Cs�ddlm}|jdddd�}|jd}|jdd	�}|j||d
d�}|sJdSd}	|D]}
|
jd
krbqR|
��}	qpqR|	sxdSg}|	D]}|�|�q�|S)Nrrvrxryrzr{r|r~rT)rdrWr�rir�)	r�rwr�r�r�ZgetPublishedSourcesr�ZsourceFileUrlsro)
rr�rTrWrwr�r|r~ZpssZsfusZpsZsource_filesZsfurrr�get_lp_source_packageEs.�
�
z*__AptDpkgPackageInfo.get_lp_source_packagecCsL|�|�jr|�|�jjpdS|�|�jr<|�|�jjp:dStd|��dS)z�Return the architecture of a package.

        This might differ on multiarch architectures (e. g. an i386 Firefox
        package on a x86_64 system)�unknownrPN)rUrV�architecturer[rRrSrrr�get_architecture]s
z%__AptDpkgPackageInfo.get_architecturecCs,|�d|g�}|dkrdSdd�|��D�S)z*Return list of files shipped by a package.z-LNcSsg|]}|�d�s|�qS)Zdiverted)�
startswith)r_rqrrrraps
z2__AptDpkgPackageInfo.get_files.<locals>.<listcomp>)�
_call_dpkg�
splitlines)rrT�listrrr�	get_filesjsz__AptDpkgPackageInfo.get_filesc

Cshd||��f}tj�|�s$d|}z,t�|�}t�|j�s@t�t|j	|j
�}Wntk
rhgYSXd}d||��f}tj�|�s�d|}tj�|�s�gSt|d���}|D]�}znd|kr�t�
d|�Wq�|��}	|	s�t�
d	|�Wq�t�d
|	d�d��d��}t|j	|j
�|k�r"Wq�Wntk
�r:YnX||7}q�W5QRX|�r`|�|�SgSd
S)z/Return list of all modified files of a package.z/var/lib/dpkg/info/%s:%s.listz/var/lib/dpkg/info/%s.list�z /var/lib/dpkg/info/%s:%s.md5sumsz/var/lib/dpkg/info/%s.md5sumsr�z(%s contains NUL character, ignoring linez%%s contains empty line, ignoring liner8r}�UTF-8N)�get_system_architecturerr r"r1�S_ISREG�st_mode�OSError�max�st_mtime�st_ctimer#r�r�r�r��encode�_check_files_md5)
rrTZlistfile�sZmax_timeZsums�sumfilerrrsZwordsrrr�get_modified_filesrsF


z'__AptDpkgPackageInfo.get_modified_filesc
Cstjdddd|gtjd�}|��d��}|jdkr8iSi}|��D]�}|sNqD|����dd�\}}t	j
�|�r�zLt|d	��}|�
�}	W5QRXt��}
|
�|	�|
��}||kr�|	||<Wq�tk
r�}zd
t|�||<W5d}~XYq�XqDd||<qD|S)a?Return modified configuration files of a package.

        Return a file name -> file contents map of all configuration files of
        package. Please note that apport.hookutils.attach_conffiles() is the
        official user-facing API for this, which will ask for confirmation and
        allows filtering.
        z
dpkg-queryz-Wz--showformat=${Conffiles}�--��stdoutrN�rz[inaccessible: %s]z	[deleted])�
subprocess�Popen�PIPE�communicater��
returncoder�rnr�rr r"r#r��hashlibZmd5rBZ	hexdigestrprF)
rrT�dpkg�out�modifiedrsr Zdefault_md5sumrr�contents�mZcalculated_md5sumrNrrr�get_modified_conffiles�s6
��

$
z+__AptDpkgPackageInfo.get_modified_conffilescCs|d}d}d}|sx|t|�krxtjdddd|g||||�tjtjtjd�}|��d�d	�}|jdkrn|}||7}q|S)
zsCall fgrep for a pattern on given file list and return the first
        matching file, or None if no file matches.N�drZfgrepz-lxm�1r�)�stdinr��stderrr�)�lenr�r�r�r�r�r�)r�patternZ	file_list�matchZ
slice_size�i�pr�rrrZ
__fgrep_files�s ��

z"__AptDpkgPackageInfo.__fgrep_filesNcCst|r|�||||�Stjdd|gtjtjd�}|��d�d�}|jdkrf|rf|��d}|dkrf|Stj	�
tj	�|��d��}	g}
g}t
�
d�D]P}tj	�
tj	�|��d���d	�d}
|
|	ks�|	|
kr�|�|�q�|
�|�q�|�||�}|�s|�||
�}|�sH|�d
��rH|dd�}|�d
||�}|�sH|�d
||
�}|�rptj	�
tj	�|��d�d	�dSdS)apReturn the package a file belongs to.

        Return None if the file is not shipped by any package.

        If uninstalled is True, this will also find files of uninstalled
        packages; this is very expensive, though, and needs network access and
        lots of CPU and I/O resources. In this case, map_cachedir can be set to
        an existing directory which will be used to permanently store the
        downloaded maps. If it is not set, a temporary directory will be used.
        Also, release and arch can be set to a foreign release/architecture
        instead of the one from the current system.
        zdpkg-divertz--list�r�r�rr�r}zhardening-wrapperz/var/lib/dpkg/info/*.list�:z/usr�N�%s)�_search_contentsr�r�r�r�r�r�r�rr �splitext�basename�lowerrmro� _AptDpkgPackageInfo__fgrep_filesr�)r�fileZuninstalled�map_cachedirr.r/r�r�rX�fnameZ	all_listsZlikely_listsrqr�r�rrr�get_file_package�s<�&"z%__AptDpkgPackageInfo.get_file_packagecCsBtjddgtjd�}|��d����}|jdks6t�|s>t�|S)zcReturn the architecture of the system, in the notation used by the
        particular distribution.r�z--print-architecturer�r�r�r�r�r�r�rnr��AssertionError)�klassr�r/rrrr�s
�z,__AptDpkgPackageInfo.get_system_architecturecCs>tjddgtjd�}|��d����}|jdks6t�d|S)z�Return a list of default library search paths.

        The entries should be separated with a colon ':', like for
        $LD_LIBRARY_PATH. This needs to take any multiarch directories into
        account.
        zdpkg-architecturez-qDEB_HOST_MULTIARCHr�rz/lib/%s:/libr�)rr�Zmultiarch_triplerrr�get_library_pathss
�z&__AptDpkgPackageInfo.get_library_pathscCs<||_z|jr t�|j�d|_Wntk
r6YnXdS)z�Explicitly set a distribution mirror URL for operations that need to
        fetch distribution files/packages from the network.

        By default, the mirror will be read from the system configuration
        files.
        N)rrrrr)rr�rrr�
set_mirror-s
z__AptDpkgPackageInfo.set_mirrorcCs&tj��}|r:t��}|�d|���|��|j|d<|rRt	j
dddg|d�dddd|g}|rx|d	d
|7<�zt	j
|||d�dk�r�|s�Wd
S|�|��||�}	|	�r�d}
t
jj�d�dkr�t
jj�d�}
t
jj�dd�t
jj��}t
j�|�}g}
|	D]}|
�t
jj|||d���q|��}||jk�rBWd
S|
�rXt
jj�d|
�t�tj�|d��D] }t	j
ddd|gt	j|d��qlnWd
SWntk
�r�Yd
SXd
}t�tj�||d��D]}tj�|��r�|}�q�|�s�t d��zt	j
dd|d�Wntk
�r YnX|S)a:Download source package and unpack it into dir.

        This also has to care about applying patches etc., so that dir will
        eventually contain the actually compiled source. dir needs to exist and
        should be empty.

        If version is given, this particular version will be retrieved.
        Otherwise this will fetch the latest available version.

        If sandbox is given, it calls apt-get source in that sandbox, otherwise
        it uses the system apt configuration.

        If apt_update is True, it will call apt-get update before apt-get
        source. This is mostly necessary for freshly created sandboxes.

        Return the directory that contains the actual source root directory
        (which might be a subdirectory of dir). Return None if the source is
        not available.
        zODir "%s";
Dir::State::Status "/var/lib/dpkg/status";
Debug::NoLocking "true";
 Z
APT_CONFIGzapt-getz-qqrB)�envz--assume-yes�sourcer}�=)�cwdr�rNrizAcquire::http::Proxy)�destdirz*.dsczdpkg-sourcez-sn�-x)r�r�z-*z.could not determine source tree root directoryz�(debian/rules patch || debian/rules apply-patches || debian/rules apply-dpatches || debian/rules unpack || debian/rules patch-stamp || debian/rules setup) >/dev/null 2>&1T)�shellr�)!r�environ�copy�tempfileZNamedTemporaryFile�writer��flushr^r��callr��get_distro_namer;r�r��findrkr<r=�AcquireProgress�Acquirero�AcquireFile�runZRESULT_CONTINUErmr r!r�r��isdirr�)rZ
srcpackage�dirrWZsandboxZ
apt_updater�rq�argvZsf_urls�proxyrJ�fetcherZaf_queueZsf�resultZdsc�rootr`rrr�get_source_tree>s~
�


����
�
z$__AptDpkgPackageInfo.get_source_treecCsdt��dS)z�Return the actual Linux kernel package name.

        This is used when the user reports a bug against the "linux" package.
        zlinux-image-r�)r�unamerrrr�get_kernel_package�sz'__AptDpkgPackageInfo.get_kernel_packagecCsg}g}|d��d}|d}|d��d}d|}|��}||krZ||jrZ||fStjj�d�d}	d|||f}
d	|
}ttj	�
|	|
�d
�}t|�}
|
��dkr�dS|
�
d
�}|s�q�|�|�q�|��|��t�ddtj	�
|	|
�g�}|dk�r|�|
�d�d�||fS)z�Install kernel debug package

        Ideally this would be just another package but the kernel is
        special in various ways currently so we can not use the apt
        method.
        ZUname�ZArchitectureZPackagezlinux-image-debug-%s�Dir::Cache::archivesz/partialz
%s_%s_%s.ddebz,http://ddebs.ubuntu.com/pool/main/l/linux/%s�wr�)riZlinuxi r�z-ir�_)r�r?ZisInstalledr;r�r��find_dirr#rr r!rr�r�r�r��closer�r�ro)r�reportrVZoutdatedZkverr/�verZ
debug_pkgname�cZ
target_dir�debr�r��u�blockZretrrr�_install_debug_kernel�s4

z*__AptDpkgPackageInfo._install_debug_kernelTc=s�
|s|��}|s d}|��|_n�tj�||d�}||��kr^tj�|||d�}
tj�|
�r^|
}z|�|�|��Wn4t	k
r�}zt
�dt|��W5d}~XYnXt
tj�||d���}|����|_W5QRXtj�|�s�t	d|��|�rVd}||��k�r|}nd}|�r*tj�|||d	�}ntj�|d
|d	�}tj�|��sbt�|�nd}t��}tjj�d|�tjj�d
d�tjj�dd�tjj�dd�|�r�tjj��}ntjj��}|�s�|�||||��|j|	|��nx|�|||��|j|	�tjtj� |�d��z��!|�Wn4tj"j#k
�rT}zt	t|���W5d}~XYnX��
�tjj�$d�}d}tj�%�}tj�|d�}i}tj�|��r�t
|��8}|D],}|��}|�s��q�|�&�\}}|||<�q�W5QRXt�}i}tj�'|�}g}|�rNg} |D�]8\}!}"z�|!}#WnBt(k
�r`d|!�)dd�}$||$d7}t
�|$�Y�qYnX|#j*j+D]�}%�|%dj,j*j-}&|%dj,dd�|D�k�r��qj|%dj,|k�r�||%dj,}'|�.|'|&�dk�r�| �/|%dj,|'f�n| �/|%dj,|&f�n| �/|%dj,|&f�|%dj,dd�|D�k�rj|�/|%dj,df��qj�q|�0| �|D�]�\}!}"z�|!}#WnBt(k
�r�d|!�)dd�}$||$d7}t
�|$�Y�qRYnXz|"�r�|#j1|"|#_*Wntt(k
�r6|�2|��||!|"|�\}(})|(�r|�/tjj3||(d|)|d��|"||!<n|d |!|"|#j*j-f7}YnX|#j*}*|�4|!�|�rB|�5|�}+|*j6D]}|+�7|t���4|!��q^g},d!|*j8k�r�|,tj�9|*j8d!�7},d"|*j8k�r�|,tj�9|*j8d"�7},|,D�]x}-|-dd|*j:j,k�r�q�|-d}-��;|-d��r�z|+|-d}.Wnt(k
�r*Y�q�YnX|.D]�}||*j:j,k�rF�q0tj�|d#|�}/t<�<|/�D]4}0|�=|0�}"tj�>|"|-d$|-d%��rbt�?|0��qbz
||=Wnt(k
�r�YnX�q0~.n|tj�|d#|-d�}/t<�<|/�D]Z}0|�=|0�}"tj�>|"|-d$|-d%��r�t�?|0�z||-d=Wnt(k
�r8YnX�q�q�|*j@d&k�rR|
�rRz�|!d'}1�|1}2d}3|"�r�z|2j1|"|2_*d}3Wnft(k
�r�|�2|��||1|"|�\}(})|(�r�|�/tjj3||(d|)|d��|"||1<d}3nt(�YnX|3�s2z|2j1|*j-|2_*Wn,t(k
�r0|d(|!|"|2j*j-f7}YnX|�4|1�W�qRt(k
�r|�A�|�B|*jC��r��fd)d�|jDD�}4|"�r�|4D]"}2�|2j*j-|"k�r�|4�E|2��q�ng}4|4�	r�|4D]�}||k�r̐q�d}3|"�	rTz�|j1|"�|_*d}3Wn`t(k
�	rR|�2|��|||"|�\}(})|(�	rN|�/tjj3||(d|)|d��|"||<d}3YnX|3�	s�z�|j1|*j-�|_*Wnt(k
�	r�YnX|�4|��q��n`d}3|!d*}5zڈ|5}6|�4|5�|"�
r:z|6j1|"|6_*d}3Wn`t(k
�
r8|�2|��||5|"|�\}(})|(�
r4|�/tjj3||(d|)|d��|"||5<d}3YnX|3�
s�z|6j1|*j-|6_*Wn.t(k
�
r�|d+|!|*j-|6j*j-f7}YnXWnxt(k
�
r�|"�
r�|�2|��||5|"|�\}(})|(�
r�|�/tjj3||(d|)|d��|"||5<d}3|3�
s�|d,|!7}YnXYnX�qRtF|�}7|�G�D]�}||7k�r�|7|dk�rj|�H|��|j*j-k�rX|�E|�n�|�Idd�nZ|�H|�|7|k�r��|�Idd�n4|�H|��|j*j-k�r��|�Idd�n
|�E|�n4|�H|��|j*j-k�r�|�Idd�n
|�E|��qtJ�J�}8z�jK|d-�WnBtj"j#k
�rX}zt
�Ld.t|��tM�Nd%�W5d}~XYnX|�rhtOd/�|jPD]�}9tQ�Rd0d1|9jSg��T�}:|:���&�\}}|�r�||k�s�tj�U|9jS�|8k�
r|�H|�|k�r�n6||k�r�|||k�r�ntQ�Vd2d3|9jS|g�|||<tj�W|9jS��&d4d%�d};|;|k�rn|�E|;��qntX|�Y��}<|<�Z�t
|d5��>}|<D]2}|�[|�|�[d6�|�[||�|�[d��
qZW5QRX|�
r�t\�]|�|�
r�t^d7d6�|���|�
r�|�_|�|S)8a�Install packages into a sandbox (for apport-retrace).

        In order to work without any special permissions and without touching
        the running system, this should only download and unpack packages into
        the given root directory, not install them into the system.

        configdir points to a directory with by-release configuration files for
        the packaging system; this is completely dependent on the backend
        implementation, the only assumption is that this looks into
        configdir/release/, so that you can use retracing for multiple
        DistroReleases. As a special case, if configdir is None, it uses the
        current system configuration, and "release" is ignored.

        release is the value of the report's 'DistroRelease' field.

        packages is a list of ('packagename', 'version') tuples. If the version
        is None, it should install the most current available version.

        If cache_dir is given, then the downloaded packages will be stored
        there, to speed up subsequent retraces.

        If permanent_rootdir is True, then the sandbox created from the
        downloaded packages will be reused, to speed up subsequent retraces.

        If architecture is given, the sandbox will be created with packages of
        the given architecture (as specified in a report's "Architecture"
        field). If not given it defaults to the host system's architecture.

        If origins is given, the sandbox will be created with apt data sources
        for foreign origins.

        If install_deps is True, then the dependencies of packages will also
        be installed.

        Return a string with outdated packages, or an empty string if all
        packages were installed.

        If something is wrong with the environment (invalid configuration,
        package servers down, etc.), this should raise a SystemError with a
        meaningful error message.
        �/etc/apt/sources.list�sources.listzcannot determine mirror: %sNZcodenamez%s does not existFrir;�systemTzAPT::ArchitecturezAcquire::LanguagesZnonez'Acquire::http::Proxy::api.launchpad.netZDIRECTz#Acquire::http::Proxy::launchpad.netr9r�zpackages.txtz#package %s does not exist, ignoring�%z%%�
rcSsg|]}|d�qSr]r�r_rXrrrra`sz9__AptDpkgPackageInfo.install_packages.<locals>.<listcomp>r}cSsg|]}|d�qSr]rrrrrranszsha1:%s)�hashr�z,%s version %s required, but %s is available
Z	ConflictsZReplacesz%s_*.debr�r��all�-dbgzAoutdated -dbg package for %s: package version %s -dbg version %s
cs2g|]*}|�d�r|�krd�|jjkr|�qS)rZtransitional)r�r[Zdescription)r_r��rCrrra�s

�z-dbgsymzKoutdated debug symbol package for %s: package version %s dbgsym version %s
z%no debug symbol package found for %s
)r�z+Package download error, try again later: %szExtracting downloaded debs...�dpkg-debz--showr�r�rr�� z*apt fetcher did not fetch these packages: )`r��get_distro_codename�current_release_codenamerr r!r"r��$_get_primary_mirror_from_apt_sourcesrEr�r�rFr#r�rnr��makedirsr��mkdtempr;r�r�rkr<�textr�r=rOr�r@r>rArBrCrDrZ
SourceRecordsr�r�rQ�replacer[Zdependenciesr^rW�compare_versionsro�extendZversionsr�r��addr*Zprovides�
setdefault�recordZ
parse_dependsrTZis_virtual_packagerm�_deb_versionZ	check_dep�unlinkr�Zrestart�lookuprdZbinariesr3�dictr�rbZmark_install�timeZfetch_archives�error�sys�exit�print�itemsr�Zcheck_outputZdestfiler��getctimeZ
check_callr�r��keys�sortr�rrr�r-)=rr:r'r.Zpackages�verboseZ	cache_dirZpermanent_rootdirr�rMZinstall_dbgZinstall_depsrIZarch_apt_sourcesrNrqZtmp_aptrootZaptroot_archrHrJZ
archivedirZobsoleteZsrc_recordsZpkg_listZpkg_versionsrsr��vZ	real_pkgsZlp_cacher�Z
acquire_queueZdepsrXrZ	cache_pkgr�ZdepZdep_pkg_versZinst_versionZlp_urlZsha1sumr[Zvirtual_mappingZ	conflictsZconflictZ	providersZdebsr Zdbg_pkgZdbgZ	pkg_foundZdbgsZ
dbgsym_pkgZdbgsymZrequested_pkgsZlast_writtenr�r��pkg_nameZpkgsrrr�install_packages�s�-
�$
��





��










��
�

��


��
�
��

$




�
z%__AptDpkgPackageInfo.install_packagescCstj�|����|�S)z2Return known package names which match given glob.)rmZfnmatch�filterr?r-)rZnameglobrrr�package_name_glob�sz&__AptDpkgPackageInfo.package_name_globcCsHtjdg|tjtjd�}|�t�d�d�}|jdkr<|Std��dS)zRCall dpkg with given arguments and return output, or return None on
        error.r�r�rr�zpackage does not existN)r�r�r�r��inputr�r�rR)r��argsr�r�rrrr��s�
z__AptDpkgPackageInfo._call_dpkgcCs�tj�|�rBtjdd|gtjtjdid�}|��djddd�}nLt|�t	ksVt
d	��tjddgtjtjtjdid
�}|�|�djddd�}|jdkr�gSg}|��D]$}|�
d�r�|�|�dd
�d�q�|S)z�Internal function for calling md5sum.

        This is separate from get_modified_files so that it is automatically
        testable.
        z/usr/bin/md5sumz-cr8)r�r�r�r�rr�r)�errorsz&md5sum list value must be a byte array)r�r�r�r�r�ZFAILEDr�r�)rr r"r�r�r�r�r��typer�r�r�r�r�ro�rsplit)rr�r�r�Z
mismatchesrsrrrr��s0�
�

z%__AptDpkgPackageInfo._check_files_md5c
Cs�t|���}|D]p}|��}t|�dkr|ddkr|d�d�rFd}nd}||�d�sf||�d�r||W5QR�Sqtd	|��W5QRXd
S)z?Heuristically determine primary mirror from an apt sources.list�rrr��[r�zhttp://zhttps://zEcannot determine default mirror: %s does not contain a valid deb lineN)r#r�r�r�rE)r�rIrqrsZfieldsZ
mirror_idxrrrr�s
��z9__AptDpkgPackageInfo._get_primary_mirror_from_apt_sourcescCs|js|�d�|_|jS)zReturn the distribution mirror URL.

        If it has not been set yet, it will be read from the system
        configuration.r
)rrrrrr�_get_mirror�sz __AptDpkgPackageInfo._get_mirrorcCs&t|d�r|jdk	r|jStd��dS)z7Map a DistroRelease: field value to a release code namerNzBCannot map DistroRelease to a code name without install_packages())�hasattrr�NotImplementedError)rr.rrr�_distro_release_to_codename�sz0__AptDpkgPackageInfo._distro_release_to_codenamec 
Cs|r
|}n|jst��|_|j}|dkr0|��}|dkrB|��}n
|�|�}dD�]\}tj�|d|||f�}d}z t�	|�}	t
t��|	j�}
Wnt
k
r�d}
YnX|
dks�|
dk�r.d|��|||f}|
�r�zddlm}dd	lm}
Wn.tk
�r"ddlm}dd	lm}
YnXdd
lm}|
|�d}||�}|�d|
|�d
�|��}|�dd�}|�r�|�|d�}||�|	j�k}nd}nd}|�r.d|_zt|�}Wn(tk
�r�|dk�r҂nYqPYnXt|d��(}|�d�}|�s��q
|� |��q�W5QRX|�!�tj�"|��s.t#�|�$|||�}|�rPt%|�d
k�rVd|_|jrPddl&}|�d|d���2}d}|D�] }|d7}|dk�r�|dk�r�|dk�r��q�|�'�d}|�'d�ddk�r6|�'d�ddk�r�q�|�'d�ddk�r|�'d�d
dk�r�q�|�'�d�'d�d�'d�d}n:|�'d�ddk�r�|�'�d�'d�d�'d�d}n�q�||k�r�|||k�r��q�n|||<n|||<�q�W5QRXqP|j�r�|�(|||�d|_t)|t*��r�|�+�}|dd k�r�|dd�}|�,�g}|�-d!��r(|�.|d"d��,��n�|�-d#��rL|�.|d"d��,��n�|�-d$��rp|�.|d"d��,��nj|�-d%��r�|�.|d"d��,��nF|�-d&��r�|�.|d"d��,��n"|�-d'��r�|�.|d"d��,��|D]4}z||�+�}|WSt/k
�rYnX�q�dS)(z4Internal function for searching file in Contents.gz.N)z	-proposedriz	-securityz-updatesz%s%s-Contents-%s.gzFi�Qz%s/dists/%s%s/Contents-%s.gzr)�HTTPConnection)�urlparse)�datetimer�ZHEADr�z
last-modifiedz%a, %d %b %Y %H:%M:%S %ZTrir+i@Br�r)ZtrustyZxenial�!�/susr)�libslibexecslibx32�bin�sbin�sharesgamessBrotherrH)sdocsiconssmanstexlivesgocodeslocaleshelpr}�,)rErFrGr8zusr/lib/x86_64-linux-gnu/r�zusr/lib/i386-linux-gnu/zusr/lib/systemd/z
usr/lib/udev/zusr/bin/z	usr/sbin/)0rr�rr�rr?rr r!r1�intr&r�r�r<Zhttplibr@rA�ImportErrorZhttp.client�urllib.parserBZrequestZgetresponseZ	getheader�strptimeZ
fromtimestamprrrpr#r�r�rr"r�r5r��gzipr�r7r�r�r�r�r�rorQ) rr�r�r.r/r�Zpocket�maprB�stZager�r@rArBZserverZconn�resZmodified_strr��srcrq�dataZcontents_mappingrNr�Zline_numrsr rT�filesrXrrrr��s�




�

�



��""




z%__AptDpkgPackageInfo._search_contentsc
	Cs�|�d��r�|�d�dd�}d}t|�dkr<|�d�d}d}|t|�k�r t�d|d|��}t�d||d��}zPtttj	j
|||d	����*}	|	��|	��d
kr�t
d|	����W5QRXWnRtt
fk
�r|d7}|t|�k�r|�r|�d�d}d}nd}Yq@YnX�q q@|�r�|�r�d||||f}
d
||||f}zFtt|���,}	|	��|	��d
k�r�t
d|	����W5QRXd}Wntt
fk
�r�d}YnX|
|d|
dd�dSdS)a�For an origin from a Launchpad PPA create sources.list content.

        distro is the distribution for which content is being created e.g.
        ubuntu.

        release_codename is the codename of the release for which content is
        being created e.g. trusty.

        Return a string containing content suitable for writing to a sources.list
        file, or None if the origin is not a Launchpad PPA.
        �LP-PPA-�-r�NTr��ppaF��user�distroZppanamer�r�z-deb http://ppa.launchpad.net/%s/%s/%s %s mainz5http://ppa.launchpad.net/%s/%s/%s/dists/%s/main/debugz main/debugriz
deb-srcr:r)r�r�r�rorFr!rrr��	packagingrr�r�rr)
r�rfrZrLZ
componentsZtry_ppa�indexrY�ppa_namer�Zppa_lineZ	debug_urlZ	add_debugrrr�create_ppa_source_from_origin�s^

��


�
�
z2__AptDpkgPackageInfo.create_ppa_source_from_originc
Csrtj�tj�|ddd��s�t�tj�|ddddd��t�tj�|ddddd��t�tj�|ddd��t�tj�|d	dd
��t�tj�|d	dd��tj�|d	dd�}tj�|�r�t�|�tj�|d
�r�t�|d
|�n
t�|�t	|��8}t	tj�|d	dd�d��}|�
|���W5QRXW5QRX|�r�d}	i}
|D�]|}|dk�rZ�qFd}tj�|d
��r�tj�|d
|d�}tj�|��s�d|k�r�tj�|d
|�d�d�}tj�|��s�d}ntj�|��s�d}|�rt	|��}
|
��}	W5QRXn|�
|||�}	|	�r�t	tj�|d	dd|d�d��}|�
|	�W5QRX|	��D]\}|�d��rh�qTd|k�rv�qT|��d�d�d}|��d�d�d}||f|
|<�qTnt�d|��qFtj�tj�|�d�}tj�|��rt�|tj�|d	d��n&tj�d��r*t�dtj�|d	d��tj�|d	dd�}tj�|��rTt�|�tj�|d
��rxt�|d
|�n&tj�d ��r�t�d |�n
t�|�|�rn|	�rn|
��D]�\}\}}tjjt|�|t|�d!�}tj�|�}|�s�q�z|d"}Wn*tk
�r&t�d#|�Y�q�YnXd$d%tj�|d&|�d'd(d)d*d+|g	}t�|�d,k�r�t�d-|��q�dS).N�var�libr;Zlists�partialrCZarchivesr��etcz
apt.conf.dz
preferences.dzsources.list.dz.drr�rir�z.listzLP-PPArU�a�#zppa.launchpad.netr�r8r:r�z-Could not find or create source config for %sztrusted.gpgz/etc/apt/trusted.gpgz
trusted.gpg.dz/etc/apt/trusted.gpg.drX�signing_key_fingerprintz/Error: can't find signing_key_fingerprint at %szapt-keyz	--keyringz%s.gpgZadvz--quietz--keyserverzkeyserver.ubuntu.comz
--recv-keyrzUnable to import key for %s)rr r"r!rrrr�Zcopytreer#r�r�rnr^r�r�r�r�r��dirnamer�r+r[rrr��
IndexErrorr�r�)r�Zapt_rootrIrKrLrMZlist_drR�destZsource_list_contentZorigin_datarfZorigin_pathZsrc_extrsrYrWZtrusted_gpgZ	trusted_dZppa_userr]Zppa_archive_urlZppa_inforer�rrrr@�s�


"

�
��


�����z'__AptDpkgPackageInfo._build_apt_sandboxcCsJtjdd|dgtjd�}|�t�d�d���}|jdks>t�|sFt�|S)z!Return the version of a .deb filerz-fZVersionr�rr�)	r�r�r�r�r5r�rnr�r�)r�rXr�r�rrrr"4s
z!__AptDpkgPackageInfo._deb_versioncCstj�||�S)zkCompare two package versions.

        Return -1 for ver < ver2, 0 for ver1 == ver2, and 1 for ver1 > ver2.)r;r�Zversion_compare)rZver1Zver2rrrr>sz%__AptDpkgPackageInfo.compare_versionscCsJ|jdkrDtjddgtjd�}|��d�d���|_|jdksDt�|jS)z(Get "lsb_release -sc", cache the result.N�lsb_releasez-scr�rr�)	�_distro_codenamer�r�r�r�r�rnr�r�)rrirrrrGs

�z(__AptDpkgPackageInfo.get_distro_codenamecCs<|jdkr6|��d��|_d|jkr6|j�dd�|_|jS)zuGet osname from /etc/os-release, or if that doesn't exist,
           'lsb_release -sir' output and cache the result.NrrrV)�_distro_namerjr�rrrrrr�Ts


z$__AptDpkgPackageInfo.get_distro_name)F)FNNN)NNF)FNFNNTF)4�__name__�
__module__�__qualname__�__doc__rrr*r-r5r7r?rOrUrZr\rcrergrlrtr�r�r�r�r�r�r�r�r��classmethodr�r�r�r�r�r	r2r4r�r�rr<r?r�r^r@r"rrjrrkr�rrrrr
)s�

	
"

0(�
6
�
X'�
X	




A
k
	r
)#ror�rrmr1r(r�rr&r�r��
contextlibr�warnings�filterwarnings�
FutureWarningr;ZcPickler$ZurllibrrrrprrrKZurllib.errorZurllib.requestrLr�Zapport.packagingr	r
�implrrrr�<module>sD@D