From a57fa91d69ea89e494b7312335b168e21c4f7cfb Mon Sep 17 00:00:00 2001 From: Eli Young Date: Tue, 27 Nov 2018 19:25:45 -0800 Subject: [PATCH] Support currrent versions of DNF --- tracer/packageManagers/dnf.py | 11 ++++++++++- tracer/packageManagers/rpm.py | 36 ++++++++++++++++++++++++----------- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/tracer/packageManagers/dnf.py b/tracer/packageManagers/dnf.py index 3f4cae7..a835133 100644 --- a/tracer/packageManagers/dnf.py +++ b/tracer/packageManagers/dnf.py @@ -18,6 +18,7 @@ from __future__ import absolute_import +import os.path from tracer.resources.system import System if System.distribution() in ["fedora", "mageia"]: @@ -27,8 +28,16 @@ class Dnf(Rpm): + def __init__(self, **kwargs): + super(Dnf, self).__init__(**kwargs) + if os.path.exists('/var/lib/dnf/history.sqlite'): + self.opts['modern_swdb'] = True + @property - def history_path(self): return '/var/lib/dnf/history/' + def history_path(self): + if self.opts.get('modern_swdb'): + return '/var/lib/dnf/history.sqlite' + return '/var/lib/dnf/history/' def package_files(self, pkg_name): if self._is_installed(pkg_name): diff --git a/tracer/packageManagers/rpm.py b/tracer/packageManagers/rpm.py index 77594c6..9c158e0 100644 --- a/tracer/packageManagers/rpm.py +++ b/tracer/packageManagers/rpm.py @@ -55,17 +55,29 @@ def packages_newer_than(self, unix_time): if not os.path.exists(self.history_path): return PackagesCollection([]) - sql = """ - SELECT DISTINCT pkgtups.name, trans_end.timestamp AS end - - FROM trans_beg JOIN trans_end JOIN trans_data_pkgs JOIN pkgtups - ON trans_beg.tid=trans_end.tid - AND trans_data_pkgs.tid=trans_beg.tid - AND trans_data_pkgs.pkgtupid=pkgtups.pkgtupid - - WHERE trans_beg.timestamp > ? - ORDER BY pkgtups.name - """ + if self.opts.get('modern_swdb'): + sql = """ + SELECT DISTINCT rpm.name, trans.dt_end AS end + + FROM trans JOIN trans_item JOIN rpm + ON trans.id=trans_item.trans_id + AND trans_item.item_id=rpm.item_id + + WHERE trans.dt_begin > ? + ORDER BY rpm.name + """ + else: + sql = """ + SELECT DISTINCT pkgtups.name, trans_end.timestamp AS end + + FROM trans_beg JOIN trans_end JOIN trans_data_pkgs JOIN pkgtups + ON trans_beg.tid=trans_end.tid + AND trans_data_pkgs.tid=trans_beg.tid + AND trans_data_pkgs.pkgtupid=pkgtups.pkgtupid + + WHERE trans_beg.timestamp > ? + ORDER BY pkgtups.name + """ try: packages = PackagesCollection() @@ -139,6 +151,8 @@ def _file_provided_by(self, file): def _database_file(self): """Returns path to yum history database file""" + if self.opts.get('modern_swdb'): + return self.history_path for file in sorted(listdir(self.history_path), reverse=True): if file.startswith("history-") and file.endswith(".sqlite"): return self.history_path + file