pkg mods: latest_version: (1) always allow refresh arg (2) error on invalid kwargs

This commit is contained in:
Chris Rebert 2013-09-12 18:52:45 -07:00
parent 43d04b40a6
commit bd72e44a2f
13 changed files with 74 additions and 16 deletions

View File

@ -124,13 +124,8 @@ def latest_version(*names, **kwargs):
salt '*' pkg.latest_version <package name> fromrepo=unstable salt '*' pkg.latest_version <package name> fromrepo=unstable
salt '*' pkg.latest_version <package1> <package2> <package3> ... salt '*' pkg.latest_version <package1> <package2> <package3> ...
''' '''
if len(names) == 0: refresh = salt.utils.is_true(kwargs.pop('refresh', True))
return ''
ret = {}
# Initialize the dict with empty strings
for name in names:
ret[name] = ''
pkgs = list_pkgs(versions_as_list=True)
if 'repo' in kwargs: if 'repo' in kwargs:
# Remember to kill _get_repo() too when removing this warning. # Remember to kill _get_repo() too when removing this warning.
salt.utils.warn_until( salt.utils.warn_until(
@ -139,11 +134,24 @@ def latest_version(*names, **kwargs):
'removed in 0.18.0. Please use \'fromrepo\' instead.' 'removed in 0.18.0. Please use \'fromrepo\' instead.'
) )
fromrepo = _get_repo(**kwargs) fromrepo = _get_repo(**kwargs)
kwargs.pop('fromrepo', None)
kwargs.pop('repo', None)
if kwargs:
raise TypeError('Got unexpected keyword argument(s): {0!r}'.format(kwargs))
if len(names) == 0:
return ''
ret = {}
# Initialize the dict with empty strings
for name in names:
ret[name] = ''
pkgs = list_pkgs(versions_as_list=True)
repo = ' -o APT::Default-Release="{0}"'.format(fromrepo) \ repo = ' -o APT::Default-Release="{0}"'.format(fromrepo) \
if fromrepo else '' if fromrepo else ''
# Refresh before looking for the latest version available # Refresh before looking for the latest version available
if salt.utils.is_true(kwargs.get('refresh', True)): if refresh:
refresh_db() refresh_db()
for name in names: for name in names:

View File

@ -120,6 +120,10 @@ def latest_version(*names, **kwargs):
salt '*' pkg.latest_version <package name> salt '*' pkg.latest_version <package name>
salt '*' pkg.latest_version <package1> <package2> <package3> salt '*' pkg.latest_version <package1> <package2> <package3>
''' '''
kwargs.pop('refresh', True)
if kwargs:
raise TypeError('Got unexpected keyword argument(s): {0!r}'.format(kwargs))
if len(names) <= 1: if len(names) <= 1:
return '' return ''
else: else:

View File

@ -170,11 +170,15 @@ def latest_version(*names, **kwargs):
salt '*' pkg.latest_version <package name> salt '*' pkg.latest_version <package name>
salt '*' pkg.latest_version <package1> <package2> <package3> ... salt '*' pkg.latest_version <package1> <package2> <package3> ...
''' '''
refresh = salt.utils.is_true(kwargs.pop('refresh', True))
if kwargs:
raise TypeError('Got unexpected keyword argument(s): {0!r}'.format(kwargs))
if len(names) == 0: if len(names) == 0:
return '' return ''
# Refresh before looking for the latest version available # Refresh before looking for the latest version available
if salt.utils.is_true(kwargs.get('refresh', True)): if refresh:
refresh_db() refresh_db()
ret = {} ret = {}

View File

@ -68,10 +68,14 @@ def latest_version(*names, **kwargs):
salt '*' pkg.latest_version <package1> <package2> <package3> ... salt '*' pkg.latest_version <package1> <package2> <package3> ...
''' '''
refresh = salt.utils.is_true(kwargs.pop('refresh', True))
if kwargs:
raise TypeError('Got unexpected keyword argument(s): {0!r}'.format(kwargs))
ret = {} ret = {}
# Refresh before looking for the latest version available # Refresh before looking for the latest version available
if salt.utils.is_true(kwargs.get('refresh', True)): if refresh:
refresh_db() refresh_db()
if _check_pkgng(): if _check_pkgng():

View File

@ -80,6 +80,10 @@ def latest_version(*names, **kwargs):
salt '*' pkg.latest_version <package name> salt '*' pkg.latest_version <package name>
''' '''
kwargs.pop('refresh', True)
if kwargs:
raise TypeError('Got unexpected keyword argument(s): {0!r}'.format(kwargs))
pkgs = list_pkgs() pkgs = list_pkgs()
ret = {} ret = {}
# Initialize the dict with empty strings # Initialize the dict with empty strings

View File

@ -44,11 +44,15 @@ def latest_version(*names, **kwargs):
salt '*' pkg.latest_version <package name> salt '*' pkg.latest_version <package name>
salt '*' pkg.latest_version <package1> <package2> <package3> ... salt '*' pkg.latest_version <package1> <package2> <package3> ...
''' '''
refresh = salt.utils.is_true(kwargs.pop('refresh', True))
if kwargs:
raise TypeError('Got unexpected keyword argument(s): {0!r}'.format(kwargs))
if len(names) == 0: if len(names) == 0:
return '' return ''
# Refresh before looking for the latest version available # Refresh before looking for the latest version available
if salt.utils.is_true(kwargs.get('refresh', True)): if refresh:
refresh_db() refresh_db()
ret = {} ret = {}

View File

