(self)
Save the config to a file
Save the config to a file
Save the config to a file
def save(self):
        """Save the config to a file"""
        dbg('ConfigBase::save: saving config')
        parser = ConfigObj(encoding='utf-8')
        parser.indent_type = '  '

        for section_name in ['global_config', 'keybindings']:
            dbg('ConfigBase::save: Processing section: %s' % section_name)
            section = getattr(self, section_name)
            parser[section_name] = dict_diff(DEFAULTS[section_name], section)

        from .configjson import JSON_PROFILE_NAME, JSON_LAYOUT_NAME

        parser['profiles'] = {}
        for profile in self.profiles:
            if profile == JSON_PROFILE_NAME:
                continue
            dbg('ConfigBase::save: Processing profile: %s' % profile)
            parser['profiles'][profile] = dict_diff(
                    DEFAULTS['profiles']['default'], self.profiles[profile])

        parser['layouts'] = {}
        for layout in self.layouts:
            if layout == JSON_LAYOUT_NAME:
                continue
            dbg('ConfigBase::save: Processing layout: %s' % layout)
            parser['layouts'][layout] = self.layouts[layout]

        parser['plugins'] = {}
        for plugin in self.plugins:
            dbg('ConfigBase::save: Processing plugin: %s' % plugin)
            parser['plugins'][plugin] = self.plugins[plugin]

        config_dir = get_config_dir()
        if not os.path.isdir(config_dir):
            os.makedirs(config_dir)

        try:
            if self.command_line_options.config:
                filename = self.command_line_options.config
            else: 
                filename = os.path.join(config_dir,'config')

            if not os.path.isfile(filename):
                open(filename, 'a').close()

            backup_file = filename + '~'
            shutil.copy2(filename, backup_file)

            with open(filename, 'wb') as fh:
                parser.write(fh)

            os.remove(backup_file)
        except Exception as ex:
            err('ConfigBase::save: Unable to save config: %s' % ex)
def save ( self ) : dbg ( 'ConfigBase::save: saving config' ) parser = ConfigObj ( encoding = 'utf-8' ) parser . indent_type = '  ' for section_name in [ 'global_config' , 'keybindings' ] : dbg ( 'ConfigBase::save: Processing section: %s' % section_name ) section = getattr ( self , section_name ) parser [ section_name ] = dict_diff ( DEFAULTS [ section_name ] , section ) from . configjson import JSON_PROFILE_NAME , JSON_LAYOUT_NAME parser [ 'profiles' ] = { } for profile in self . profiles : if profile == JSON_PROFILE_NAME : continue dbg ( 'ConfigBase::save: Processing profile: %s' % profile ) parser [ 'profiles' ] [ profile ] = dict_diff ( DEFAULTS [ 'profiles' ] [ 'default' ] , self . profiles [ profile ] ) parser [ 'layouts' ] = { } for layout in self . layouts : if layout == JSON_LAYOUT_NAME : continue dbg ( 'ConfigBase::save: Processing layout: %s' % layout ) parser [ 'layouts' ] [ layout ] = self . layouts [ layout ] parser [ 'plugins' ] = { } for plugin in self . plugins : dbg ( 'ConfigBase::save: Processing plugin: %s' % plugin ) parser [ 'plugins' ] [ plugin ] = self . plugins [ plugin ] config_dir = get_config_dir ( ) if not os . path . isdir ( config_dir ) : os . makedirs ( config_dir ) try : if self . command_line_options . config : filename = self . command_line_options . config else : filename = os . path . join ( config_dir , 'config' ) if not os . path . isfile ( filename ) : open ( filename , 'a' ) . close ( ) backup_file = filename + '~' shutil . copy2 ( filename , backup_file ) with open ( filename , 'wb' ) as fh : parser . write ( fh ) os . remove ( backup_file ) except Exception as ex : err ( 'ConfigBase::save: Unable to save config: %s' % ex )