Add support for state=latest and *
This commit is contained in:
parent
050e619e7b
commit
495af842fc
1 changed files with 37 additions and 17 deletions
|
@ -177,9 +177,18 @@ def list_stuff(module, conf_file, stuff):
|
||||||
else:
|
else:
|
||||||
return [pkg_to_dict(p) for p in dnf.subject.Subject(stuff).get_best_query(my.sack)]
|
return [pkg_to_dict(p) for p in dnf.subject.Subject(stuff).get_best_query(my.sack)]
|
||||||
|
|
||||||
|
|
||||||
|
def _mark_package_install(my, res, pkg_spec):
|
||||||
|
"""Mark the package for install."""
|
||||||
|
try:
|
||||||
|
my.install(pkg_spec)
|
||||||
|
except dnf.exceptions.MarkingError:
|
||||||
|
res['results'].append('No package %s available.' % pkg_spec)
|
||||||
|
res['rc'] = 1
|
||||||
|
|
||||||
|
|
||||||
def ensure(module, state, pkgspec, conf_file, enablerepo, disablerepo, disable_gpg_check):
|
def ensure(module, state, pkgspec, conf_file, enablerepo, disablerepo, disable_gpg_check):
|
||||||
my = dnf_base(conf_file)
|
my = dnf_base(conf_file)
|
||||||
items = pkgspec.split(',')
|
|
||||||
if disablerepo:
|
if disablerepo:
|
||||||
for repo in disablerepo.split(','):
|
for repo in disablerepo.split(','):
|
||||||
[r.disable() for r in my.repos.get_matching(repo)]
|
[r.disable() for r in my.repos.get_matching(repo)]
|
||||||
|
@ -199,22 +208,33 @@ def ensure(module, state, pkgspec, conf_file, enablerepo, disablerepo, disable_g
|
||||||
res['msg'] = 'This command has to be run under the root user.'
|
res['msg'] = 'This command has to be run under the root user.'
|
||||||
res['rc'] = 1
|
res['rc'] = 1
|
||||||
|
|
||||||
pkg_specs, grp_specs, filenames = dnf.cli.commands.parse_spec_group_file(items)
|
if pkgspec == '*' and state == 'latest':
|
||||||
if state in ['installed', 'present']:
|
my.upgrade_all()
|
||||||
# Install files.
|
else:
|
||||||
local_pkgs = map(my.add_remote_rpm, filenames)
|
items = pkgspec.split(',')
|
||||||
map(my.package_install, local_pkgs)
|
pkg_specs, grp_specs, filenames = dnf.cli.commands.parse_spec_group_file(items)
|
||||||
# Install groups.
|
if state in ['installed', 'present']:
|
||||||
if grp_specs:
|
# Install files.
|
||||||
my.read_comps()
|
for filename in filenames:
|
||||||
my.env_group_install(grp_specs, dnf.const.GROUP_PACKAGE_TYPES)
|
my.package_install(my.add_remote_rpm(filename))
|
||||||
# Install packages.
|
# Install groups.
|
||||||
for pkg_spec in pkg_specs:
|
if grp_specs:
|
||||||
try:
|
my.read_comps()
|
||||||
my.install(pkg_spec)
|
my.env_group_install(grp_specs, dnf.const.GROUP_PACKAGE_TYPES)
|
||||||
except dnf.exceptions.MarkingError:
|
# Install packages.
|
||||||
res['results'].append('No package %s available.' % pkg_spec)
|
for pkg_spec in pkg_specs:
|
||||||
res['rc'] = 1
|
_mark_package_install(my, res, pkg_spec)
|
||||||
|
elif state == 'latest':
|
||||||
|
# These aren't implemented yet, so assert them out.
|
||||||
|
assert not filenames
|
||||||
|
assert not grp_specs
|
||||||
|
for pkg_spec in pkg_specs:
|
||||||
|
try:
|
||||||
|
my.upgrade(pkg_spec)
|
||||||
|
except dnf.exceptions.MarkingError:
|
||||||
|
# If not already installed, try to install.
|
||||||
|
_mark_package_install(my, res, pkg_spec)
|
||||||
|
|
||||||
if not my.resolve() and res['rc'] == 0:
|
if not my.resolve() and res['rc'] == 0:
|
||||||
res['msg'] += 'Nothing to do'
|
res['msg'] += 'Nothing to do'
|
||||||
res['changed'] = False
|
res['changed'] = False
|
||||||
|
|
Loading…
Reference in a new issue