Blame dnf/sack.py

Packit 6f3914
# sack.py
Packit 6f3914
# The dnf.Sack class, derived from hawkey.Sack
Packit 6f3914
#
Packit 6f3914
# Copyright (C) 2012-2016 Red Hat, Inc.
Packit 6f3914
#
Packit 6f3914
# This copyrighted material is made available to anyone wishing to use,
Packit 6f3914
# modify, copy, or redistribute it subject to the terms and conditions of
Packit 6f3914
# the GNU General Public License v.2, or (at your option) any later version.
Packit 6f3914
# This program is distributed in the hope that it will be useful, but WITHOUT
Packit 6f3914
# ANY WARRANTY expressed or implied, including the implied warranties of
Packit 6f3914
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
Packit 6f3914
# Public License for more details.  You should have received a copy of the
Packit 6f3914
# GNU General Public License along with this program; if not, write to the
Packit 6f3914
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit 6f3914
# 02110-1301, USA.  Any Red Hat trademarks that are incorporated in the
Packit 6f3914
# source code or documentation are not subject to the GNU General Public
Packit 6f3914
# License and may only be used or replicated with the express permission of
Packit 6f3914
# Red Hat, Inc.
Packit 6f3914
#
Packit 6f3914
Packit 6f3914
from __future__ import absolute_import
Packit 6f3914
from __future__ import unicode_literals
Packit 6f3914
import dnf.util
Packit 6f3914
import dnf.package
Packit 6f3914
import dnf.query
Packit 6f3914
import hawkey
Packit 6f3914
import os
Packit 6f3914
from dnf.pycomp import basestring
Packit 6f3914
Packit 6f3914
Packit 6f3914
class Sack(hawkey.Sack):
Packit 6f3914
    # :api
Packit 6f3914
Packit 6f3914
    def __init__(self, *args, **kwargs):
Packit 6f3914
        super(Sack, self).__init__(*args, **kwargs)
Packit 6f3914
Packit 6f3914
    def _configure(self, installonly=None, installonly_limit=0):
Packit 6f3914
        if installonly:
Packit 6f3914
            self.installonly = installonly
Packit 6f3914
        self.installonly_limit = installonly_limit
Packit 6f3914
Packit 6f3914
    def query(self, flags=0):
Packit 6f3914
        # :api
Packit 6f3914
        """Factory function returning a DNF Query."""
Packit 6f3914
        return dnf.query.Query(self, flags)
Packit 6f3914
Packit 6f3914
Packit 6f3914
def _build_sack(base):
Packit 6f3914
    cachedir = base.conf.cachedir
Packit 6f3914
    # create the dir ourselves so we have the permissions under control:
Packit 6f3914
    dnf.util.ensure_dir(cachedir)
Packit 6f3914
    return Sack(pkgcls=dnf.package.Package, pkginitval=base,
Packit 6f3914
                arch=base.conf.substitutions["arch"],
Packit 6f3914
                cachedir=cachedir, rootdir=base.conf.installroot,
Packit 6f3914
                logfile=os.path.join(base.conf.logdir, dnf.const.LOG_HAWKEY),
Packit 6f3914
                logdebug=base.conf.debuglevel > 2)
Packit 6f3914
Packit 6f3914
Packit 6f3914
def _rpmdb_sack(base):
Packit 6f3914
    # used by subscription-manager (src/dnf-plugins/product-id.py)
Packit 6f3914
    sack = _build_sack(base)
Packit 6f3914
    try:
Packit 6f3914
        # It can fail if rpmDB is not present
Packit 6f3914
        sack.load_system_repo(build_cache=False)
Packit 6f3914
    except IOError:
Packit 6f3914
        pass
Packit 6f3914
    return sack
Packit 6f3914
Packit 6f3914
Packit 6f3914
def rpmdb_sack(base):
Packit 6f3914
    # :api
Packit 6f3914
    """
Packit 6f3914
    Returns a new instance of sack containing only installed packages (@System repo)
Packit 6f3914
    Useful to get list of the installed RPMs after transaction.
Packit 6f3914
    """
Packit 6f3914
    return _rpmdb_sack(base)