1280 $ ˆl–äY>”Ð?Jq@¿q§®2Ú˜´oÆ „Y¿ÅÄÃ,& # package.py # Module defining the dnf.Package class. # # Copyright (C) 2012-2016 Red Hat, Inc. # # This copyrighted material is made available to anyone wishing to use, # modify, copy, or redistribute it subject to the terms and conditions of # the GNU General Public License v.2, or (at your option) any later version. # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY expressed or implied, including the implied warranties of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General # Public License for more details. You should have received a copy of the # GNU General Public License along with this program; if not, write to the # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. Any Red Hat trademarks that are incorporated in the # source code or documentation are not subject to the GNU General Public # License and may only be used or replicated with the express permission of # Red Hat, Inc. # """ Contains the dnf.Package class. """ from __future__ import absolute_import from __future__ import unicode_literals from dnf.i18n import _ import binascii import dnf.exceptions import dnf.rpm import dnf.yum.misc import hawkey import libdnf.error import libdnf.utils import logging import os import rpm logger = logging.getLogger("dnf") class Package(hawkey.Package): """ Represents a package. #:api """ DEBUGINFO_SUFFIX = "-debuginfo" # :api DEBUGSOURCE_SUFFIX = "-debugsource" # :api def __init__(self, initobject, base): super(Package, self).__init__(initobject) self.base = base self._priv_chksum = None self._repo = None self._priv_size = None @property def _chksum(self): if self._priv_chksum: return self._priv_chksum if self._from_cmdline: chksum_type = dnf.yum.misc.get_default_chksum_type() try: chksum_val = libdnf.utils.checksum_value(chksum_type, self.location) except libdnf.error.Error as e: raise dnf.exceptions.MiscError(str(e)) return (hawkey.chksum_type(chksum_type), binascii.unhexlify(chksum_val)) return super(Package, self).chksum @_chksum.setter def _chksum(self, val): self._priv_chksum = val @property def _from_cmdline(self): return self.reponame == hawkey.CMDLINE_REPO_NAME @property def _from_system(self): return self.reponame == hawkey.SYSTEM_REPO_NAME @property def _from_repo(self): """ 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) """ pkgrepo = None if self._from_system: pkgrepo = self.base.history.repo(self) if pkgrepo: return '@' + pkgrepo return self.reponame @property def from_repo(self): # :api if self._from_system: return self.base.history.repo(self) return "" @property def _header(self): """ 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. """ return dnf.rpm._header(self.localPkg()) @property def _size(self): if self._priv_size: return self._priv_size return super(Package, self).size @_size.setter def _size(self, val): self._priv_size = val @property def _pkgid(self): if self.hdr_chksum is None: return None (_, chksum) = self.hdr_chksum return binascii.hexlify(chksum) @property def source_name(self): # :api """ returns name