(self)
Load configuration data from our various sources
Load configuration data from our various sources
Load configuration data from our various sources
def load(self):
        """Load configuration data from our various sources"""
        if self.loaded is True:
            dbg('ConfigBase::load: config already loaded')
            return

        if self.command_line_options and self.command_line_options.config:
            filename = self.command_line_options.config
        else:
            filename = os.path.join(get_config_dir(), 'config')
            if not os.path.exists(filename):
                filename = os.path.join(get_system_config_dir(), 'config')
        dbg('looking for config file: %s' % filename)
        try:
            #
            # Make sure we attempt to update the ‘cell_height’ config
            # only once when starting a new instance of Terminator.
            #
            if not self.config_file_updated_to_cell_height:
                update_config_to_cell_height(filename)
                self.config_file_updated_to_cell_height = True

            configfile = open(filename, 'r')
        except Exception as ex:
            if not self.whined:
                err('ConfigBase::load: Unable to open %s (%s)' % (filename, ex))
                self.whined = True
            return
        # If we have successfully loaded a config, allow future whining
        self.whined = False

        try:
            configspec = self.defaults_to_configspec()
            parser = ConfigObj(configfile, configspec=configspec)
            validator = Validator()
            result = parser.validate(validator, preserve_errors=True)
        except Exception as ex:
            err('Unable to load configuration: %s' % ex)
            return

        if result != True:
            err('ConfigBase::load: config format is not valid')
            for (section_list, key, _other) in flatten_errors(parser, result):
                if key is not None:
                    err('[%s]: %s is invalid' % (','.join(section_list), key))
                else:
                    err('[%s] missing' % ','.join(section_list))
        else:
            dbg('config validated successfully')

        for section_name in self.sections:
            dbg('ConfigBase::load: Processing section: %s' % section_name)
            section = getattr(self, section_name)
            if section_name == 'profiles':
                for profile in parser[section_name]:
                    dbg('ConfigBase::load: Processing profile: %s' % profile)
                    if section_name not in section:
                        # FIXME: Should this be outside the loop?
                        section[profile] = copy(DEFAULTS['profiles']['default'])
                    section[profile].update(parser[section_name][profile])
            elif section_name == 'plugins':
                if section_name not in parser:
                    continue
                for part in parser[section_name]:
                    dbg('ConfigBase::load: Processing %s: %s' % (section_name,
                                                                 part))
                    section[part] = parser[section_name][part]
            elif section_name == 'layouts':
                for layout in parser[section_name]:
                    dbg('ConfigBase::load: Processing %s: %s' % (section_name,
                                                                 layout))
                    if layout == 'default' and \
                       parser[section_name][layout] == {}:
                           continue
                    section[layout] = parser[section_name][layout]
            elif section_name == 'keybindings':
                if section_name not in parser:
                    continue
                for part in parser[section_name]:
                    dbg('ConfigBase::load: Processing %s: %s' % (section_name,
                                                                 part))
                    if parser[section_name][part] == 'None':
                        section[part] = None
                    else:
                        section[part] = parser[section_name][part]
            else:
                try:
                    section.update(parser[section_name])
                except KeyError as ex:
                    dbg('ConfigBase::load: skipping missing section %s' %
                            section_name)

        self.loaded = True
def load ( self ) : if self . loaded is True : dbg ( 'ConfigBase::load: config already loaded' ) return if self . command_line_options and self . command_line_options . config : filename = self . command_line_options . config else : filename = os . path . join ( get_config_dir ( ) , 'config' ) if not os . path . exists ( filename ) : filename = os . path . join ( get_system_config_dir ( ) , 'config' ) dbg ( 'looking for config file: %s' % filename ) try : # # Make sure we attempt to update the ‘cell_height’ config # only once when starting a new instance of Terminator. # if not self . config_file_updated_to_cell_height : update_config_to_cell_height ( filename ) self . config_file_updated_to_cell_height = True configfile = open ( filename , 'r' ) except Exception as ex : if not self . whined : err ( 'ConfigBase::load: Unable to open %s (%s)' % ( filename , ex ) ) self . whined = True return # If we have successfully loaded a config, allow future whining self . whined = False try : configspec = self . defaults_to_configspec ( ) parser = ConfigObj ( configfile , configspec = configspec ) validator = Validator ( ) result = parser . validate ( validator , preserve_errors = True ) except Exception as ex : err ( 'Unable to load configuration: %s' % ex ) return if result != True : err ( 'ConfigBase::load: config format is not valid' ) for ( section_list , key , _other ) in flatten_errors ( parser , result ) : if key is not None : err ( '[%s]: %s is invalid' % ( ',' . join ( section_list ) , key ) ) else : err ( '[%s] missing' % ',' . join ( section_list ) ) else : dbg ( 'config validated successfully' ) for section_name in self . sections : dbg ( 'ConfigBase::load: Processing section: %s' % section_name ) section = getattr ( self , section_name ) if section_name == 'profiles' : for profile in parser [ section_name ] : dbg ( 'ConfigBase::load: Processing profile: %s' % profile ) if section_name not in section : # FIXME: Should this be outside the loop? section [ profile ] = copy ( DEFAULTS [ 'profiles' ] [ 'default' ] ) section [ profile ] . update ( parser [ section_name ] [ profile ] ) elif section_name == 'plugins' : if section_name not in parser : continue for part in parser [ section_name ] : dbg ( 'ConfigBase::load: Processing %s: %s' % ( section_name , part ) ) section [ part ] = parser [ section_name ] [ part ] elif section_name == 'layouts' : for layout in parser [ section_name ] : dbg ( 'ConfigBase::load: Processing %s: %s' % ( section_name , layout ) ) if layout == 'default' and parser [ section_name ] [ layout ] == { } : continue section [ layout ] = parser [ section_name ] [ layout ] elif section_name == 'keybindings' : if section_name not in parser : continue for part in parser [ section_name ] : dbg ( 'ConfigBase::load: Processing %s: %s' % ( section_name , part ) ) if parser [ section_name ] [ part ] == 'None' : section [ part ] = None else : section [ part ] = parser [ section_name ] [ part ] else : try : section . update ( parser [ section_name ] ) except KeyError as ex : dbg ( 'ConfigBase::load: skipping missing section %s' % section_name ) self . loaded = True