From 3ec2fc27deefc647127c9e729221826a90fd7a96 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Fri, 17 Jun 2011 08:03:26 -0400 Subject: Improved handling of JSON data from probes --- doc/server/plugins/probes/index.txt | 6 +++--- src/lib/Server/Plugins/Probes.py | 17 ++++++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/doc/server/plugins/probes/index.txt b/doc/server/plugins/probes/index.txt index d52e7bb95..5b1f9e259 100644 --- a/doc/server/plugins/probes/index.txt +++ b/doc/server/plugins/probes/index.txt @@ -128,12 +128,12 @@ string-like object that has some interesting and salient features: * If the data is a valid XML document, then ``metadata.Probes['script-name'].xdata`` will be an ``lxml.etree._Element`` object representing the XML data. -* If the data is a valid JSON document, and the Python ``json`` module - is installed (included in Python 2.6 onward), then +* If the data is a valid JSON document, and either the Python ``json`` + or ``simplejson`` module is installed, then ``metadata.Probes['script-name'].json`` will be a data structure representing the JSON data. * If the data is a valid YAML document, and either the Python ``yaml`` - module or ``syck`` module is installed, then + or ``syck`` module is installed, then ``metadata.Probes['script-name'].yaml`` will be a data structure representing the YAML data. diff --git a/src/lib/Server/Plugins/Probes.py b/src/lib/Server/Plugins/Probes.py index b07c4dfd3..ec0f294dd 100644 --- a/src/lib/Server/Plugins/Probes.py +++ b/src/lib/Server/Plugins/Probes.py @@ -6,19 +6,22 @@ try: import json has_json = True except ImportError: - has_json = False + try: + import simplejson as json + has_json = True + except ImportError: + has_json = False try: import syck has_syck = True except ImportError: has_syck = False - -try: - import yaml - has_yaml = True -except ImportError: - has_yaml = False + try: + import yaml + has_yaml = True + except ImportError: + has_yaml = False import Bcfg2.Server.Plugin -- cgit v1.2.3-1-g7c22