config's string representation

This commit is contained in:
gwen 2012-11-28 10:14:16 +01:00
parent bf112bc756
commit d9c8e06236
1 changed files with 11 additions and 17 deletions

View File

@ -409,27 +409,21 @@ class Config(object):
except: except:
pass # hidden, disabled option pass # hidden, disabled option
# ______________________________________________________________________ # ______________________________________________________________________
def __str__(self, indent=""): def __str__(self):
"Config's string representation" "Config's string representation"
lines = [] lines = []
children = [(child._name, child) for name, grp in self.iter_groups():
for child in self._cfgimpl_descr._children] lines.append("[%s]" % name)
children.sort() for name, value in self:
for name, child in children: try:
if self._cfgimpl_value_owners.get(name, None) == 'default': lines.append("%s = %s" % (name, value))
continue except:
value = getattr(self, name) pass
if isinstance(value, Config):
substr = value.__str__(indent + " ")
else:
substr = "%s %s = %s" % (indent, name, value)
if substr:
lines.append(substr)
if indent and not lines:
return '' # hide subgroups with all default values
lines.insert(0, "%s[%s]" % (indent, self._cfgimpl_descr._name,))
return '\n'.join(lines) return '\n'.join(lines)
__repr__ = __str__
def getpaths(self, include_groups=False, allpaths=False, mandatory=False): def getpaths(self, include_groups=False, allpaths=False, mandatory=False):
"""returns a list of all paths in self, recursively, taking care of """returns a list of all paths in self, recursively, taking care of
the context of properties (hidden/disabled) the context of properties (hidden/disabled)