@ -112,13 +112,17 @@ def latest_version(*names, **kwargs):
salt '*' pkg.latest_version <package1> <package2> ... salt '*' pkg.latest_version <package1> <package2> ...
''' '''
refresh = salt.utils.is_true(kwargs.pop('refresh', True))
if kwargs:
raise TypeError('Got unexpected keyword argument(s): {0!r}'.format(kwargs))
pkglist = {} pkglist = {}
pkgin = _check_pkgin() pkgin = _check_pkgin()
if not pkgin: if not pkgin:
return pkglist return pkglist
# Refresh before looking for the latest version available # Refresh before looking for the latest version available
if salt.utils.is_true(kwargs.get('refresh', True)): if refresh:
refresh_db() refresh_db()
for name in names: for name in names:

View File

@ -72,6 +72,10 @@ def latest_version(pkg_name, **kwargs):
salt '*' pkgng.latest_version <package name> salt '*' pkgng.latest_version <package name>
''' '''
kwargs.pop('refresh', True)
if kwargs:
raise TypeError('Got unexpected keyword argument(s): {0!r}'.format(kwargs))
cmd = 'pkg info {0}'.format(pkg_name) cmd = 'pkg info {0}'.format(pkg_name)
out = __salt__['cmd.run'](cmd).split() out = __salt__['cmd.run'](cmd).split()
return out[0] return out[0]

View File

@ -185,6 +185,10 @@ def latest_version(*names, **kwargs):
salt '*' pkgutil.latest_version CSWpython salt '*' pkgutil.latest_version CSWpython
salt '*' pkgutil.latest_version <package1> <package2> <package3> ... salt '*' pkgutil.latest_version <package1> <package2> <package3> ...
''' '''
refresh = salt.utils.is_true(kwargs.pop('refresh', True))
if kwargs:
raise TypeError('Got unexpected keyword argument(s): {0!r}'.format(kwargs))
if not names: if not names:
return '' return ''
ret = {} ret = {}
@ -193,7 +197,7 @@ def latest_version(*names, **kwargs):
ret[name] = '' ret[name] = ''
# Refresh before looking for the latest version available # Refresh before looking for the latest version available
if salt.utils.is_true(kwargs.get('refresh', True)): if refresh:
refresh_db() refresh_db()
pkgs = list_pkgs() pkgs = list_pkgs()

View File

@ -127,6 +127,10 @@ def latest_version(*names, **kwargs):
pkgadd, this function will always return an empty string for a given pkgadd, this function will always return an empty string for a given
package. package.
''' '''
kwargs.pop('refresh', True)
if kwargs:
raise TypeError('Got unexpected keyword argument(s): {0!r}'.format(kwargs))
ret = {} ret = {}
if not names: if not names:
return '' return ''

View File

@ -213,6 +213,11 @@ def latest_version(*names, **kwargs):
salt '*' pkg.latest_version <package name> fromrepo=epel-testing salt '*' pkg.latest_version <package name> fromrepo=epel-testing
salt '*' pkg.latest_version <package1> <package2> <package3> ... salt '*' pkg.latest_version <package1> <package2> <package3> ...
''' '''
refresh = salt.utils.is_true(kwargs.pop('refresh', True))
# FIXME: do stricter argument checking that somehow takes _get_repo_options() into account
# if kwargs:
# raise TypeError('Got unexpected keyword argument(s): {0!r}'.format(kwargs))
if len(names) == 0: if len(names) == 0:
return '' return ''
ret = {} ret = {}
@ -221,7 +226,7 @@ def latest_version(*names, **kwargs):
ret[name] = '' ret[name] = ''
# Refresh before looking for the latest version available # Refresh before looking for the latest version available
if salt.utils.is_true(kwargs.get('refresh', True)): if refresh:
refresh_db() refresh_db()
yumbase = yum.YumBase() yumbase = yum.YumBase()

View File

@ -157,6 +157,11 @@ def latest_version(*names, **kwargs):
salt '*' pkg.latest_version <package name> fromrepo=epel-testing salt '*' pkg.latest_version <package name> fromrepo=epel-testing
salt '*' pkg.latest_version <package1> <package2> <package3> ... salt '*' pkg.latest_version <package1> <package2> <package3> ...
''' '''
refresh = salt.utils.is_true(kwargs.pop('refresh', True))
# FIXME: do stricter argument checking that somehow takes _get_repo_options() into account
# if kwargs:
# raise TypeError('Got unexpected keyword argument(s): {0!r}'.format(kwargs))
if len(names) == 0: if len(names) == 0:
return '' return ''
ret = {} ret = {}
@ -165,7 +170,7 @@ def latest_version(*names, **kwargs):
ret[name] = '' ret[name] = ''
# Refresh before looking for the latest version available # Refresh before looking for the latest version available
if salt.utils.is_true(kwargs.get('refresh', True)): if refresh:
refresh_db() refresh_db()
# Get updates for specified package(s) # Get updates for specified package(s)

View File

@ -69,6 +69,10 @@ def latest_version(*names, **kwargs):
salt '*' pkg.latest_version <package name> salt '*' pkg.latest_version <package name>
salt '*' pkg.latest_version <package1> <package2> <package3> ... salt '*' pkg.latest_version <package1> <package2> <package3> ...
''' '''
refresh = salt.utils.is_true(kwargs.pop('refresh', True))
if kwargs:
raise TypeError('Got unexpected keyword argument(s): {0!r}'.format(kwargs))
if len(names) == 0: if len(names) == 0:
return '' return ''
@ -77,7 +81,7 @@ def latest_version(*names, **kwargs):
ret[name] = '' ret[name] = ''
# Refresh before looking for the latest version available # Refresh before looking for the latest version available
if salt.utils.is_true(kwargs.get('refresh', True)): if refresh:
refresh_db() refresh_db()
cmd = 'zypper info -t package {0}'.format(' '.join(names)) cmd = 'zypper info -t package {0}'.format(' '.join(names))