diff options
Diffstat (limited to 'py/configobjwalker.py')
-rw-r--r-- | py/configobjwalker.py | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/py/configobjwalker.py b/py/configobjwalker.py index 985fd36..576adcd 100644 --- a/py/configobjwalker.py +++ b/py/configobjwalker.py @@ -21,22 +21,45 @@ def configobj_walker(cfg): def _walk_section(s, level=0): from configobj import Section assert isinstance(s, Section) - indent = ' ' * level + indent = u' ' * level for name in s.scalars: for c in s.comments[name]: yield indent + c.strip() - line = '{0}{1}: {2}'.format(indent, name, s[name]) + x = s[name] + if u'\n' in x: + i = indent + u' ' + x = u'|\n' + i + x.strip().replace(u'\n', u'\n' + i) + elif ':' in x: + x = u"'" + x.replace(u"'", u"''") + u"'" + line = u'{0}{1}: {2}'.format(indent, name, x) c = s.inline_comments[name] if c: - line += ' ' + c + line += u' ' + c yield line for name in s.sections: for c in s.comments[name]: yield indent + c.strip() - line = '{0}{1}:'.format(indent, name) + line = u'{0}{1}:'.format(indent, name) c = s.inline_comments[name] if c: - line += ' ' + c + line += u' ' + c yield line for val in _walk_section(s[name], level=level+1): yield val + +##def config_obj_2_rt_yaml(cfg): +## from .comments import CommentedMap, CommentedSeq +## from configobj import ConfigObj +## assert isinstance(cfg, ConfigObj) +## #for c in cfg.initial_comment: +## # if c.strip(): +## # pass +## cm = CommentedMap() +## for name in s.sections: +## cm[name] = d = CommentedMap() +## +## +## #for c in cfg.final_comment: +## # if c.strip(): +## # yield c +## return cm |