Skip to content

Commit

Permalink
Merge pull request #117 from elyscape/support-new-dnf
Browse files Browse the repository at this point in the history
Support current versions of DNF
  • Loading branch information
FrostyX authored Dec 5, 2018
2 parents c3593b9 + a57fa91 commit 1932c5f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
11 changes: 10 additions & 1 deletion tracer/packageManagers/dnf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from __future__ import absolute_import

import os.path

from tracer.resources.system import System
if System.distribution() in ["fedora", "mageia"]:
Expand All @@ -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):
Expand Down
36 changes: 25 additions & 11 deletions tracer/packageManagers/rpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1932c5f

Please sign in to comment.