mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
commit
2e24a4fdaa
@ -31,7 +31,7 @@ def output(grains):
|
||||
'''
|
||||
Output the grains in a clean way
|
||||
'''
|
||||
colors = salt.utils.get_colors(__opts__.get('color'))
|
||||
colors = salt.utils.get_colors(__opts__.get('color'), __opts__.get('color_theme'))
|
||||
encoding = grains['locale_info']['defaultencoding']
|
||||
if encoding == 'unknown':
|
||||
encoding = 'utf-8' # let's hope for the best
|
||||
|
@ -79,7 +79,9 @@ def output(data):
|
||||
|
||||
|
||||
def _format_host(host, data):
|
||||
colors = salt.utils.get_colors(__opts__.get('color'))
|
||||
colors = salt.utils.get_colors(
|
||||
__opts__.get('color'),
|
||||
__opts__('color_theme'))
|
||||
tabular = __opts__.get('state_tabular', False)
|
||||
rcounts = {}
|
||||
hcolor = colors['GREEN']
|
||||
|
@ -17,7 +17,9 @@ def output(data):
|
||||
Read in the dict structure generated by the salt key API methods and
|
||||
print the structure.
|
||||
'''
|
||||
color = salt.utils.get_colors(__opts__.get('color'))
|
||||
color = salt.utils.get_colors(
|
||||
__opts__.get('color'),
|
||||
__opts__.get('color_theme'))
|
||||
strip_colors = __opts__.get('strip_colors', True)
|
||||
if __opts__['transport'] == 'zeromq':
|
||||
acc = 'minions'
|
||||
|
@ -39,7 +39,9 @@ class NestDisplay(object):
|
||||
Manage the nested display contents
|
||||
'''
|
||||
def __init__(self):
|
||||
self.colors = salt.utils.get_colors(__opts__.get('color'))
|
||||
self.colors = salt.utils.get_colors(
|
||||
__opts__.get('color'),
|
||||
__opts__.get('color_theme'))
|
||||
|
||||
def ustring(self,
|
||||
indent,
|
||||
|
@ -23,7 +23,9 @@ class NestDisplay(object):
|
||||
Create generator for nested output
|
||||
'''
|
||||
def __init__(self):
|
||||
self.colors = salt.utils.get_colors(__opts__.get('color'))
|
||||
self.colors = salt.utils.get_colors(
|
||||
__opts__.get('color'),
|
||||
__opts__.get('color_theme'))
|
||||
|
||||
def display(self, ret, indent, prefix, out):
|
||||
'''
|
||||
|
@ -23,7 +23,9 @@ def output(data):
|
||||
'''
|
||||
Format the data for printing stage information from the overstate system
|
||||
'''
|
||||
colors = salt.utils.get_colors(__opts__.get('color'))
|
||||
colors = salt.utils.get_colors(
|
||||
__opts__.get('color'),
|
||||
__opts__.get('color_theme'))
|
||||
ostr = ''
|
||||
for comp in data:
|
||||
for name, stage in comp.items():
|
||||
|
@ -104,6 +104,8 @@ from salt.exceptions import (
|
||||
SaltInvocationError
|
||||
)
|
||||
|
||||
# Import third party libs
|
||||
import yaml
|
||||
|
||||
# Do not use these color declarations, use get_colors()
|
||||
# These color declarations will be removed in the future
|
||||
@ -152,7 +154,28 @@ def is_empty(filename):
|
||||
return False
|
||||
|
||||
|
||||
def get_colors(use=True):
|
||||
def get_color_theme(theme):
|
||||
'''
|
||||
Return the color theme to use
|
||||
'''
|
||||
if not os.path.isfile(theme):
|
||||
log.warning('The named theme {0} if not available'.format(theme))
|
||||
try:
|
||||
with fopen(theme, 'rb') as fp_:
|
||||
colors = yaml.safe_load(fp_.read())
|
||||
ret = {}
|
||||
for color in colors:
|
||||
ret[color] = '\033[{0}m'.format(colors[color])
|
||||
if not isinstance(colors, dict):
|
||||
log.warning('The theme file {0} is not a dict'.format(theme))
|
||||
return {}
|
||||
return ret
|
||||
except Exception:
|
||||
log.warning('Failed to read the color theme {0}'.format(theme))
|
||||
return {}
|
||||
|
||||
|
||||
def get_colors(use=True, theme=None):
|
||||
'''
|
||||
Return the colors as an easy to use dict, pass False to return the colors
|
||||
as empty strings so that they will not be applied
|
||||
@ -178,6 +201,8 @@ def get_colors(use=True):
|
||||
'RED_BOLD': '\033[01;31m',
|
||||
'ENDC': '\033[0m',
|
||||
}
|
||||
if theme:
|
||||
colors.update(get_color_theme(theme))
|
||||
|
||||
if not use:
|
||||
for color in colors:
|
||||
|
Loading…
Reference in New Issue
Block a user