mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
Set loglevel for cmds with a lot of output to TRACE
This commit also fixes the recently-added function pkg.owner. It did not successfully handle file paths containing spaces, and it did not conform to the way Salt handles other package information queries (i.e. version(), latest_version(), etc.)
This commit is contained in:
parent
cf5a2efbf0
commit
8fa1f642da
@ -67,7 +67,7 @@ def latest_version(*names, **kwargs):
|
||||
ret[name] = ''
|
||||
cmd = 'pacman -Sp --needed --print-format "%n %v" ' \
|
||||
'{0}'.format(' '.join(names))
|
||||
out = __salt__['cmd.run_stdout'](cmd, output_loglevel='debug')
|
||||
out = __salt__['cmd.run_stdout'](cmd, output_loglevel='trace')
|
||||
for line in out.splitlines():
|
||||
try:
|
||||
name, version_num = line.split()
|
||||
@ -130,10 +130,7 @@ def list_upgrades(refresh=False):
|
||||
r'"^\s|^:"'
|
||||
).format(' '.join(options))
|
||||
|
||||
out = __salt__['cmd.run'](
|
||||
cmd,
|
||||
output_loglevel='debug'
|
||||
)
|
||||
out = __salt__['cmd.run'](cmd, output_loglevel='trace')
|
||||
for line in out.splitlines():
|
||||
comps = line.split(' ')
|
||||
if len(comps) < 2:
|
||||
@ -186,7 +183,7 @@ def list_pkgs(versions_as_list=False, **kwargs):
|
||||
|
||||
cmd = 'pacman -Q'
|
||||
ret = {}
|
||||
out = __salt__['cmd.run'](cmd, output_loglevel='debug')
|
||||
out = __salt__['cmd.run'](cmd, output_loglevel='trace')
|
||||
for line in out.splitlines():
|
||||
if not line:
|
||||
continue
|
||||
@ -219,7 +216,7 @@ def refresh_db():
|
||||
'''
|
||||
cmd = 'LANG=C pacman -Sy'
|
||||
ret = {}
|
||||
out = __salt__['cmd.run'](cmd, output_loglevel='debug')
|
||||
out = __salt__['cmd.run'](cmd, output_loglevel='trace')
|
||||
for line in out.splitlines():
|
||||
if line.strip().startswith('::'):
|
||||
continue
|
||||
@ -356,7 +353,7 @@ def install(name=None,
|
||||
cmd = 'pacman -S "{0}"'.format('" "'.join(options+targets))
|
||||
|
||||
old = list_pkgs()
|
||||
__salt__['cmd.run'](cmd, output_loglevel='debug')
|
||||
__salt__['cmd.run'](cmd, output_loglevel='trace')
|
||||
__context__.pop('pkg.list_pkgs', None)
|
||||
new = list_pkgs()
|
||||
return salt.utils.compare_dicts(old, new)
|
||||
@ -384,7 +381,7 @@ def upgrade(refresh=False):
|
||||
cmd = 'pacman -Su --noprogressbar --noconfirm'
|
||||
if salt.utils.is_true(refresh):
|
||||
cmd += ' -y'
|
||||
__salt__['cmd.run'](cmd, output_loglevel='debug')
|
||||
__salt__['cmd.run'](cmd, output_loglevel='trace')
|
||||
__context__.pop('pkg.list_pkgs', None)
|
||||
new = list_pkgs()
|
||||
return salt.utils.compare_dicts(old, new)
|
||||
@ -410,7 +407,7 @@ def _uninstall(action='remove', name=None, pkgs=None, **kwargs):
|
||||
'--noprogressbar '
|
||||
'--noconfirm {1}'
|
||||
).format(remove_arg, ' '.join(targets))
|
||||
__salt__['cmd.run'](cmd, output_loglevel='debug')
|
||||
__salt__['cmd.run'](cmd, output_loglevel='trace')
|
||||
__context__.pop('pkg.list_pkgs', None)
|
||||
new = list_pkgs()
|
||||
return salt.utils.compare_dicts(old, new)
|
||||
@ -494,7 +491,7 @@ def file_list(*packages):
|
||||
errors = []
|
||||
ret = []
|
||||
cmd = 'pacman -Ql {0}'.format(' '.join(packages))
|
||||
out = __salt__['cmd.run'](cmd, output_loglevel='debug')
|
||||
out = __salt__['cmd.run'](cmd, output_loglevel='trace')
|
||||
for line in out.splitlines():
|
||||
if line.startswith('error'):
|
||||
errors.append(line)
|
||||
@ -521,7 +518,7 @@ def file_dict(*packages):
|
||||
errors = []
|
||||
ret = {}
|
||||
cmd = 'pacman -Ql {0}'.format(' '.join(packages))
|
||||
out = __salt__['cmd.run'](cmd, output_loglevel='debug')
|
||||
out = __salt__['cmd.run'](cmd, output_loglevel='trace')
|
||||
for line in out.splitlines():
|
||||
if line.startswith('error'):
|
||||
errors.append(line)
|
||||
@ -535,16 +532,28 @@ def file_dict(*packages):
|
||||
|
||||
def owner(*paths):
|
||||
'''
|
||||
Return the name of the package that owns the specified file. Files may be
|
||||
passed as a string (``path``) or as a list of strings (``paths``). If
|
||||
``path`` contains a comma, it will be converted to ``paths``. If a file
|
||||
name legitimately contains a comma, pass it in via ``paths``.
|
||||
.. versionadded:: Helium
|
||||
|
||||
Return the name of the package that owns the file. Multiple file paths can
|
||||
be passed. Like :mod:`pkg.version <salt.modules.yumpkg.version`, if a
|
||||
single path is passed, a string will be returned, and if multiple paths are
|
||||
passed, a dictionary of file/package name pairs will be returned.
|
||||
|
||||
If the file is not owned by a package, or is not present on the minion,
|
||||
then an empty string will be returned for that path.
|
||||
|
||||
CLI Example:
|
||||
|
||||
salt '*' pkg.owner /usr/bin/apachectl
|
||||
salt '*' pkg.owner /usr/bin/apachectl /etc/httpd/conf/httpd.conf
|
||||
salt '*' pkg.owner /usr/bin/apachectl /usr/bin/zsh
|
||||
'''
|
||||
cmd = 'pacman -Qqo {0}'
|
||||
return salt.utils.pkg.find_owner(
|
||||
__salt__['cmd.run'], cmd, *paths)
|
||||
if not paths:
|
||||
return ''
|
||||
ret = {}
|
||||
cmd = 'pacman -Qqo {0!r}'
|
||||
for path in paths:
|
||||
ret[path] = __salt__['cmd.run_stdout'](cmd.format(path),
|
||||
output_loglevel='debug')
|
||||
if len(ret) == 1:
|
||||
return ret.values()[0]
|
||||
return ret
|
||||
|
Loading…
Reference in New Issue
Block a user