mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Py3 compatibility fixes.
This commit is contained in:
parent
263a8ef3da
commit
83cdb11ccf
@ -262,9 +262,8 @@ Links
|
||||
For more examples and information see <https://github.com/mickep76/pepa>.
|
||||
'''
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from __future__ import absolute_import
|
||||
# Import futures
|
||||
from __future__ import absolute_import, print_function
|
||||
|
||||
__author__ = 'Michael Persson <michael.ake.persson@gmail.com>'
|
||||
__copyright__ = 'Copyright (c) 2013 Michael Persson'
|
||||
@ -279,7 +278,10 @@ import yaml
|
||||
import jinja2
|
||||
import re
|
||||
from os.path import isfile, join
|
||||
from salt.ext.six.moves import input
|
||||
|
||||
# Import 3rd-party libs
|
||||
import salt.ext.six as six
|
||||
from salt.ext.six.moves import input # pylint: disable=import-error,redefined-builtin
|
||||
|
||||
# Import Salt libs
|
||||
import salt.utils
|
||||
@ -310,7 +312,7 @@ if __name__ == '__main__':
|
||||
formatter = None
|
||||
if not args.no_color:
|
||||
try:
|
||||
import colorlog
|
||||
import colorlog # pylint: disable=import-error
|
||||
formatter = colorlog.ColoredFormatter("[%(log_color)s%(levelname)-8s%(reset)s] %(log_color)s%(message)s%(reset)s")
|
||||
except ImportError:
|
||||
formatter = logging.Formatter("[%(levelname)-8s] %(message)s")
|
||||
@ -350,7 +352,7 @@ def key_value_to_tree(data):
|
||||
Convert key/value to tree
|
||||
'''
|
||||
tree = {}
|
||||
for flatkey, value in data.items():
|
||||
for flatkey, value in six.iteritems(data):
|
||||
t = tree
|
||||
keys = flatkey.split(__opts__['pepa_delimiter'])
|
||||
for key in keys:
|
||||
@ -384,7 +386,7 @@ def ext_pillar(minion_id, pillar, resource, sequence, subkey=False, subkey_only=
|
||||
output['pepa_templates'] = []
|
||||
immutable = {}
|
||||
|
||||
for categ, info in [s.items()[0] for s in sequence]:
|
||||
for categ, info in [next(six.iteritems(s)) for s in sequence]:
|
||||
if categ not in inp:
|
||||
log.warn("Category is not defined: {0}".format(categ))
|
||||
continue
|
||||
@ -500,7 +502,7 @@ def validate(output, resource):
|
||||
Validate Pepa templates
|
||||
'''
|
||||
try:
|
||||
import cerberus
|
||||
import cerberus # pylint: disable=import-error
|
||||
except ImportError:
|
||||
log.critical('You need module cerberus in order to use validation')
|
||||
return
|
||||
@ -524,7 +526,7 @@ def validate(output, resource):
|
||||
|
||||
val = cerberus.Validator()
|
||||
if not val.validate(output['pepa_keys'], all_schemas):
|
||||
for ekey, error in val.errors.items():
|
||||
for ekey, error in six.iteritems(val.errors):
|
||||
log.warning('Validation failed for key {0}: {1}'.format(ekey, error))
|
||||
|
||||
output['pepa_schema_keys'] = all_schemas
|
||||
@ -615,10 +617,15 @@ if __name__ == '__main__':
|
||||
yaml.dumper.SafeDumper.ignore_aliases = lambda self, data: True
|
||||
if not args.no_color:
|
||||
try:
|
||||
# pylint: disable=import-error
|
||||
import pygments
|
||||
import pygments.lexers
|
||||
import pygments.formatters
|
||||
print(pygments.highlight(yaml.safe_dump(result), pygments.lexers.YamlLexer(), pygments.formatters.TerminalFormatter()))
|
||||
# pylint: disable=no-member
|
||||
print(pygments.highlight(yaml.safe_dump(result),
|
||||
pygments.lexers.YamlLexer(),
|
||||
pygments.formatters.TerminalFormatter()))
|
||||
# pylint: enable=no-member, import-error
|
||||
except ImportError:
|
||||
print(yaml.safe_dump(result, indent=4, default_flow_style=False))
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user