[Checkins] SVN: Sandbox/ulif/ZConfigParser/ZConfigParser/convert.py Add very simple conversion to start with.

Uli Fouquet uli at gnufix.de
Mon Apr 6 06:22:55 EDT 2009


Log message for revision 98919:
  Add very simple conversion to start with.

Changed:
  A   Sandbox/ulif/ZConfigParser/ZConfigParser/convert.py

-=-
Added: Sandbox/ulif/ZConfigParser/ZConfigParser/convert.py
===================================================================
--- Sandbox/ulif/ZConfigParser/ZConfigParser/convert.py	                        (rev 0)
+++ Sandbox/ulif/ZConfigParser/ZConfigParser/convert.py	2009-04-06 10:22:55 UTC (rev 98919)
@@ -0,0 +1,20 @@
+"""Convert ZConfig configurations/files to ConfigParser style.
+"""
+from ZConfigParser import schemaless
+
+
+def convertFile(filepath):
+    config = schemaless.loadConfigFile(open(filepath, 'rb'))
+    return convertSection(config)
+
+def convertSection(section, prefix='zope'):
+    body = ''
+    if section.type:
+        prefix = '%s/%s' % (prefix, section.type)
+        body = '\n[%s]\n' % (prefix)
+    for key in list(section):
+        body += '%s = %s\n' % (key, section[key][0])
+    for section in section.sections:
+        body += '%s = %s/%s\n' % (section.type, prefix, section.type)
+        body += convertSection(section, prefix)
+    return body



More information about the Checkins mailing list