mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Merge pull request #3467 from giantlock/develop
fix some issues with pkg
This commit is contained in:
commit
b93a536785
@ -48,22 +48,63 @@ def search(pkg_name):
|
||||
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::
|
||||
|
||||
salt '*' pkg.available_version <package name>
|
||||
salt '*' pkg.available_version <package1> <package2> <package3> ...
|
||||
'''
|
||||
|
||||
ret = {}
|
||||
|
||||
if _check_pkgng():
|
||||
for line in __salt__['cmd.run']('{0} search -f {1}'.format(
|
||||
_cmd('pkg'), name)
|
||||
for line in __salt__['cmd.run_stdout']('{0} upgrade -nq'.format(
|
||||
_cmd('pkg'))
|
||||
).splitlines():
|
||||
if line.startswith('Version'):
|
||||
_, ver = line.split(':', 1)
|
||||
return ver.strip()
|
||||
return ''
|
||||
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():
|
||||
if line.startswith('Version'):
|
||||
_, _, ver = line.split()[:3]
|
||||
ret[pkg] = ver
|
||||
break
|
||||
|
||||
ret.update(dict.fromkeys(set(names) - set(ret), ''))
|
||||
|
||||
if len(names) == 1:
|
||||
return ret.values()[0]
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
def version(name):
|
||||
|
@ -139,6 +139,8 @@ def installed(
|
||||
|
||||
else:
|
||||
targets = [name]
|
||||
if version:
|
||||
version = str(version)
|
||||
|
||||
cver = old_pkgs.get(name, '')
|
||||
if cver == version:
|
||||
|
Loading…
Reference in New Issue
Block a user