Revision d5835922 lib/objects.py

b/lib/objects.py
28 28

  
29 29

  
30 30
import simplejson
31
from cStringIO import StringIO
32 31
import ConfigParser
33 32
import re
33
from cStringIO import StringIO
34 34

  
35 35
from ganeti import errors
36 36
from ganeti import constants
......
40 40
           "OS", "Node", "Cluster"]
41 41

  
42 42

  
43
# Check whether the simplejson module supports indentation
44
_JSON_INDENT = 2
45
try:
46
  simplejson.dumps(1, indent=_JSON_INDENT)
47
except TypeError:
48
  _JSON_INDENT = None
49

  
50

  
43 51
class ConfigObject(object):
44 52
  """A generic config object.
45 53

  
......
86 94
    """Dump to a file object.
87 95

  
88 96
    """
89
    simplejson.dump(self.ToDict(), fobj)
97
    data = self.ToDict()
98
    if _JSON_INDENT is None:
99
      simplejson.dump(data, fobj)
100
    else:
101
      simplejson.dump(data, fobj, indent=_JSON_INDENT)
90 102

  
91 103
  @classmethod
92 104
  def Load(cls, fobj):

Also available in: Unified diff