From 595872434205a4ec652edf0ff97fe4d154d9ad56 Mon Sep 17 00:00:00 2001 From: Denis Generalov Date: Sat, 26 Jan 2013 04:24:30 +0400 Subject: [PATCH 1/3] keep up with pkg.latest state --- salt/modules/freebsdpkg.py | 49 ++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/salt/modules/freebsdpkg.py b/salt/modules/freebsdpkg.py index 3cce87ec99..c72c5af8c1 100644 --- a/salt/modules/freebsdpkg.py +++ b/salt/modules/freebsdpkg.py @@ -48,7 +48,7 @@ def search(pkg_name): return {"Results": res} -def available_version(name): +def available_version(*names): ''' The available version of the package in the repository @@ -56,14 +56,49 @@ def available_version(name): salt '*' pkg.available_version ''' + + 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): From 527bb79c7dbec93001de51c93dbf9fa40bf6757a Mon Sep 17 00:00:00 2001 From: Denis Generalov Date: Sat, 26 Jan 2013 18:03:39 +0400 Subject: [PATCH 2/3] update docstring for available_version() --- salt/modules/freebsdpkg.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/salt/modules/freebsdpkg.py b/salt/modules/freebsdpkg.py index c72c5af8c1..5a0611c469 100644 --- a/salt/modules/freebsdpkg.py +++ b/salt/modules/freebsdpkg.py @@ -50,11 +50,17 @@ def search(pkg_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 + salt '*' pkg.available_version ... ''' ret = {} From 959ddfb5cbfb8a5f40173d914ebd91d2bedffb15 Mon Sep 17 00:00:00 2001 From: Denis Generalov Date: Sat, 26 Jan 2013 18:04:44 +0400 Subject: [PATCH 3/3] fix version type --- salt/states/pkg.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/salt/states/pkg.py b/salt/states/pkg.py index 62ddef1d88..6d5f738234 100644 --- a/salt/states/pkg.py +++ b/salt/states/pkg.py @@ -139,6 +139,8 @@ def installed( else: targets = [name] + if version: + version = str(version) cver = old_pkgs.get(name, '') if cver == version: