Abstracted parsing yum output

This commit is contained in:
Seth House 2011-12-23 16:06:25 -07:00
parent 0af8e1c183
commit 8e7fd39cea
2 changed files with 33 additions and 0 deletions

View File

@ -44,3 +44,10 @@ class SaltInvocationError(SaltException):
or invalid arguments are specified on the command line
'''
pass
class PkgParseError(SaltException):
'''
Used when of the pkg modules cannot correctly parse the output from the CLI
tool (pacman, yum, apt, aptitude, etc)
'''
pass

View File

@ -1,6 +1,13 @@
'''
Support for YUM
'''
import logging
from collections import namedtuple
from salt.exceptions import PkgParseError
logger = logging.getLogger(__name__)
def __virtual__():
'''
Confine this module to yum based systems
@ -21,6 +28,25 @@ def __virtual__():
return False
def _parse_yum(arg):
'''
A small helper to parse yum output; returns a list of namedtuples
'''
cmd = 'yum -q {0}'.format(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)
return results
def _list_removed(old, new):
'''
List the packages which have been removed between the two package objects