Merge pull request #3467 from giantlock/develop

fix some issues with pkg
This commit is contained in:
Thomas S Hatch 2013-01-27 10:00:14 -08:00
commit b93a536785
2 changed files with 51 additions and 8 deletions

View File

@ -48,22 +48,63 @@ def search(pkg_name):
return {"Results": res} return {"Results": res}
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. If more than one package name is specified, a dict of
name/version pairs is returned.
If the latest version of a given package is already installed, an empty
string will be returned for that package.
CLI Example:: CLI Example::
salt '*' pkg.available_version <package name> salt '*' pkg.available_version <package name>
salt '*' pkg.available_version <package1> <package2> <package3> ...
''' '''
ret = {}
if _check_pkgng(): if _check_pkgng():
for line in __salt__['cmd.run']('{0} search -f {1}'.format( for line in __salt__['cmd.run_stdout']('{0} upgrade -nq'.format(
_cmd('pkg'), name) _cmd('pkg'))
).splitlines():
if not line.startswith('\t'):
continue
line = line.strip()
if line.startswith('Installing'):
_, pkg, ver = line.split()
pkg = pkg.rstrip(':')
elif line.startswith('Upgrading'):
_, pkg, _, _, ver = line.split()
pkg = pkg.rstrip(':')
elif line.startswith('Reinstalling'):
_, pkgver = line.split()
comps = pkgver.split('-')
pkg = ''.join(comps[:-1])
ver = comps[-1]
else:
# unexpected string
continue
if pkg in names:
ret[pkg] = ver
# keep pkg.latest culm
for pkg in set(names) - set(ret) - set(list_pkgs()):
for line in __salt__['cmd.run']('{0} search -fe {1}'.format(
_cmd('pkg'), pkg)
).splitlines(): ).splitlines():
if line.startswith('Version'): if line.startswith('Version'):
_, ver = line.split(':', 1) _, _, ver = line.split()[:3]
return ver.strip() ret[pkg] = ver
return '' break
ret.update(dict.fromkeys(set(names) - set(ret), ''))
if len(names) == 1:
return ret.values()[0]
return ret
def version(name): def version(name):

View File

@ -139,6 +139,8 @@ def installed(
else: else:
targets = [name] targets = [name]
if version:
version = str(version)
cver = old_pkgs.get(name, '') cver = old_pkgs.get(name, '')
if cver == version: if cver == version: