From: Markus Lehtonen Date: Mon, 24 Mar 2014 13:01:46 +0000 (+0200) Subject: conf: make it possible to add new sections X-Git-Tag: 0.22~22 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=186df6d128a61839c29a8f921edffa8c7cfcc223;p=tools%2Fgbs.git conf: make it possible to add new sections Change the set_into_file() method so that a new section is added if the desired section is not found in the config. Change-Id: Ic4c513bd07b0b7ce8a82b921faba35ed36befef5 Signed-off-by: Markus Lehtonen --- diff --git a/gitbuildsys/conf.py b/gitbuildsys/conf.py index 9095441..0bbaf0e 100644 --- a/gitbuildsys/conf.py +++ b/gitbuildsys/conf.py @@ -133,18 +133,19 @@ class BrainConfigParser(SafeConfigParser): if last_section_line is not None: self._flines.insert(last_section_line + 1, new_line) else: - raise NoSectionError(section) + self._flines.insert(lineno + 1, '\n') + self._flines.insert(lineno + 2, '[%s]\n' % section) + self._flines.insert(lineno + 3, new_line) def set_into_file(self, section, option, value, replace_opt=None): """When set new value, need to update the readin file lines, which can be saved back to file later. """ - try: - SafeConfigParser.set(self, section, option, value) - if replace_opt: - SafeConfigParser.remove_option(self, section, replace_opt) - except NoSectionError, err: - raise errors.ConfigError(str(err)) + if not self.has_section(section): + self.add_section(section) + SafeConfigParser.set(self, section, option, value) + if replace_opt: + SafeConfigParser.remove_option(self, section, replace_opt) # If the code reach here, it means the section and key are ok try: