Make "absent" runnable with specifying NVR in DNF module. (#53206)

* Make "absent" runnable with specifying NVR in DNF module.

* Fix indent and comment.

* Adjust indent.

* Fix removing multiple packages with NVR.

* Replace nevra_strict with nevra , since it's not included in libdnf on Fedora 28.
This commit is contained in:
Masaki Furuta 2019-03-08 06:48:18 -08:00 committed by ansibot
parent bcb2f59458
commit ba3345b52b

View file

@ -1102,8 +1102,21 @@ class DnfModule(YumDnf):
installed = self.base.sack.query().installed()
for pkg_spec in pkg_specs:
if ("*" in pkg_spec) or installed.filter(name=pkg_spec):
self.base.remove(pkg_spec)
installed_pkg = list(map(str, installed.filter(name=pkg_spec).run()))
if installed_pkg:
candidate_pkg = self._packagename_dict(installed_pkg[0])
installed_pkg = installed.filter(name=candidate_pkg['name']).run()
else:
candidate_pkg = self._packagename_dict(pkg_spec)
installed_pkg = installed.filter(nevra=pkg_spec).run()
if installed_pkg:
installed_pkg = installed_pkg[0]
evr_cmp = self._compare_evr(
installed_pkg.epoch, installed_pkg.version, installed_pkg.release,
candidate_pkg['epoch'], candidate_pkg['version'], candidate_pkg['release'],
)
if evr_cmp == 0:
self.base.remove(pkg_spec)
# Like the dnf CLI we want to allow recursive removal of dependent
# packages