Commit d5835922 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Use indenting if supported by simplejson.

Reviewed-by: iustinp
parent 9ff7e35c
...@@ -28,9 +28,9 @@ pass to and from external parties. ...@@ -28,9 +28,9 @@ pass to and from external parties.
import simplejson import simplejson
from cStringIO import StringIO
import ConfigParser import ConfigParser
import re import re
from cStringIO import StringIO
from ganeti import errors from ganeti import errors
from ganeti import constants from ganeti import constants
...@@ -40,6 +40,14 @@ __all__ = ["ConfigObject", "ConfigData", "NIC", "Disk", "Instance", ...@@ -40,6 +40,14 @@ __all__ = ["ConfigObject", "ConfigData", "NIC", "Disk", "Instance",
"OS", "Node", "Cluster"] "OS", "Node", "Cluster"]
# Check whether the simplejson module supports indentation
simplejson.dumps(1, indent=_JSON_INDENT)
except TypeError:
class ConfigObject(object): class ConfigObject(object):
"""A generic config object. """A generic config object.
...@@ -86,7 +94,11 @@ class ConfigObject(object): ...@@ -86,7 +94,11 @@ class ConfigObject(object):
"""Dump to a file object. """Dump to a file object.
""" """
simplejson.dump(self.ToDict(), fobj) data = self.ToDict()
if _JSON_INDENT is None:
simplejson.dump(data, fobj)
simplejson.dump(data, fobj, indent=_JSON_INDENT)
@classmethod @classmethod
def Load(cls, fobj): def Load(cls, fobj):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment