o UfT@s(dZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl Z e ddeddlZzddlZddlmZmZmZeeeefeZeZWn#ey|ddlmZmZddlmZdd lmZmZddlZYnwddlZdd lm Z Gd d 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)closingignorezapt API not stable yet)urlopenquoteunquote)URLError HTTPError)r)rr) PackageInfoc@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZddZddZd d!Zd"d#Zd_d%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Z 3 3d`d4d5Zed6d7Zd8d9Zd:d;Z 3 $dadd?Z"d@dAZ# 3 3 $dbdCdDZ$dEdFZ%edGdHZ&dIdJZ'edKdLZ(dMdNZ)dOdPZ*dQdRZ+edSdTZ,edUdVZ-edWdXZ.dYdZZ/d3Z0d[d\Z1d3Z2d]d^Z3d3S)c__AptDpkgPackageInfozConcrete 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_obj_launchpad_base_ppa_archive_url_contents_updateselfr7/usr/lib/python3/dist-packages/apport/packaging_impl.py__init__-s  z__AptDpkgPackageInfo.__init__cCs4z|jr t|jWdSWdStyYdSw)N)rshutilrmtreeAttributeErrorrrrr__del__9s z__AptDpkgPackageInfo.__del__cCsv|jdur|jStj|d}tj|r5t|d}t||_Wd|jS1s-wY|jSi|_|jS)Nvirtual_mapping.picklerb)rospathjoinexistsopenpickleloadr configdir mapping_filefprrr_virtual_mapping@s    z%__AptDpkgPackageInfo._virtual_mappingcCsZtj|d}|jdur+t|d}t|j|WddS1s$wYdSdS)Nrwb)r r!r"rr$r%dumpr'rrr_save_virtual_mappingMs   "z*__AptDpkgPackageInfo._save_virtual_mappingcCs|jr|jd|kr|jd|kr|jStj|d||f}tj|r2t|jdkr2t|tj|rXt|d}t ||_Wd|jS1sPwY|jS||d|_|jS)Nreleasearchcontents_mapping-%s-%s.picklerr)r/r0) rr r!r"r#statst_sizeremover$r%r&rr(r/r0r)r*rrr_contents_mappingSs$      z&__AptDpkgPackageInfo._contents_mappingcCs|tj|d||f}|jdursz9__AptDpkgPackageInfo.get_dependencies..Depends PreDepends Recommends)rW_pkg current_ver depends_listget)rrVcur_verrrrget_dependenciess   z%__AptDpkgPackageInfo.get_dependenciescCs@||jr ||jjS||jr||jjStd|)z-Return the source package name for a package.rR)rWrX source_namer]rTrUrrr get_sources   z__AptDpkgPackageInfo.get_sourcecCs8||j}|s td|jD] }|jr|jSqdS)zReturn 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)rWrXrTrOorigin)rrVrZrprrrget_package_origins   z'__AptDpkgPackageInfo.get_package_origincCs||}|jr|jjdurdS|d}|jr,|jjr,|jjD] }|j|kr+dSq!tdd|jjDtdgkrDtj drDdSdS) zCheck 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|]}|jqSr)rp)rborrrrdsz:__AptDpkgPackageInfo.is_distro_package..z/etc/system-image/channel.ini) rWrXrYget_os_versionr]rOrpsetr r!r#)rrVrZrMrrrrris_distro_packages      z&__AptDpkgPackageInfo.is_distro_packagec Cs||}|jr|jjdurdSg}tdD]1}z&t|}|D] }|}|r.||q!Wdn1s9wYWqtyHYqw|jr_|jj r_|jj D] }|j |vr^dSqTdS)zCheck 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) rWrXrYglobr$stripappendIOErrorr]rOrp)rrVrZnative_originsffdlinerrrrris_native_origin_packages0      z-__AptDpkgPackageInfo.is_native_origin_packagecCstjjddddlm}|jdddd}|jd }|j| d d } | j |d } |j d d} | j ||| ddd} | s?dSd} | D]!}|j dkrKqC|jsV|jdd} n|j|rd|jdd} nqC| sidS| D] }|d|dfSdS)NzAPT::Get::AllowUnauthenticatedTruer Launchpadapport-retrace productiondevelrYubuntu)name_or_version)archtagprimaryraFT) binary_namerYdistro_arch_seriesordered exact_match)NNrsDeleted) include_metaurlsha1)r<apt_pkgconfigrulaunchpadlib.launchpadrlogin_anonymously distributions getSeriessplitgetDistroArchSeries getArchivegetPublishedBinariesstatusarchitecture_specificbinaryFileUrlsdistro_arch_series_linkendswith)r distro_idr/rVrYr0r launchpadrseriesdasrbpphbf_urlsbpbfrrrget_lp_binary_package s@        z*__AptDpkgPackageInfo.get_lp_binary_packageFc Cszt|}|dkrtd|Wnttfy)tdt|YdSwz|}WntyCtdt|YdSwt |t rN| d}|rWt |dSt |S)zOpen, 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-8entries)rgetcoderrapportwarningrreadrz isinstancebytesdecodejsonloads)rrrresponsecontentrrr json_request+s(      z!__AptDpkgPackageInfo.json_requestc Csddlm}|jdddd}|jd}|jdd }|j||d d }|s%dSd } |D] } | jd kr1q)| } | s:dSg} | D]} | | q>| S)NrrrrrrrrrT)rnrYrrsr) rrrrrgetPublishedSourcesrsourceFileUrlsry) rrrVrYrrrrpsssfusps source_filessfurrrget_lp_source_packageEs.     z*__AptDpkgPackageInfo.get_lp_source_packagecCsH||jr||jjpdS||jr||jjpdStd|)zReturn the architecture of a package. This might differ on multiarch architectures (e. g. an i386 Firefox package on a x86_64 system)unknownrR)rWrX architecturer]rTrUrrrget_architecture]s   z%__AptDpkgPackageInfo.get_architecturecCs,|d|g}|dur dSdd|DS)z*Return list of files shipped by a package.z-LNcSsg|] }|ds|qS)diverted) startswith)rbr|rrrrdpsz2__AptDpkgPackageInfo.get_files..) _call_dpkg splitlines)rrVlistrrr get_filesjsz__AptDpkgPackageInfo.get_filesc Csnd||f}tj|sd|}zt|}t|js tt|j |j }Wn ty3gYSwd}d||f}tj|sPd|}tj|sPgSt |dQ}|D]F}z6d|vrgt d|WqX|} | sut d |WqXtd | d d d }t|j |j |krWqXWn tyYnw||7}qXWd n1swY|r||SgS)z/Return list of all modified files of a package.z/var/lib/dpkg/info/%s:%s.listz/var/lib/dpkg/info/%s.listz /var/lib/dpkg/info/%s:%s.md5sumsz/var/lib/dpkg/info/%s.md5sumsrz(%s contains NUL character, ignoring linez%%s contains empty line, ignoring liner9rUTF-8N)get_system_architecturer r!r#r2S_ISREGst_modeOSErrormaxst_mtimest_ctimer$rrrrencode_check_files_md5) rrVlistfilesmax_timesumssumfiler}r~wordsrrrget_modified_filesrsP            z'__AptDpkgPackageInfo.get_modified_filesc Cstjdddd|gtjd}|d}|jdkriSi}|D]f}|s'q"|dd\}}t j |rz0t |d  }| } Wdn1sNwYt} | | | } | |krh| ||<Wq"ty} zd t| ||<WYd} ~ q"d} ~ wwd ||<q"|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}--stdoutrNrz[inaccessible: %s]z [deleted]) subprocessPopenPIPE communicater returncoderrxrr r!r#r$rhashlibmd5rD hexdigestrzrH) rrVdpkgoutmodifiedr~r!default_md5sumr}contentsmcalculated_md5sumrPrrrget_modified_conffiless<        z+__AptDpkgPackageInfo.get_modified_conffilescCsd}d}d}|sC|t|krCtjdddd|g||||tjtjtjd}|dd }|jdkr7|}||7}|sC|t|ks|S) zsCall fgrep for a pattern on given file list and return the first matching file, or None if no file matches.Ndrfgrepz-lxm1r)stdinrstderrr)lenrrrrrr)rpattern file_listmatch slice_sizeiprrrr __fgrep_filess   z"__AptDpkgPackageInfo.__fgrep_filesNcCsj|r |||||Stjdd|gtjtjd}|dd}|jdkr3|r3|d}|dkr3|Stj tj |d } g} g} t dD](} tj tj | d d d} | | vsg| | vrm| | qJ| | qJ||| }|s||| }|s|d r|d d }|d || }|s|d || }|rtj tj |dd 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. z dpkg-divertz--listrrrrrzhardening-wrapperz/var/lib/dpkg/info/*.list:z/usrN%s)_search_contentsrrrrrrrr r!splitextbasenamelowerrwry _AptDpkgPackageInfo__fgrep_filesr)rfile uninstalled map_cachedirr/r0rrrZfname all_lists likely_listsr|rrrrrget_file_packages:  &     "z%__AptDpkgPackageInfo.get_file_packagecCsBtjddgtjd}|d}|jdksJ|sJ|S)zcReturn the architecture of the system, in the notation used by the particular distribution.rz--print-architecturerrrrrrrrxr)klassrr0rrrrs z,__AptDpkgPackageInfo.get_system_architecturecCs>tjddgtjd}|d}|jdksJd|S)zReturn 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_MULTIARCHrrz /lib/%s:/libr)rrmultiarch_triplerrrget_library_pathss z&__AptDpkgPackageInfo.get_library_pathscCs@||_z|jrt|jd|_WdSWdStyYdSw)zExplicitly 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)rrrrr set_mirror-s   z__AptDpkgPackageInfo.set_mirrorcCs tj}|rt}|d|||j|d<|r(t j gd|ddddd|g}|r;|d d |7<zt j |||d d kr|sKWd S| | ||} | rd} t jjddkrpt jjd} t jjddt jj} t j| } g} | D]}| t jj| ||dq| }|| jkrWd S| rt jjd| ttj|dD]}t j ddd|gt j|dqnWd SWn tyYd Swd }ttj||dD] }tj|r|}q|sJdz t j dd|dW|StyY|Sw)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"; APT_CONFIG)apt-get-qqrD)envrrz --assume-yessourcer=)cwdrrNrszAcquire::http::Proxy)destdirz*.dscz dpkg-sourcez-sn-x)rrz-*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 environcopytempfileNamedTemporaryFilewriterflushrarcallrget_distro_namer<rrfindrur=r>AcquireProgressAcquirery AcquireFilerunRESULT_CONTINUErwr!r"rrisdir)r srcpackagedirrYsandbox apt_updaterr|argvsf_urlsproxyrLfetcheraf_queuesfresultdscrootrcrrrget_source_tree>s           z$__AptDpkgPackageInfo.get_source_treecCsdtdS)zReturn the actual Linux kernel package name. This is used when the user reports a bug against the "linux" package. z linux-image-r)r unamerrrrget_kernel_packagesz'__AptDpkgPackageInfo.get_kernel_packagecCsg}g}|dd}|d}|dd}d|}|}||vr-||jr-||fStjjdd} d|||f} d | } ttj | | d } t | } | d krWd S | d}|s`n| |qX| | tddtj | | g}|dkr|| dd||fS)zInstall 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. Uname ArchitecturePackagezlinux-image-debug-%sDir::Cache::archivesz/partialz %s_%s_%s.ddebz,http://ddebs.ubuntu.com/pool/main/l/linux/%swr)rslinuxTi rz-ir_)rrA isInstalledr<rrfind_dirr$r r!r"rrrr$r%closerr&ry)rreportrXoutdatedkverr0ver debug_pkgnamec target_dirdebrrublockretrrr_install_debug_kernels8   z*__AptDpkgPackageInfo._install_debug_kernelTc =s|s|}|sd} ||_nftj||d} ||kr/tj|||d} tj| r/| } z ||| Wnt yT}zt dt |WYd}~nd}~wwt tj||d}||_Wdn1sqwYtj| st d| |rd}||kr|}nd}|rtj|||d }n tj|d |d }tj|st|nd }t}tjjd |tjjd dtjjddtjjdd|rtjj}ntjj}|s||| |||j| |n7||| ||j| tjtj |dz!|Wntj"j#y*}zt t |d}~ww tjj$d}d}tj%}tj|d}i}tj|r{t |!}|D]}|}|s_qT|&\}}|||<qTWdn 1svwYt}i}tj'|}g}| rBg} |D]\}!}"z|!}#Wnt(yd|!)dd}$||$d7}t |$Yqw|#j*j+D]~}%|%dj,vr҈-|%dj,d|%d<|%dj,j*j.}&|%dj,dd|Dvrq|%dj,|vr||%dj,}'|/|'|&dkr | 0|%dj,|'fn| 0|%dj,|&fn | 0|%dj,|&f|%dj,dd|Dvr9|0|%dj,dfqq|1| |D]J\}!}"z|!}#Wnt(ymd|!)dd}$||$d7}t |$YqDwz |"rx|#j2|"|#_*Wn9t(y|3|||!|"|\}(})|(r|0tjj4||(d|)|d|"||!<n |d |!|"|#j*j.f7}Ynw|#j*}*|5|!|r|6|}+|*j7D] }|+8|t5|!qg},d!|*j9vr|,tj:|*j9d!7},d"|*j9vr|,tj:|*j9d"7},|,D]}-|-dd|*j;j,kr q|-d}-<|-drtz|+|-d}.Wn t(y(Yqw|.D]E}||*j;j,kr6q+tj|d#|}/t==|/D]}0|>|0}"tj?|"|-d$|-d%r]t@|0qDz||=Wq+t(ypYq+w~.qtj|d#|-d}/t==|/D].}0|>|0}"tj?|"|-d$|-d%rt@|0z||-d=Wqt(yYqwqq|*jAd&kr| rzt|!d'}1|1}2d}3|"r z |2j2|"|2_*d }3Wn2t(y|3|||1|"|\}(})|(r|0tjj4||(d|)|d|"||1<d }3nt(Ynw|3s+z |2j2|*j.|2_*Wnt(y*|d(|!|"|2j*j.f7}Ynw|5|1WqDt(y|B|C|*jDrgfd)d|jED}4|"rf|4D]}2|2j*j.|"krd|4F|2qTng}4|4r|4D]m}||vrwqnd}3|"rz|j2|"|_*d }3Wn/t(y|3||||"|\}(})|(r|0tjj4||(d|)|d|"||<d }3Ynw|3sz |j2|*j.|_*Wn t(yYnw|5|qnnd}3|!d*}5zk|5}6|5|5|"r*z |6j2|"|6_*d }3Wn/t(y)|3|||5|"|\}(})|(r'|0tjj4||(d|)|d|"||5<d }3Ynw|3sMz |6j2|*j.|6_*Wnt(yL|d+|!|*j.|6j*j.f7}YnwWn;t(y|"r~|3|||5|"|\}(})|(r~|0tjj4||(d|)|d|"||5<d }3|3s|d,|!7}YnwYqDwqDtG|}7|HD]x}||7vr|7|dur|I||j*j.kr|F|q|Jddq|I||7|kr׈|Jddq|I||j*j.kr|Jddq|F|q|I||j*j.kr |Jddq|F|qtKK}8zjL|d-Wn"tj"j#y?}zt Md.t |tNOd%WYd}~nd}~ww|rGtPd/|jQD]c}9tRSd0d1|9jTgU}:|:&\}}|rq||vsqtjV|9jT|8kr|I||krzn||vr|||krntRWd2d3|9jT|g|||<tjX|9jT&d4d%d};|;|vr|F|;qJtY|Z}<|<[t |d5$}|.rcSr^r_rr_rrrrdqr`zsha1:%s)hashrz,%s version %s required, but %s is available ConflictsReplacesz%s_*.debrr@all-dbgzAoutdated -dbg package for %s: package version %s -dbg version %s cs2g|]}|dr|vrd|jjvr|qS)re transitional)rr] description)rbrrErrrdsz-dbgsymzKoutdated debug symbol package for %s: package version %s dbgsym version %s z%no debug symbol package found for %s )r6z+Package download error, try again later: %szExtracting downloaded debs...dpkg-debz--showrrrFrD z*apt fetcher did not fetch these packages: )`rget_distro_codenamecurrent_release_codenamer r!r"r#r$_get_primary_mirror_from_apt_sourcesrGrrrHr$rrxr.makedirsr"mkdtempr<rrrur=textr)r>rQr'rBr@rCrDrErFrH SourceRecordsrr*rSreplacer] dependenciesraget_providing_packagesrYcompare_versionsryextendversionsrr+addr+provides setdefaultrecord parse_dependsrVis_virtual_packagerw _deb_version check_depunlinkrrestartlookuprnbinariesr4dictr!rk mark_installtimefetch_archiveserrorsysexitprintitemsr check_outputdestfilergetctime check_callrrkeyssortr$rrr.)=rr;r(r/packagesverbose cache_dirpermanent_rootdirrrO install_dbg install_depsrKarch_apt_sourcesrPr| tmp_aptroot aptroot_archrJrL archivedirobsolete src_recordspkg_list pkg_versionsr~rv real_pkgslp_cacher6 acquire_queuedepsrZrM cache_pkgrdep dep_pkg_vers inst_versionlp_urlsha1sumr]virtual_mapping conflictsconflict providersdebsr!dbg_pkgdbg pkg_founddbgs dbgsym_pkgdbgsymrequested_pkgs last_writtenrrpkg_namepkgsrrhrinstall_packagess-                                                              ^   $         z%__AptDpkgPackageInfo.install_packagescCstj||S)z2Return known package names which match given glob.)rwfnmatchfilterrAr)rnameglobrrrpackage_name_globsz&__AptDpkgPackageInfo.package_name_globcCsDtjdg|tjtjd}|tdd}|jdkr|Std)zRCall dpkg with given arguments and return output, or return None on error.rrrrzpackage does not exist)rrrrinputrrrT)rargsrrrrrrs z__AptDpkgPackageInfo._call_dpkgcCstj|r!tjdd|gtjtjdid}|djddd}n&t|t ks+Jd tjddgtjtjtjdid }||djddd}|j dkrNgSg}| D]}| d rf| |d d dqT|S)zInternal function for calling md5sum. This is separate from get_modified_files so that it is automatically testable. z/usr/bin/md5sumz-cr9)rrrrrrrr)errorsz&md5sum list value must be a byte array)rrrrrFAILEDrr@)r r!r#rrrrrtyperrrrryrsplit)rrrr mismatchesr~rrrrs(      z%__AptDpkgPackageInfo._check_files_md5cCst|C}|D]9}|}t|dkr@|ddkr@|ddr#d}nd}||ds3||dr@||Wd Sqtd |1sJwYd S) z?Heuristically determine primary mirror from an apt sources.listrrQr@[rzhttp://zhttps://NzEcannot determine default mirror: %s does not contain a valid deb line)r$rrrrG)rrKr|r~fields mirror_idxrrrrms"    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.rV)rrmrrrr _get_mirrors z __AptDpkgPackageInfo._get_mirrorcCs"t|dr |jdur |jStd)z7Map a DistroRelease: field value to a release code namerlNzBCannot map DistroRelease to a code name without install_packages())hasattrrlNotImplementedError)rr/rrr_distro_release_to_codenamesz0__AptDpkgPackageInfo._distro_release_to_codenamec Cs$|r|}n |js t|_|j}|dur|}|dur!|}n||}dD]}tj|d|||f}d}zt |} t t | j } Wn t yTd} Ynw| dus^| dkrd||||f} | rzddlm} dd lm} Wntyddlm} dd lm} Ynwdd lm}| | d }| |}|d | | d |}|dd}|r||d}||| j k}nd}nd}|rd|_zt| }Wnty|dkrYq(wt|d} |d}|sn| |qWdn 1swY|!tj"|sJ|#|||}|r&t$|d kr)d|_|jrddl%}|d|d}d}|D]}|d 7}|dkrU|dvrU|dkrUq>|&d}|&dddkr|&dd dvrqq>|&dd dkr|&dd dvrq>|&d&dd&dd}n|&dddvr|&d&dd&dd}nq>||vr|||krÐq>|||<q>|||<q>Wdn 1swYq(|jr|'|||d|_t(|t)r|*}|dd kr|d d}|+g}|,d!r|-|d"d+nY|,d#r.|-|d"d+nG|,d$r@|-|d"d+n5|,d%rR|-|d"d+n#|,d&rd|-|d"d+n|,d'ru|-|d"d+|D]}z ||*}|WSt.yYqwwdS)(z4Internal function for searching file in Contents.gz.N)z -proposedrsz -securityz-updatesz%s%s-Contents-%s.gzFiQz%s/dists/%s%s/Contents-%s.gzr)HTTPConnection)urlparse)datetimer@HEADrz last-modifiedz%a, %d %b %Y %H:%M:%S %ZTrsr,i@Brr)trustyxenial!/susr)libslibexecslibx32binsbinsharesgamessBrotherr)sdocsiconssmanstexlivesgocodeslocaleshelpr,)rrrr9zusr/lib/x86_64-linux-gnu/rzusr/lib/i386-linux-gnu/zusr/lib/systemd/z usr/lib/udev/zusr/bin/z usr/sbin/)/rr"rorrkrr r!r"r2intrrrrhttplibrr ImportError http.client urllib.parserrequest getresponse getheaderstrptime fromtimestamprrrzr$rr$rIr#r6rgziprr8rrrrrryrS) rr r r/r0r0pocketmaprDstagerrrrserverconnres modified_strrsrcr|datacontents_mappingrrline_numr~r!rVfilesrZrrrrs                    ""               z%__AptDpkgPackageInfo._search_contentsc Cs|dr|ddd}d}t|dkr|dd}d}|t|krtd|d|}td||d}z2tttj j |||d } | | d kr[t d | Wdn1sewYWn#tt fy|d7}|t|kr|r|dd}d}nd}Yqw |r|rd ||||f} d ||||f} z,tt| } | | d krt d | Wdn1swYd} Wn tt fyd} Ynw| | d| dddSdS)aFor 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--rNTr@ppaFuserdistroppanamerrz-deb http://ppa.launchpad.net/%s/%s/%s %s mainz5http://ppa.launchpad.net/%s/%s/%s/dists/%s/main/debugz main/debugrsz deb-srcrr])rrrryrHr"rrr packagingrrrrr) rrprrN componentstry_ppaindexrppa_namerppa_line debug_url add_debugrrrcreate_ppa_source_from_originsl            z2__AptDpkgPackageInfo.create_ppa_source_from_originc Cstjtj|dddsMttj|dddddttj|dddddttj|dddttj|d dd ttj|d dd tj|d dd }tj|rat|tj|d rrt|d |nt|t |+}t tj|d ddd}| | Wdn1swYWdn1swY|rd} i} |D]} | dkrqd} tj|d rtj|d | d} tj| sd| vrtj|d | dd} tj| sd} ntj| sd} | rt |  } | } Wdn 1swYn| | ||} | r|t tj|d dd | dd }| | Wdn 1sCwY| D].}|drVqLd|vr]qL|ddd}|ddd}||f| | <qLqtd| qtjtj|d}tj|rt|tj|d dntjdrtdtj|d dtj|d dd}tj|rt|tj|d rt|d |ntjd rtd |nt||rV| rX| D]_\} \}}tjjt||t|d!}tj|}|sqz|d"}Wnty1td#|Yqwd$d%tj|d&| d'd(d)d*d+|g }t|d,krTtd-| qdSdSdS).Nvarlibr<listspartialrEarchivesretcz apt.conf.dz preferences.dzsources.list.dz.drWrDrsrz.listzLP-PPAra#zppa.launchpad.netr@r9rrz-Could not find or create source config for %sz trusted.gpgz/etc/apt/trusted.gpgz trusted.gpg.dz/etc/apt/trusted.gpg.drsigning_key_fingerprintz/Error: can't find signing_key_fingerprint at %szapt-keyz --keyringz%s.gpgadvz--quietz --keyserverzkeyserver.ubuntu.comz --recv-keyrzUnable to import key for %s)r r!r#r"rnrrr.copytreer$r$rrxrrrrrrdirnamer!rrrrr IndexErrorrr&)rapt_rootrKrMrNrOlist_drdestsource_list_content origin_datarp origin_pathsrc_extr~rr trusted_gpg trusted_dppa_userrppa_archive_urlppa_infor r3rrrrBs                    z'__AptDpkgPackageInfo._build_apt_sandboxcCsJtjdd|dgtjd}|tdd}|jdksJ|s#J|S)z!Return the version of a .deb fileriz-fVersionrrr)rrrrrrrxr)rrZrrrrrr~7s z!__AptDpkgPackageInfo._deb_versioncCstj||S)zkCompare two package versions. Return -1 for ver < ver2, 0 for ver1 == ver2, and 1 for ver1 > ver2.)r<rversion_compare)rver1ver2rrrruAsz%__AptDpkgPackageInfo.compare_versionscCsJ|jdur"tjddgtjd}|dd|_|jdks"J|jS)z(Get "lsb_release -sc", cache the result.N lsb_releasez-scrrr)_distro_codenamerrrrrrxr)rr!rrrrkJs  z(__AptDpkgPackageInfo.get_distro_codenamecCs<|jdur|d|_d|jvr|jdd|_|jS)zuGet osname from /etc/os-release, or if that doesn't exist, 'lsb_release -sir' output and cache the result.Nrrjr) _distro_namertrrrrrrrr'Ws  z$__AptDpkgPackageInfo.get_distro_name)F)FNNN)NNF)FNFNNTF)4__name__ __module__ __qualname____doc__rrr+r.r6r8rArQrWr\r^rmrorqrvrrrrrrrrr r classmethodrrrr<r>rUrrrrrmrrrrrBr~rur"rkr#r'rrrrr )s        " 0( 6   X' [      A k   r )#r'rr rwr2rr"rrrr contextlibrwarningsfilterwarnings FutureWarningr<cPickler%urllibrrrrzrrr urllib.errorurllib.requestrrapport.packagingr r implrrrrsH@       G