summaryrefslogtreecommitdiffstats
path: root/plugins.d
diff options
context:
space:
mode:
authorIlya <ilyamaschenko@gmail.com>2017-02-07 10:31:00 +0900
committerIlya <ilyamaschenko@gmail.com>2017-02-07 10:31:00 +0900
commite621007e591fb71bbec6c41fbd26caba61d58e6f (patch)
treed5b99cced8d077d3e5fcd32cce9eed7c21eb3674 /plugins.d
parent1881345cb01f8d9a726c5406e2a656ea18d36cbc (diff)
python.d.plugin: YAML output is ordered now
Diffstat (limited to 'plugins.d')
-rwxr-xr-xplugins.d/python.d.plugin27
1 files changed, 25 insertions, 2 deletions
diff --git a/plugins.d/python.d.plugin b/plugins.d/python.d.plugin
index b4e6473a62..44b729094c 100755
--- a/plugins.d/python.d.plugin
+++ b/plugins.d/python.d.plugin
@@ -67,6 +67,26 @@ try:
except ImportError:
msg.fatal('Cannot find yaml library')
+try:
+ from collections import OrderedDict
+ ORDERED = True
+ DICT = OrderedDict
+ msg.info('YAML output is ordered')
+except ImportError:
+ ORDERED = False
+ DICT = dict
+ msg.info('YAML output is unordered')
+else:
+ def ordered_load(stream, Loader=yaml.Loader, object_pairs_hook=OrderedDict):
+ class OrderedLoader(Loader):
+ pass
+ def construct_mapping(loader, node):
+ loader.flatten_mapping(node)
+ return object_pairs_hook(loader.construct_pairs(node))
+ OrderedLoader.add_constructor(
+ yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG,
+ construct_mapping)
+ return yaml.load(stream, OrderedLoader)
class PythonCharts(object):
"""
@@ -235,7 +255,7 @@ class PythonCharts(object):
# check if there are dict in config dict
many_jobs = False
for name in config:
- if type(config[name]) is dict:
+ if isinstance(config[name], DICT):
many_jobs = True
break
@@ -420,7 +440,10 @@ def read_config(path):
"""
try:
with open(path, 'r') as stream:
- config = yaml.load(stream)
+ if ORDERED:
+ config = ordered_load(stream, yaml.SafeLoader)
+ else:
+ config = yaml.load(stream)
except (OSError, IOError):
msg.error(str(path), "is not a valid configuration file")
return None