1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

dnf: fix compatibility with DNF 2.0 (#3325)

* dnf: fix compatibility with DNF 2.0

* Reimplement (copy) old dnf.cli.commands.parse_spec_group_file(),
  upstream uses argparse since 2.0.
* add_remote_rpm() has been changed to the add_remote_rpms()

Closes: https://github.com/ansible/ansible-modules-extras/issues/3310
Signed-off-by: Igor Gnatenko <ignatenko@redhat.com>

* fixup! dnf: fix compatibility with DNF 2.0
This commit is contained in:
Igor Gnatenko 2016-10-31 17:24:26 +01:00 committed by Matt Clay
parent 5cb9bbbd18
commit 16896194a8

View file

@ -265,13 +265,35 @@ def _mark_package_install(module, base, pkg_spec):
module.fail_json(msg="No package {} available.".format(pkg_spec)) module.fail_json(msg="No package {} available.".format(pkg_spec))
def _parse_spec_group_file(names):
pkg_specs, grp_specs, filenames = [], [], []
for name in names:
if name.endswith(".rpm"):
filenames.append(name)
elif name.startswith("@"):
grp_specs.append(name[1:])
else:
pkg_specs.append(name)
return pkg_specs, grp_specs, filenames
def _install_remote_rpms(base, filenames):
if int(dnf.__version__.split(".")[0]) >= 2:
pkgs = list(sorted(base.add_remote_rpms(list(filenames)), reverse=True))
else:
pkgs = []
for filename in filenames:
pkgs.append(base.add_remote_rpm(filename))
for pkg in pkgs:
base.package_install(pkg)
def ensure(module, base, state, names): def ensure(module, base, state, names):
allow_erasing = False allow_erasing = False
if names == ['*'] and state == 'latest': if names == ['*'] and state == 'latest':
base.upgrade_all() base.upgrade_all()
else: else:
pkg_specs, group_specs, filenames = dnf.cli.commands.parse_spec_group_file( pkg_specs, group_specs, filenames = _parse_spec_group_file(names)
names)
if group_specs: if group_specs:
base.read_comps() base.read_comps()
@ -286,8 +308,7 @@ def ensure(module, base, state, names):
if state in ['installed', 'present']: if state in ['installed', 'present']:
# Install files. # Install files.
for filename in (f.strip() for f in filenames): _install_remote_rpms(base, (f.strip() for f in filenames))
base.package_install(base.add_remote_rpm(filename))
# Install groups. # Install groups.
for group in (g.strip() for g in groups): for group in (g.strip() for g in groups):
base.group_install(group, dnf.const.GROUP_PACKAGE_TYPES) base.group_install(group, dnf.const.GROUP_PACKAGE_TYPES)
@ -297,8 +318,7 @@ def ensure(module, base, state, names):
elif state == 'latest': elif state == 'latest':
# "latest" is same as "installed" for filenames. # "latest" is same as "installed" for filenames.
for filename in filenames: _install_remote_rpms(base, filenames)
base.package_install(base.add_remote_rpm(filename))
for group in groups: for group in groups:
try: try:
base.group_upgrade(group) base.group_upgrade(group)