def load_config(self): '''(internal) This function is used for returning a ConfigParser with the application configuration. It's doing 3 things: #. Creating an instance of a ConfigParser #. Loading the default configuration by calling :meth:`build_config`, then #. If it exists, it loads the application configuration file, otherwise it creates one. :return: :class:`~kivy.config.ConfigParser` instance ''' try: config = ConfigParser.get_configparser('app') except KeyError: config = None if config is None: config = ConfigParser(name='app') self.config = config self.build_config(config) # if no sections are created, that's mean the user don't have # configuration. if len(config.sections()) == 0: return # ok, the user have some sections, read the default file if exist # or write it ! filename = self.get_application_config() if filename is None: return config Logger.debug('App: Loading configuration <{0}>'.format(filename)) if exists(filename): try: config.read(filename) except: Logger.error('App: Corrupted config file, ignored.') config.name = '' try: config = ConfigParser.get_configparser('app') except KeyError: config = None if config is None: config = ConfigParser(name='app') self.config = config self.build_config(config) pass else: Logger.debug('App: First configuration, create <{0}>'.format( filename)) config.filename = filename config.write() return config
def load_config(self): try: config = ConfigParser.get_configparser('app') except KeyError: config = None if config is None: config = ConfigParser(name='app') self.config = config self.build_config(config) # if no sections are created, that's mean the user don't have # configuration. if len(config.sections()) == 0: return # ok, the user have some sections, read the default file if exist # or write it ! filename = self.get_application_config() if filename is None: return config Logger.debug('FlexApp: Loading configuration <{0}>'.format(filename)) if exists(filename): try: config.read(filename) except: Logger.error('FlexApp: Corrupted config file, ignored.') config.name = '' try: config = ConfigParser.get_configparser('app') except KeyError: config = None if config is None: config = ConfigParser(name='app') self.config = config self.build_config(config) pass else: Logger.debug('FlexApp: First configuration, create <{0}>'.format( filename)) config.filename = filename config.write() return config