o åvŽfø+ã@spdZddlZddlZddlZddlZddlZddlZddlZdd„Zdd„Z d dd „Z ddgdddfd d „Z dS) zFunctions to manage sandboxeséNc Cs†i}| dd¡d| dd¡ ¡D]'}| ¡sqz | ¡dd…\}}Wnty4t d|¡Yqw|||<qdd „| ¡DƒS) z™Determine necessary packages for given report. Return list of (pkgname, version) pairs. version might be None for unknown package versions. ÚPackageÚÚ Ú DependenciesNéú%invalid Package/Dependencies line: %scSsg|]\}}||f‘qS©r)Ú.0ÚpÚvrrú5/usr/lib/python3/dist-packages/apport/sandboxutils.pyÚ %sz#needed_packages..)ÚgetÚ splitlinesÚstripÚsplitÚ ValueErrorÚapportÚwarningÚitems)ÚreportÚpkgsÚlineÚpkgÚversionrrr Úneeded_packagess$  ý rc Csxi}| dd¡d| dd¡ ¡D]'}| ¡sqz | ¡dd…\}}Wnty4t d|¡Yqw|||<q|S)z0Return package -> version dictionary from reportrrrrNrr)rrrrrrr)rÚpkg_versrrrrrr Úreport_package_versions(s$  ý rFc stƒ}tƒ}d|vr<|d ¡D]*}| ¡sq| ¡}t|ƒdvr:d|dvr:d|dvr:tj |d¡} | | ¡qn t j   |d¡  ¡}tj  |¡sQt |¡|D]+}t jj|d||d | d ¡d } | rx|rrt  d || f¡| | ¡qSt  d |¡qS‡fdd„|DƒS)aæDetermine necessary runtime packages for given report. This determines libraries dynamically loaded at runtime in two cases: 1. The executable has already run: /proc/pid/maps is used, from the report 2. The executable has not already run: shared_libraries() is used The libraries are resolved to the packages that installed them. Return list of (pkgname, None) pairs. When pkgmap_cache_dir is specified, it is used as a cache for get_file_package(). ÚProcMaps)ééÚxéz.soéÚExecutablePathTÚ DistroReleaseÚ Architecture©ÚreleaseÚarchz0dynamically loaded %s needs package %s, queueingz/%s is needed, but cannot be mapped to a packagecsg|] }|ˆ |¡f‘qSr)r)r r ©Ú pkg_versionsrr r hsz+needed_runtime_packages..)ÚsetrrrÚlenÚosÚpathÚrealpathÚaddrÚ fileutilsÚshared_librariesÚvaluesÚexistsÚmakedirsÚ packagingÚget_file_packagerÚlogr) rÚsandboxÚpkgmap_cache_dirr+ÚverboserÚlibsrÚcolsÚlibrrr*r Úneeded_runtime_packages:s<$ €ú   þÿ ÿr@cCs”|rtj |¡}tj |¡st |¡d}ntjdd}t t j |¡d}|r.tj |¡}n tjdd}t t j |¡tj  ||d¡} g} d|vsXd|  d d ¡|  d d ¡vr\t |ƒ} g} |D] } |  | d f¡q`|d krpd }d } |r—|  d d ¡d|  d d ¡}t d¡}t| |¡ƒ} | r—t d| ¡ztjj|||d| ||||  d¡| d }WntyÆ}z t t|ƒ¡WYd }~nd }~ww| rýz|tjj|||d| ||||  d¡| ddd 7}Wntyü}z t t|ƒ¡WYd }~nd }~wwt|ƒ}t||| ||ƒ} dD]N}||vrXtjj||d| |d|  d¡d}|dkr6|ddkr6d|d<d}|rOt d||f|¡|  ||  |¡f¡q t d|||¡q | rz|tjj|||d| ||||  d¡| d 7}Wnty}z t t|ƒ¡WYd }~nd }~wwd |vr¹dD]!}||vr·tj |||¡s·t d|||||d ¡q—|rÀ||d<t d¡|||fS) a0 Build a sandbox with the packages that belong to a particular report. This downloads and unpacks all packages from the report's Package and Dependencies fields, plus all packages that ship the files from ProcMaps (often, runtime plugins do not appear in Dependencies), plus optionally some extra ones, for the distro release and architecture of the report. For unpackaged executables, there are no Dependencies. Packages for shared libaries are unpacked. report is an apport.Report object to build a sandbox for. Presence of the Package field determines whether to determine dependencies through packaging (via the optional report['Dependencies'] field), or through ldd via needed_runtime_packages() -> shared_libraries(). Usually report['Architecture'] and report['Uname'] are present. config_dir points to a directory with by-release configuration files for the packaging system, or "system"; this is passed to apport.packaging.install_packages(), see that method for details. cache_dir points to a directory where the downloaded packages and debug symbols are kept, which is useful if you create sandboxes very often. If not given, the downloaded packages get deleted at program exit. sandbox_dir points to a directory with a permanently unpacked sandbox with the already unpacked packages. This speeds up operations even further if you need to create sandboxes for different reports very often; but the sandboxes can become very big over time, and you must ensure that an already existing sandbox matches the DistroRelease: and Architecture: of report. If not given, a temporary directory will be created which gets deleted at program exit. extra_packages can specify a list of additional packages to install which are not derived from the report and will be installed along with their dependencies. If verbose is True (False by default), this will write some additional logging to stdout. If log_timestamps is True, these log messages will be prefixed with the current time. If dynamic_origins is True (False by default), the sandbox will be built with packages from foreign origins that appear in the report's Packages:/Dependencies:. Return a tuple (sandbox_dir, cache_dir, outdated_msg). TÚapport_sandbox_)ÚprefixFÚ apport_cache_r%rz[originrrrNÚsystemrz+\[origin: ([a-zA-Z0-9][a-zA-Z0-9\+\.\-]+)\]z Origins: %sr&)Ú architectureÚorigins)rErFÚ install_dbgÚ install_deps)ÚInterpreterPathr$r'Ú systemctlÚ SourcePackageÚsystemdz/bin/systemctlr$z%Installing extra package %s to get %sz%Cannot find package which ships %s %sz2%s %s does not exist (report specified package %s)ÚRetraceOutdatedPackagesz built sandbox)r.r/ÚabspathÚisdirr6ÚtempfileÚmkdtempÚatexitÚregisterÚshutilÚrmtreeÚjoinrrÚappendÚreÚcompiler,Úfindallrr9r7Úinstall_packagesÚ SystemErrorÚfatalÚstrrr@r8r5Úmemdbg)rÚ config_dirÚ cache_dirÚ sandbox_dirÚextra_packagesr<Úlog_timestampsÚdynamic_originsÚpermanent_rootdirr;rÚ extra_pkgsr rFÚpkg_listÚmÚ outdated_msgÚer+r/rrrr Ú make_sandboxks²4     $    ý€ÿ   ü€ÿ þ €   ý€ÿ  ÿ€  rl)F) Ú__doc__rRr.Úos.pathrXrTrPrrrr@rlrrrr Ús0  1þ