Commit c1cc5baf authored by Gerion Entrup's avatar Gerion Entrup
Browse files

settings: add writer.py

parent 187ccca2
#!/usr/bin/env python3
import settings
import configparser
......@@ -11,26 +8,26 @@ class PFile():
def write(self, s):
s = s.split('\n')
print("1", s)
for idx, line in enumerate(s):
if len(line) > 0 and line[0] != '#':
self._before_comment = True
if line.startswith('#') and self._before_comment:
s[idx] = '\n' + line
self._before_comment = False
print("2", s)
self._orig.write('\n'.join(s))
root = 'settings'
config = configparser.ConfigParser(allow_no_value=True)
config.add_section(root)
for opt, value in settings.get_options():
doc = settings.get_doc(opt).split('\n')
for line in doc:
if len(line) > 0:
line = ' ' + line
config.set(root, '#' + line)
config.set(root, opt, str(value))
with open('example.ini', 'w') as c_file:
config.write(PFile(c_file))
def write(path, settings):
root = 'settings'
config = configparser.ConfigParser(allow_no_value=True)
config.add_section(root)
for opt, value in settings.get_options():
doc = settings.get_doc(opt).split('\n')
for line in doc:
if len(line) > 0:
line = ' ' + line
config.set(root, '#' + line)
config.set(root, opt, str(value))
with open(path, 'w') as c_file:
config.write(PFile(c_file))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment