diff --git a/python/dnfdaemon/server/backend.py b/python/dnfdaemon/server/backend.py index bf9a95a..6d9c8bf 100644 --- a/python/dnfdaemon/server/backend.py +++ b/python/dnfdaemon/server/backend.py @@ -38,6 +38,7 @@ import sys import re import os +import libdnf.transaction logger = logging.getLogger('dnfdaemon.base.dnf') @@ -71,38 +72,38 @@ def __init__(self, parent): self._packages = None def _tree(self, dirpath): - """Traverse dirpath recursively and yield relative filenames.""" - for root, dirs, files in os.walk(dirpath): - base = os.path.relpath(root, dirpath) - for f in files: - path = os.path.join(base, f) - yield os.path.normpath(path) + """Traverse dirpath recursively and yield relative filenames.""" + for root, dirs, files in os.walk(dirpath): + base = os.path.relpath(root, dirpath) + for f in files: + path = os.path.join(base, f) + yield os.path.normpath(path) def _filter(self, files, patterns): - """Yield those filenames that match any of the patterns.""" - return (f for f in files for p in patterns if re.match(p, f)) + """Yield those filenames that match any of the patterns.""" + return (f for f in files for p in patterns if re.match(p, f)) def _clean(self, dirpath, files): - """Remove the given filenames from dirpath.""" - count = 0 - for f in files: - path = os.path.join(dirpath, f) - logger.debug(_('Removing file %s'), path) - misc.unlink_f(path) - count += 1 - return count + """Remove the given filenames from dirpath.""" + count = 0 + for f in files: + path = os.path.join(dirpath, f) + logger.debug(_('Removing file %s'), path) + misc.unlink_f(path) + count += 1 + return count def _removeCacheFiles(self): - ''' Remove solv and xml files ''' - cachedir = self.conf.cachedir + ''' Remove solv and xml files ''' + cachedir = self.conf.cachedir - types = [ 'metadata', 'packages', 'dbcache' ] - files = list(self._tree(cachedir)) - logger.debug(_('Cleaning data: ' + ' '.join(types))) + types = ['metadata', 'packages', 'dbcache'] + files = list(self._tree(cachedir)) + logger.debug(_('Cleaning data: ' + ' '.join(types))) - patterns = [dnf.repo.CACHE_FILES[t] for t in types] - count = self._clean(cachedir, self. _filter(files, patterns)) - logger.info( '%d file removed', count) + patterns = [dnf.repo.CACHE_FILES[t] for t in types] + count = self._clean(cachedir, self._filter(files, patterns)) + logger.info('%d file removed', count) def expire_cache(self): """Make the current cache expire""" @@ -163,12 +164,12 @@ def contains(self, attr, needle, ignore_case=True): else: return self.sack.query().filter(**fdict) -############################################################################### -# code copied from dnf for non public API related -# -# FIXME: this is copied from dnf/base.py, because there is no public -# API to handle gpg signatures. -############################################################################### + ############################################################################### + # code copied from dnf for non public API related + # + # FIXME: this is copied from dnf/base.py, because there is no public + # API to handle gpg signatures. + ############################################################################### def _sig_check_pkg(self, po): """Verify the GPG signature of the given package object. @@ -249,7 +250,7 @@ def _get_key_for_package(self, po, askcb=None, fullaskcb=None): def _prov_key_data(msg): msg += _('Failing package is: %s') % (po) + '\n ' msg += _('GPG Keys are configured as: %s') % \ - (', '.join(repo.gpgkey) + '\n') + (', '.join(repo.gpgkey) + '\n') return '\n\n\n' + msg user_cb_fail = False @@ -368,11 +369,15 @@ def updates(self): return pkgs # return install/upgrade type pkgs from transaction for tsi in self._base.transaction: - #print(tsi.op_type, tsi.installed, tsi.erased, tsi.obsoleted) + logger.debug(f" --> {tsi.action_name} : {tsi} action: {tsi.action} reason: {tsi.reason}") if tsi.action == dnf.transaction.PKG_UPGRADE: pkgs.append(tsi.pkg) elif tsi.action == dnf.transaction.PKG_INSTALL: # action is INSTALL, then it should be a installonlypkg + # skip dependencies (direct & real) + if tsi.reason == libdnf.transaction.TransactionItemReason_WEAK_DEPENDENCY or \ + tsi.reason == libdnf.transaction.TransactionItemReason_DEPENDENCY: + continue pkgs.append(tsi.pkg) return pkgs