Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
snf-ganeti
Commits
d5835922
Commit
d5835922
authored
Oct 08, 2007
by
Michael Hanselmann
Browse files
Use indenting if supported by simplejson.
Reviewed-by: iustinp
parent
9ff7e35c
Changes
1
Show whitespace changes
Inline
Side-by-side
lib/objects.py
View file @
d5835922
...
...
@@ -28,9 +28,9 @@ pass to and from external parties.
import
simplejson
from
cStringIO
import
StringIO
import
ConfigParser
import
re
from
cStringIO
import
StringIO
from
ganeti
import
errors
from
ganeti
import
constants
...
...
@@ -40,6 +40,14 @@ __all__ = ["ConfigObject", "ConfigData", "NIC", "Disk", "Instance",
"OS"
,
"Node"
,
"Cluster"
]
# Check whether the simplejson module supports indentation
_JSON_INDENT
=
2
try
:
simplejson
.
dumps
(
1
,
indent
=
_JSON_INDENT
)
except
TypeError
:
_JSON_INDENT
=
None
class
ConfigObject
(
object
):
"""A generic config object.
...
...
@@ -86,7 +94,11 @@ class ConfigObject(object):
"""Dump to a file object.
"""
simplejson
.
dump
(
self
.
ToDict
(),
fobj
)
data
=
self
.
ToDict
()
if
_JSON_INDENT
is
None
:
simplejson
.
dump
(
data
,
fobj
)
else
:
simplejson
.
dump
(
data
,
fobj
,
indent
=
_JSON_INDENT
)
@
classmethod
def
Load
(
cls
,
fobj
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment