!f,RdZddlZddlZddlZddlZddlZGddZeZy)zA partial apport.PackageInfo class implementation for RPM. Used as a base class for Fedora, RHEL, openSUSE, SUSE Linux, and many other distributions. NceZdZdZdZdZdZdZdZdZ dZ d Z d Z dd Z ed ZdZdZddZdZdZdZedZedZedZy )RPMPackageInfozcPartial apport.PackageInfo class implementation for RPM, as found in Fedora, RHEL, CentOS, etc.cDtj|_d|_y)N)rpmTransactionSetts_mirror)selfs ;/usr/lib/python3/dist-packages/apport/packaging_impl/rpm.py__init__zRPMPackageInfo.__init__.s$$& c|j|}|t|ds |dd|dS|dr|dsy|dd|dd|dS)z*Return the installed version of a package.Nev-r:) _get_header ValueErrorr packagehdrs r get_versionzRPMPackageInfo.get_version2spw' ; 3x#hZqS + +3xs3xc(1SXJaCz22rctd)z1Return the latest available version of a package.Emethod must be implemented by distro-specific RPMPackageInfo subclassNotImplementedError)r rs r get_available_versionz$RPMPackageInfo.get_available_version>s" S  rc<|j|}g}|dD]}|jds|jdr&|ddk(r|jd|}n|jd|}|D])}|j|}||vs|j |+|S)z/Return a list of packages a package depends on.requiresrpmlibzuname(r/ basenamesprovides)r startswith_get_headers_by_tag_make_envra_from_headerappend)r rrreqsr req_headsrhrh_envras r get_dependencieszRPMPackageInfo.get_dependenciesEsw'Z *A||H%h)?ts{ 44[!D  44ZC  *77;4'KK) * * rc.|j|}|dS)z-Return the source package name for a package. sourcerpmrrs r get_sourcezRPMPackageInfo.get_sourceWsw';rc.|j|}|dS)zReturn the architecture of a package. This might differ on multiarch architectures (e. g. an i386 Firefox package on a x86_64 system). archr1rs r get_architecturezRPMPackageInfo.get_architecture\sw'6{rc|j|}g}t|d|dD],\}}tj|r|j |.|S)z*Return list of files shipped by a package. filenames filemodes)rzipstatS_ISDIRr))r rrfilesfmodes r get_fileszRPMPackageInfo.get_filesgsYw'3{+S-=> GAt<<% Q  rc|j|}|d}|d}|d}g}t|D]\}}||s tj|tjs1tj |} t j | jsf||| jk(ry|j|||r|j||S)z/Return list of all modified files of a package.r7 filemtimesfilemd5s) r enumerateosaccessR_OKr:S_ISREGst_modest_mtime _checkmd5r)) r rrr<mtimesmd5smodifiedifilenamess r get_modified_filesz!RPMPackageInfo.get_modified_filespsw'K \":$U+ *KAx799Xrww/!A<< *ayAJJ&>>(DG4)! *$rNctd)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. rr)r file uninstalled map_cachedirreleaser4s r get_file_packagezRPMPackageInfo.get_file_packages"" S  rctjgddtjd}|jj }|S)zcReturn the architecture of the system, in the notation used by the particular distribution.)rz--evalz %_target_cpuT)checkstdouttext) subprocessrunPIPErZstrip)rpmarchr4s r get_system_architecturez&RPMPackageInfo.get_system_architectures;.. -??   ~~##% rc|js td|j|}|sy|dr&|dddjd}||jvryy)zaCheck if a package is a genuine distro package (True) or comes from a third-party source.z0Subclass the RPM implementation for your distro!Fsiggpg hexT)official_keylistrrencode)r rrkeyids r is_distro_packagez RPMPackageInfo.is_distro_packagesm$$%B w' x=M"R(//6E---rc||_y)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)r )r urls r set_mirrorzRPMPackageInfo.set_mirrors  rctd)aDownload source package and unpack it into output_dir. This also has to care about applying patches etc., so that output_dir will eventually contain the actually compiled source. output_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, that sandbox is used to download the source package, otherwise it uses the system configuration. Return the directory that contains the actual source root directory (which might be a subdirectory of output_dir). Return None if the source is not available. rr)r srcpackage output_dirversionsandboxs r get_source_treezRPMPackageInfo.get_source_trees$" S  rctd)ztCompare two package versions. Return -1 for ver < ver2, 0 for ver1 == ver2, and 1 for ver1 > ver2. rr)r ver1ver2s r compare_versionszRPMPackageInfo.compare_versionss" S  rctd)z2Return known package names which match given glob.TODOr)r nameglobs r package_name_globz RPMPackageInfo.package_name_globs !&))rc|jj||}|jdk(rtd|d||S)zQGet a list of RPM headers by doing dbMatch on the given tag and argument.rzCould not find package with z: )r dbMatchcountr)r tagargmatchess r r'z"RPMPackageInfo._get_headers_by_tagsD''//#s+ ==?a ;C53%HI Irc|}t|}|dkDr[tjjd|}t |}t|dkDr|d}n|dt|dz }|dz }|dkDr[|dk(rt d|S)z0Get the RPM header that matches the given ENVRA.rnamez!No headers found for this envra: )lenimplr r}listr)envraquerystrqlenmihdrshs r rzRPMPackageInfo._get_headers5zQh2B8D4y1} G CMA$56H!8DQh 19@HI Irc^|dd|dd|dd|d}|dr |dd|}|S|}|S) z,Generate an ENVRA string from an rpm header.nrrr.r4rrr)rnvrars r r(z&RPMPackageInfo._make_envra_from_headers^C&1S6(!AcF81QvYK8 S6vhav&E E rctj}t|d5}|j}ddd|j ||j k(S#1swY-xYw)zCheck a file's md5sum.zutf-8)encodingN)hashlibmd5openreadupdate hexdigest)rOfilemd5mmd5_filedatas r rJzRPMPackageInfo._checkmd5$sW KKM (W - #==?D # !++-'' # #s AA()FNNN)NN)__name__ __module__ __qualname____doc__rgr rrr.r2r5r?rQrW staticmethodrarjrmrsrwr{r'rr(rJrrr rr&s+  3 $ <NR *  ( ,  *.((rr)rrrDr:r\rrrrrr rs46  E(E(Pr