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