mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
Abstracted parsing yum output
This commit is contained in:
parent
0af8e1c183
commit
8e7fd39cea
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user