Add support for state=latest and *

reviewable/pr18780/r1
ToBeReplaced 10 years ago committed by Igor Gnatenko
parent 050e619e7b
commit 495af842fc

@ -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
if pkgspec == '*' and state == 'latest':
my.upgrade_all()
else:
items = pkgspec.split(',')
pkg_specs, grp_specs, filenames = dnf.cli.commands.parse_spec_group_file(items) pkg_specs, grp_specs, filenames = dnf.cli.commands.parse_spec_group_file(items)
if state in ['installed', 'present']: if state in ['installed', 'present']:
# Install files. # Install files.
local_pkgs = map(my.add_remote_rpm, filenames) for filename in filenames:
map(my.package_install, local_pkgs) my.package_install(my.add_remote_rpm(filename))
# Install groups. # Install groups.
if grp_specs: if grp_specs:
my.read_comps() my.read_comps()
my.env_group_install(grp_specs, dnf.const.GROUP_PACKAGE_TYPES) my.env_group_install(grp_specs, dnf.const.GROUP_PACKAGE_TYPES)
# Install packages. # Install packages.
for pkg_spec in pkg_specs:
_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: for pkg_spec in pkg_specs:
try: try:
my.install(pkg_spec) my.upgrade(pkg_spec)
except dnf.exceptions.MarkingError: except dnf.exceptions.MarkingError:
res['results'].append('No package %s available.' % pkg_spec) # If not already installed, try to install.
res['rc'] = 1 _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…
Cancel
Save