Skip to content

Commit 3b59592

Browse files
committed
better search/download of rpms
Search only for installed packages, but download only available. If the package is not available (anymore?) in repos, try to diff with cached rpm file (can be downloaded manually by end-user).
1 parent effc2e6 commit 3b59592

2 files changed

Lines changed: 27 additions & 6 deletions

File tree

dnf-plugins/diff.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,11 @@ def configure(self):
4646
)
4747

4848
def _resolve_local_package(self, name):
49-
self.base.fill_sack()
5049
subj = dnf.subject.Subject(name)
5150
q = subj.get_best_query(self.base.sack)
52-
q = q.available()
53-
q = q.latest()
51+
q = q.installed()
5452
if len(q.run()) == 0:
55-
msg = _("No package %s available.") % (name)
53+
msg = _("No package %s is installed.") % (name)
5654
raise dnf.exceptions.PackageNotFoundError(msg)
5755

5856
return list(q)
@@ -77,6 +75,7 @@ def _diff_package(self, package, package_name, files):
7775
rpm_file_name,
7876
fname])
7977

78+
8079
def _list_of_changed_files(self, package):
8180
proc = subprocess.Popen(
8281
['/usr/libexec/dnf-diff-changed-files', package],
@@ -85,9 +84,31 @@ def _list_of_changed_files(self, package):
8584
lines = [x.decode('ascii').rstrip() for x in proc.stdout.readlines()]
8685
return lines
8786

87+
88+
def _download_packages(self, to_download):
89+
pkg_list = []
90+
for pkg in to_download:
91+
pkg_spec = '{name}-{evr}.{arch}'.format(
92+
name=pkg.name,
93+
evr=pkg.evr,
94+
arch=pkg.arch,
95+
)
96+
subj = dnf.subject.Subject(pkg_spec)
97+
98+
q = subj.get_best_query(self.base.sack).available().latest()
99+
if not list(q):
100+
logger.warning(_("package {0} not available in repos, trying local cache".format(pkg_spec)))
101+
else:
102+
pkg_list.extend(list(q))
103+
104+
self.base.download_packages(pkg_list)
105+
106+
88107
def run(self):
108+
self.base.fill_sack()
109+
89110
to_download = self._resolve_local_package(self.opts.pkg)
90-
self.base.download_packages(to_download)
111+
self._download_packages(to_download)
91112

92113
for pkg in to_download:
93114
check_pkg = '{0}.{1}'.format(pkg.name, pkg.arch)

rpm/dnf-plugin-diff.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Name: dnf-plugin-diff
44
Version: 0.0
5-
Release: 1%{?dist}
5+
Release: 2%{?dist}
66
Summary: Diff changes in packages
77
BuildArch: noarch
88

0 commit comments

Comments
 (0)