mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Add multiple pkg support to pkg.latest (pacman)
Also tweaked the changes made to the pkg state in 306cc74
, and fixed a
logic bug I introduced into apt.py in the same commit.
This commit is contained in:
parent
c48a27aa5c
commit
e47bdaae4c
@ -56,7 +56,7 @@ def _pkgname_without_arch(name):
|
||||
def available_version(*names):
|
||||
'''
|
||||
Return the latest version of the named package available for upgrade or
|
||||
installation via the available apt repository
|
||||
installation
|
||||
|
||||
CLI Example::
|
||||
|
||||
@ -76,7 +76,7 @@ def available_version(*names):
|
||||
version = ''
|
||||
ret[name] = version
|
||||
# Return a string if only one package name passed
|
||||
if len(ret) == 1:
|
||||
if len(names) == 1:
|
||||
return ret[names[0]]
|
||||
return ret
|
||||
|
||||
|
@ -27,15 +27,27 @@ def _list_removed(old, new):
|
||||
return pkgs
|
||||
|
||||
|
||||
def available_version(name):
|
||||
def available_version(*names):
|
||||
'''
|
||||
The available version of the package in the repository
|
||||
Return the latest version of the named package available for upgrade or
|
||||
installation
|
||||
|
||||
CLI Example::
|
||||
|
||||
salt '*' pkg.available_version <package name>
|
||||
salt '*' pkg.available_version <package1> <package2> <package3>
|
||||
'''
|
||||
return __salt__['cmd.run']('pacman -Sp --print-format %v {0}'.format(name))
|
||||
if len(names) == 0:
|
||||
return ''
|
||||
else:
|
||||
ret = {}
|
||||
for name in names:
|
||||
cmd = 'pacman -Sp --print-format "%v" {0}'.format(name)
|
||||
ret[name] = __salt__['cmd.run_stdout'](cmd).strip()
|
||||
# Return a string if only one package name passed
|
||||
if len(names) == 1:
|
||||
return ret[names[0]]
|
||||
return ret
|
||||
|
||||
|
||||
def upgrade_available(name):
|
||||
@ -70,19 +82,27 @@ def list_upgrades():
|
||||
return upgrades
|
||||
|
||||
|
||||
def version(name):
|
||||
def version(*names):
|
||||
'''
|
||||
Returns a version if the package is installed, else returns an empty string
|
||||
Returns a string representing the package version or an empty string if not
|
||||
installed. If more than one package name is specified, a dict of
|
||||
name/version pairs is returned.
|
||||
|
||||
CLI Example::
|
||||
|
||||
salt '*' pkg.version <package name>
|
||||
salt '*' pkg.version <package1> <package2> <package3>
|
||||
'''
|
||||
pkgs = list_pkgs()
|
||||
if name in pkgs:
|
||||
return pkgs[name]
|
||||
else:
|
||||
if len(names) == 0:
|
||||
return ''
|
||||
elif len(names) == 1:
|
||||
return pkgs.get(names[0], '')
|
||||
else:
|
||||
ret = {}
|
||||
for name in names:
|
||||
ret[name] = pkgs.get(name, '')
|
||||
return ret
|
||||
|
||||
|
||||
def list_pkgs():
|
||||
|
@ -325,13 +325,28 @@ def latest(
|
||||
'comment': ' '.join(problems)}
|
||||
|
||||
if targets:
|
||||
# Find up-to-date packages
|
||||
if not pkgs:
|
||||
# There couldn't have been any up-to-date packages if this state
|
||||
# only targeted a single package and is being allowed to proceed to
|
||||
# the install step.
|
||||
up_to_date = []
|
||||
else:
|
||||
up_to_date = [x for x in pkgs if x not in targets]
|
||||
|
||||
if __opts__['test']:
|
||||
to_be_upgraded = ', '.join(sorted(targets.keys()))
|
||||
comment = 'The following packages are set to be upgraded: ' \
|
||||
'{0}.'.format(to_be_upgraded)
|
||||
if up_to_date:
|
||||
comment += ' The following packages are already ' \
|
||||
'up-to-date: ' \
|
||||
'{0}.'.format(', '.join(sorted(up_to_date)))
|
||||
|
||||
return {'name': name,
|
||||
'changes': {},
|
||||
'result': None,
|
||||
'comment': 'The following packages are set to be '
|
||||
'upgraded: {0}'.format(to_be_upgraded)}
|
||||
'comment': comment}
|
||||
|
||||
# Build updated list of pkgs to exclude non-targeted ones
|
||||
targeted_pkgs = targets.keys() if pkgs else None
|
||||
@ -353,15 +368,6 @@ def latest(
|
||||
pkgs=targeted_pkgs,
|
||||
**kwargs)
|
||||
|
||||
# Find up-to-date packages
|
||||
if not pkgs:
|
||||
# There couldn't have been any up-to-date packages if this
|
||||
# state only targeted a single package and was allowed to
|
||||
# proceed to the install step.
|
||||
up_to_date = []
|
||||
else:
|
||||
up_to_date = [x for x in pkgs if x not in targets]
|
||||
|
||||
if changes:
|
||||
# Find failed and successful updates
|
||||
failed = [x for x in targets if changes[x]['new'] != targets[x]]
|
||||
@ -369,15 +375,15 @@ def latest(
|
||||
|
||||
comments = []
|
||||
if failed:
|
||||
msg = 'The following package(s) failed to update: ' \
|
||||
msg = 'The following packages failed to update: ' \
|
||||
'{0}.'.format(', '.join(sorted(failed)))
|
||||
comments.append(msg)
|
||||
if successful:
|
||||
msg = 'The following package(s) were successfully updated: ' \
|
||||
msg = 'The following packages were successfully updated: ' \
|
||||
'{0}.'.format(', '.join(sorted(successful)))
|
||||
comments.append(msg)
|
||||
if up_to_date:
|
||||
msg = 'The following package(s) were already up-to-date: ' \
|
||||
msg = 'The following packages were already up-to-date: ' \
|
||||
'{0}.'.format(', '.join(sorted(up_to_date)))
|
||||
comments.append(msg)
|
||||
|
||||
@ -388,12 +394,12 @@ def latest(
|
||||
else:
|
||||
if len(targets) > 1:
|
||||
comment = 'All targeted packages failed to update: ' \
|
||||
'{0}'.format(', '.join(sorted(targets.keys())))
|
||||
'({0}).'.format(', '.join(sorted(targets.keys())))
|
||||
else:
|
||||
comment = 'Package {0} failed to ' \
|
||||
'update'.format(targets.keys()[0])
|
||||
'update.'.format(targets.keys()[0])
|
||||
if up_to_date:
|
||||
comment += '. The following package(s) were already ' \
|
||||
comment += ' The following packages were already ' \
|
||||
'up-to-date: ' \
|
||||
'{0}'.format(', '.join(sorted(up_to_date)))
|
||||
return {'name': name,
|
||||
|
Loading…
Reference in New Issue
Block a user