Merge branch 'develop' of github.com:saltstack/salt into develop

This commit is contained in:
Thomas S Hatch 2012-01-05 17:27:15 -07:00
commit 6563bd18a1
2 changed files with 33 additions and 21 deletions

View File

@ -36,13 +36,14 @@ def _parse_yum(arg):
out = __salt__['cmd.run_stdout'](cmd)
YumOut = namedtuple('YumOut', ('name', 'version', 'status'))
try:
results = map(YumOut._make,
[i.split() for i in out.split('\n') if len(i.split()) == 3])
except TypeError as exc:
results = ()
msg = "Could not parse yum output for: {0}".format(cmd)
logger.debug(msg, exc_info=exc)
results = []
for line in out.split('\n'):
if len(line.split()) == 3:
namearchstr, pkgver, pkgstatus = line.split()
pkgname = namearchstr.rpartition('.')[0]
results.append(YumOut(pkgname, pkgver, pkgstatus))
return results

View File

@ -11,8 +11,11 @@ declarations are typically rather simple:
pkg:
- installed
'''
import logging
from distutils.version import LooseVersion
logger = logging.getLogger(__name__)
def installed(name):
'''
Verify that the package is installed, and only that it is installed. This
@ -50,20 +53,28 @@ def latest(name):
name
The name of the package to maintain at the latest available version
'''
changes = {}
version = LooseVersion(__salt__['pkg.version'](name))
avail = LooseVersion(__salt__['pkg.available_version'](name))
if avail > version:
changes = __salt__['pkg.install'](name, True)
if not changes:
return {'name': name,
'changes': changes,
'result': False,
'comment': 'Package ' + name + ' failed to install'}
return {'name': name,
'changes': changes,
'result': True,
'comment': 'Package ' + name + ' installed'}
ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
version = __salt__['pkg.version'](name)
avail = __salt__['pkg.available_version'](name)
try:
has_newer = LooseVersion(avail) > LooseVersion(version)
except AttributeError:
logger.debug("Error comparing versions for '%s' (%s > %s)",
name, avail, version, exc_info=True)
ret['comment'] = "No version could be retrieved for '{0}'".format(name)
return ret
if has_newer:
ret['changes'] = __salt__['pkg.install'](name, True)
ret['comment'] = 'Package {0} failed to install'.format(name)
ret['result'] = True
ret['comment'] = 'Package {0} installed'.format(name)
return ret
def removed(name):