summaryrefslogtreecommitdiff
path: root/src/config.py
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2013-06-18 20:37:04 +0200
committerFlorent Le Coz <louiz@louiz.org>2013-06-18 20:37:04 +0200
commit39fa811374b7119173120175e70fb4f197bc0aba (patch)
treea9d4f70ce027ae7df31aaf4c97008fb7307533db /src/config.py
parentef9672c0fd5f053ba2eae8704836685a3edb340c (diff)
downloadpoezio-39fa811374b7119173120175e70fb4f197bc0aba.tar.gz
poezio-39fa811374b7119173120175e70fb4f197bc0aba.tar.bz2
poezio-39fa811374b7119173120175e70fb4f197bc0aba.tar.xz
poezio-39fa811374b7119173120175e70fb4f197bc0aba.zip
Trigger config_change handlers when the config has changed using a USR1 signal
Diffstat (limited to 'src/config.py')
-rw-r--r--src/config.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/config.py b/src/config.py
index 92fa503f..6b7e3864 100644
--- a/src/config.py
+++ b/src/config.py
@@ -30,10 +30,13 @@ class Config(RawConfigParser):
load/save the config to a file
"""
def __init__(self, file_name):
- self.file_name = file_name
RawConfigParser.__init__(self, None)
# make the options case sensitive
self.optionxform = str
+ self.read_file(file_name)
+
+ def read_file(self, file_name):
+ self.file_name = file_name
try:
RawConfigParser.read(self, file_name, encoding='utf-8')
except TypeError: # python < 3.2 sucks
@@ -175,8 +178,6 @@ class Config(RawConfigParser):
result_lines.append('%s = %s' % (option, value))
elif not written:
result_lines.append('%s = %s' % (option, value))
-
-
try:
df = open(self.file_name, 'w', encoding='utf-8')
for line in result_lines:
@@ -233,6 +234,16 @@ class Config(RawConfigParser):
except NoSectionError:
pass
+ def to_dict(self):
+ """
+ Returns a dict of the form {section: {option: value, option: value}, …}
+ """
+ res = {}
+ for section in self.sections():
+ res[section] = {}
+ for option in self.options(section):
+ res[section][option] = self.get(option, "", section)
+ return res
firstrun = False