From 3428eab79ab21d1ecee6d2f8edff083a2cccdf79 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Mon, 24 Sep 2012 13:25:01 -0400 Subject: made json optional again --- src/lib/Bcfg2/Server/Plugins/Ohai.py | 9 ++++++++- src/lib/Bcfg2/Server/Plugins/Packages/Yum.py | 7 ++++++- src/lib/Bcfg2/Server/Plugins/Probes.py | 13 +++++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) (limited to 'src/lib/Bcfg2/Server/Plugins') diff --git a/src/lib/Bcfg2/Server/Plugins/Ohai.py b/src/lib/Bcfg2/Server/Plugins/Ohai.py index 35e385a77..052597f84 100644 --- a/src/lib/Bcfg2/Server/Plugins/Ohai.py +++ b/src/lib/Bcfg2/Server/Plugins/Ohai.py @@ -2,7 +2,13 @@ import lxml.etree import os import logging import Bcfg2.Server.Plugin -from Bcfg2.Compat import json + +# pylint: disable=F0401 +try: + import json +except ImportError: + import simplejson as json +# pylint: enable=F0401 logger = logging.getLogger('Bcfg2.Plugins.Ohai') @@ -19,6 +25,7 @@ else fi """ + class OhaiCache(object): def __init__(self, dirname): self.dirname = dirname diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py b/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py index 4224798a8..04d4e9f74 100644 --- a/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py +++ b/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py @@ -61,7 +61,7 @@ from subprocess import Popen, PIPE import Bcfg2.Server.Plugin # pylint: disable=W0622 from Bcfg2.Compat import StringIO, cPickle, HTTPError, URLError, \ - ConfigParser, json, any + ConfigParser, any # pylint: enable=W0622 from Bcfg2.Server.Plugins.Packages.Collection import Collection from Bcfg2.Server.Plugins.Packages.Source import SourceInitError, Source, \ @@ -81,11 +81,16 @@ except ImportError: try: import yum + try: + import json + except ImportError: + import simplejson as json HAS_YUM = True except ImportError: HAS_YUM = False LOGGER.info("Packages: No yum libraries found; forcing use of internal " "dependency resolver") + # pylint: enable=E0611,F0401 XP = '{http://linux.duke.edu/metadata/common}' diff --git a/src/lib/Bcfg2/Server/Plugins/Probes.py b/src/lib/Bcfg2/Server/Plugins/Probes.py index 9e6b43d7b..58723e392 100644 --- a/src/lib/Bcfg2/Server/Plugins/Probes.py +++ b/src/lib/Bcfg2/Server/Plugins/Probes.py @@ -9,7 +9,6 @@ import operator import lxml.etree import Bcfg2.Server import Bcfg2.Server.Plugin -from Bcfg2.Compat import json # pylint: disable=F0401 try: @@ -31,6 +30,16 @@ try: except ImportError: pass +try: + import json + HAS_JSON = True +except ImportError: + try: + import simplejson as json + HAS_JSON = True + except ImportError: + HAS_JSON = False + try: import syck as yaml import syck.error as YAMLError @@ -89,7 +98,7 @@ class ProbeData(str): @property def json(self): """ The probe data as a decoded JSON data structure """ - if self._json is None: + if self._json is None and HAS_JSON: try: self._json = json.loads(self.data) except ValueError: -- cgit v1.2.3-1-g7c22