J0mh2dZddlZddlZddlZddlZddlZddlZddlZddl m Z dZ dZ ddZdeeedezfddfd Z dd ej&d edzd edzd edzdeedzdedededeeeeffdZy)zFunctions to manage sandboxes.N)implcdi}|jddd|jddjD]/}|js |jdd\}}|||<1t|jS#t$r#t j jd|YvwxYw)zDetermine 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: %s) get splitlinesstripsplit ValueErrorapportloggingwarninglistitems)reportpkgslinepkgversions 5/usr/lib/python3/dist-packages/apport/sandboxutils.pyneeded_packagesrs D ::i $ %R >2(F'GHjl zz|  !ZZ\"1-NS' S       NN " "#JD Q  s B)B/.B/c6i}|jddd|jddjD]/}|js |jdd\}}|||<1|S#t$r#t j jd|Y_wxYw)z1Return package -> version dictionary from report.rrrrNr r )r r r rrrrr)rpkg_versrrrs rreport_package_versionsr1sH ::i $ %R >2(F'GHjl  zz|  !ZZ\"1-NS'      O   NN " "#JD Q  s A,,)BBc zt}t}d|vr|djD]t}|js|j}t |dvs2d|dvs:d|dvsBt j j|d}|j|vn0tjj|dj}t j j|st j||D]}tj |d||d |j#d  } | r:|r&tj$j'd |d | d|j| ktj$j)d||D cgc]} | |j#| fc} Scc} w)aDetermine 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>xz.soExecutablePathT DistroRelease Architecturereleasearchzdynamically loaded z needs package z , queueingz/%s is needed, but cannot be mapped to a package)setr r rlenospathrealpathaddr fileutilsshared_librariesvaluesexistsmakedirs packagingget_file_packager rlogr) rpkgmap_cache_dir pkg_versionsverboserlibsrcolslibrps rneeded_runtime_packagesrADs 5D 5DV:&113 D::<::>* + $%((   ?+N+   "")$se:N HHSM NN " "A4 &/3 3Q   # $ 33 3sF8rreturncpt|D](\}\}}|dk(s|j|d|fg|ddyy)z2Move base-files to the front or add it if missing.z base-filesNr) enumeratepop)rirrs r_move_base_files_firstrG{sG&t_>C ,  HHQK%w/0D!H  r config_dir cache_dir sandbox_dirextra_packagesr<log_timestampsdynamic_originscN |rVtjj|}tjj|stj|d}n 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). Tapport_sandbox_)prefixF apport_cache_r'r z[originrrrsystemNrz+\[origin: ([a-zA-Z0-9][a-zA-Z0-9\+\.\-]+)\]z Origins: r() architectureoriginsz%s)rTrU install_dbg install_deps)InterpreterPathr&r) systemctl SourcePackagesystemdz/bin/systemctlr&zInstalling extra package z to get z%Cannot find package which ships %s %sz/usrz2%s %s does not exist (report specified package %s)RetraceOutdatedPackagesz built sandbox)"r.r/abspathisdirr6tempfilemkdtempatexitregistershutilrmtreejoinr rrecompiler,findallrrr9rGr7install_packages SystemErrorfatalstrrrAr8appendr5 startswithmemdbg)rrIrJrKrLr<rMrNpermanent_rootdirr:rrUpkg_listmatch outdated_msgerrorr@r;r/rs r make_sandboxrvszggook2 ww}}[) KK $ &&.?@  {3!GGOOI. $$O<  y1ww||Ivo/FG D 9 9b!FJJ~r$BB$v&X GjjB/06::nb3Q2RS IJemmH-.  NN  7)4 54  / 11   ? #    N3   3 I66'$23q!T3!#ZZ7!!  L +62L "6+;\7 SD6 6>,,t  /ZZ/ Ck!/*i7/?F+,#C""/uHTFC^ S,"2"23"789$$;T6$</8  3 I66'!#ZZ7  L$F9 Dv~bggnn[6$<5O&P$<**62ww~~kF4L4D&DE'-d|AB'7t ,,P '&,6"9- NN((L#fTl2y)  (,8() NN/*  < //K /T3u:../4 3 NN s5z 2 2 3b 3 NN s5z 2 2 3sZ0Q"R'* R"5 R'/3S'" R+)RR"R'' S$0)SS$' T$0)TT$)F)NNNFFF)__doc__rbr.rgrdr`apport.fileutilsrapport.loggingapport.packaging_implrr7rrrArtuplermrGReportboolrvrHrrs$ 32&44neCO&