diff options
author | Florent Le Coz <louiz@louiz.org> | 2012-02-15 20:10:00 +0100 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2012-02-15 20:10:00 +0100 |
commit | 695a7ebebaf6a277420dcb42cd96d92d77df0379 (patch) | |
tree | 8c9da1e5bf988356ad110f42113949aab94a5866 /src/config.py | |
parent | 0606c2b351ac87f110e1240d2f4ba1b94b275930 (diff) | |
parent | b89cd8fd8322bf8aa23130398a0a70defcba708d (diff) | |
download | poezio-695a7ebebaf6a277420dcb42cd96d92d77df0379.tar.gz poezio-695a7ebebaf6a277420dcb42cd96d92d77df0379.tar.bz2 poezio-695a7ebebaf6a277420dcb42cd96d92d77df0379.tar.xz poezio-695a7ebebaf6a277420dcb42cd96d92d77df0379.zip |
Merge branch 'master' of https://git.louiz.org/poezio
Diffstat (limited to 'src/config.py')
-rw-r--r-- | src/config.py | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/config.py b/src/config.py index af9c9fbe..2ee4abb1 100644 --- a/src/config.py +++ b/src/config.py @@ -113,16 +113,31 @@ class Config(RawConfigParser): df.close() result_lines = [] we_are_in_the_right_section = False + written = False + section_found = False for line in lines_before: if line.startswith('['): # check the section + if we_are_in_the_right_section and not written: + result_lines.append('%s= %s' % (option, value)) if line == '[%s]' % section: we_are_in_the_right_section = True + section_found = True else: we_are_in_the_right_section = False if (line.startswith('%s ' % (option,)) or - line.startswith('%s=' % (option,))) and we_are_in_the_right_section: - line = '%s = %s' % (option, value) + line.startswith('%s=' % (option,)) or + line.startswith('%s = ' % (option,))) and we_are_in_the_right_section: + line = '%s= %s' % (option, value) + written = True result_lines.append(line) + + if not section_found: + result_lines.append('[%s]' % section) + result_lines.append('%s= %s' % (option, value)) + elif not written: + result_lines.append('%s= %s' % (option, value)) + + df = open(self.file_name, 'w') for line in result_lines: df.write('%s\n' % line) @@ -133,11 +148,11 @@ class Config(RawConfigParser): set the value in the configuration then save it to the file """ - try: + if self.has_section(section): + RawConfigParser.set(self, section, option, value) + else: + self.add_section(section) RawConfigParser.set(self, section, option, value) - except NoSectionError: - # TODO, add this section if it didn't exist - return self.write_in_file(section, option, value) def set(self, option, value, section=DEFSECTION): |