diff --git a/kivy/config.py b/kivy/config.py index 43715013e..120ab3f43 100644 --- a/kivy/config.py +++ b/kivy/config.py @@ -376,6 +376,12 @@ class ConfigParser(PythonConfigParser, object): self._do_callbacks(section, option, value) return ret + def setall(self, section, keyvalues): + '''Set a lot of keys/values in one section at the same time. + ''' + for key, value in keyvalues.items(): + self.set(section, key, value) + def get(self, section, option, **kwargs): value = PythonConfigParser.get(self, section, option, **kwargs) if PY2: @@ -384,7 +390,7 @@ class ConfigParser(PythonConfigParser, object): return value def setdefaults(self, section, keyvalues): - '''Set a lot of keys/values in one section at the same time. + '''Set a lot of keys/value defaults in one section at the same time. ''' self.adddefaultsection(section) for key, value in keyvalues.items(): @@ -437,6 +443,17 @@ class ConfigParser(PythonConfigParser, object): return False return True + def update_config(self, filename, overwrite=False): + '''Upgrade the configuration based on a new default config file. + Overwrite any existing values if overwrite is True. + ''' + pcp = PythonConfigParser() + pcp.read(filename) + confset = self.setall if overwrite else self.setdefaults + for section in pcp.sections(): + confset(section, dict(pcp.items(section))) + self.write() + @staticmethod def _register_named_property(name, widget_ref, *largs): ''' Called by the ConfigParserProperty to register a property which