a 2h&,@sdZddlmZddlmZddlmZddlZddlZddl Zddl Zddl Z ddl Z ddlZ ddlZddlZddlZedZGddde jZdS) z! Contains the dnf.Package class. )absolute_import)unicode_literals)_NdnfcseZdZdZdZdZfddZefddZej ddZed d Z ed d Z ed dZ eddZ eddZefddZej ddZeddZeddZeddZeddZddZed d!Zed"d#Zed$d%Zed&d'Zed(d)Zej d*d)Zed+d,Zed-d.Zed/d0Zed1d2Zed3d4Zed5d6Zed7d8Z d9d:Z!d;d<Z"d=d>Z#d?d@Z$dAdBZ%dNdDdEZ&dFdGZ'edHdIZ(dJdKZ)dLdMZ*Z+S)OPackagez Represents a package. #:api z -debuginfoz -debugsourcecs,tt||||_d|_d|_d|_dSN)superr__init__base _priv_chksum_repo _priv_size)selfZ initobjectr  __class__//usr/lib/python3.9/site-packages/dnf/package.pyr 0s zPackage.__init__c s|jr |jS|jrtjj}ztj||j }Wn8tj j yj}ztj t|WYd}~n d}~00t|t|fStt|jSr)r _from_cmdlinerZyumZmiscZget_default_chksum_typelibdnfutilsZchecksum_valuelocationerrorError exceptions MiscErrorstrhawkey chksum_typebinasciiZ unhexlifyrrchksum)rrZ chksum_valerrr_chksum7s &zPackage._chksumcCs ||_dSr)r rvalrrrr!EscCs |jtjkSr)reponamerZCMDLINE_REPO_NAMErrrrrIszPackage._from_cmdlinecCs |jtjkSr)r$rSYSTEM_REPO_NAMEr%rrr _from_systemMszPackage._from_systemcCs*d}|jr|jj|}|r$d|S|jS)a9 For installed packages returns id of repository from which the package was installed prefixed with '@' (if such information is available in the history database). Otherwise returns id of repository the package belongs to (@System for installed packages of unknown origin) N@)r'r historyrepor$)rZpkgreporrr _from_repoQs zPackage._from_repocCs|jr|jj|SdS)N)r'r r)r*r%rrr from_repo`szPackage.from_repocCstj|S)z Returns the header of a locally present rpm package file. As opposed to self.get_header(), which retrieves the header of an installed package from rpmdb. )rrpm_headerlocalPkgr%rrrr/gszPackage._headercs|jr |jStt|jSr)r rrsizer%rrr_sizepsz Package._sizecCs ||_dSr)r r"rrrr2vscCs"|jdurdS|j\}}t|Sr)Z hdr_chksumrhexlify)rrrrrr_pkgidzs  zPackage._pkgidcCs4|jdur,tj|jd}|ddd}nd}|S)zO returns name of source package e.g. krb5-libs -> krb5 Nz.src.rpm-r)Z sourcerpmrutilZrtrimrsplit)rsrcnamerrr source_names  zPackage.source_namecCsF|j|jr|jS|j}|j|jr<|dt|j }||jS)a) Returns name of the debuginfo package for this package. If this package is a debuginfo package, returns its name. If this package is a debugsource package, returns the debuginfo package for the base package. e.g. kernel-PAE -> kernel-PAE-debuginfo N)nameendswithDEBUGINFO_SUFFIXDEBUGSOURCE_SUFFIXlen)rr;rrr debug_names zPackage.debug_namecCs |jdur|jn|j}||jS)zv Returns name of the debugsource package for this package. e.g. krb5-libs -> krb5-debugsource N)r:r;r>rZsrc_namerrrdebugsource_nameszPackage.debugsource_namecCsN|js dSzt|jjtj|jWStyHt j dt |Yn0dS)a` Returns the rpm header of the package if it is installed. If not installed, returns None. The header is not cached, it is retrieved from rpmdb on every call. In case of a failure (e.g. when the rpmdb changes between loading the data and calling this method), raises an instance of PackageNotFoundError. Nz4Package not found when attempting to retrieve header) r'nextr Z_tsZdbMatchr.ZRPMDBI_PACKAGESrpmdbid StopIterationrrZPackageNotFoundErrorrr%rrr get_headers  zPackage.get_headercCs |jdur|jn|j}||jS)z returns name of debuginfo package for source package of given package e.g. krb5-libs -> krb5-debuginfo N)r:r;r=rArrrsource_debug_nameszPackage.source_debug_namecCs t|jS)z: Always type it to int, rpm bindings expect it like that. )intrDr%rrridxsz Package.idxcCs|jSrr$r%rrrrepoidszPackage.repoidcCs|j|jt|j|j|jfSr)r;archrr vrr%rrrpkgtupszPackage.pkgtupcCs|jr |jS|jj|jSr)r r Zreposr$r%rrrr*sz Package.repocCs ||_dSr)r r"rrrr*scCs |jtjkrdS|jjj|Sr)rKrr&r r)r.Zget_reason_namer%rrrreasons zPackage.reasoncCs|jSr)rr%rrr relativepathszPackage.relativepathcCs|jSr)rLr%rrrasz Package.acCs|jSr)Zepochr%rrrr sz Package.ecCs|jSr)versionr%rrrrMsz Package.vcCs|jSr)releaser%rrrrNsz Package.rcCs|jSrrJr%rrr ui_from_reposzPackage.ui_from_repocCs||dkSNrZevr_cmprpkgrrrevr_eqszPackage.evr_eqcCs||dkSrVrWrXrrrevr_gt szPackage.evr_gtcCs||dkSrVrWrXrrrevr_lt szPackage.evr_ltcCs|jSr)Zmedianrr%rrr getDiscNumszPackage.getDiscNumcCsr|jr |jS|j}|jjrH|jrH|jdrHtj | | dS| s\tj |}tj |j| dS)z Package's location in the filesystem. For packages in remote repo returns where the package will be/has been downloaded. file:///)rrr*r isLocalbaseurl startswithospathjoinZget_local_baseurllstrip _is_local_pkgbasenamepkgdir)rlocrrrr0s zPackage.localPkghttpftpfilehttpscCs>|js |jrdS|jr.tj|j|jdS|j |j|S)a The location from where the package can be downloaded from. Returns None for installed and commandline packages. :param schemes: list of allowed protocols. Default is ('http', 'ftp', 'file', 'https') :return: location (string) or None Nr_) r'rrarcrdrerrfr*remote_location)rZschemesrrrrp$s zPackage.remote_locationcCsJ|jr dSd|jvr$|jds$dS|jpH|jjoH|j pH|jdS)NTz://r^F)r'rrbrr*r r`rar%rrrrg3szPackage._is_local_pkgcCs*|jjr|s|jS|jjSdSr)r*r r`rgZ cache_pkgdirrir%rrrri<s zPackage.pkgdircCs0|jdurdS|j\}}t|t|fS)z] Return the chksum type and chksum string how the legacy yum expects it. N)NN)r!rZ chksum_namerr3decode)rrrrrr returnIdSumDs  zPackage.returnIdSumc Csx|jrtd|jrdS|\}}ztj|||WStjj yr}zt j t |WYd}~n d}~00dS)Nz$Can not verify an installed package.T)r' ValueErrorrrrrrZchecksum_checkr0rrrrrr)rrrr rrrverifyLocalPkgNs zPackage.verifyLocalPkg)rk),__name__ __module__ __qualname____doc__r=r>r propertyr!setterrr'r+r-r/r2r4r:r@rBrFrGrIrKrOr*rPrQrRr rMrNrUrZr[r\r]r0rprgrirrrt __classcell__rrrrr*s                              r)rxZ __future__rrZdnf.i18nrrZdnf.exceptionsrZdnf.rpmZ dnf.yum.miscrZ libdnf.errorrZ libdnf.utilsZloggingrcr.Z getLoggerloggerrrrrrs