def setup_tribler_gui_config(self): """ Initialize the TriblerGUI configuration file and make sure that we have all required values. """ configfilepath = os.path.join(self.get_state_dir(), STATEDIR_GUICONFIG) gui_config = CallbackConfigParser() DefaultDownloadStartupConfig.getInstance().set_dest_dir( get_default_dest_dir()) # Load the config file. if os.path.exists(configfilepath): gui_config.read_file(configfilepath, 'utf-8-sig') if not gui_config.has_section('Tribler'): gui_config.add_section('Tribler') for k, v in tribler_defaults['Tribler'].iteritems(): if not gui_config.has_option(k, v): gui_config.set('Tribler', k, v) if not gui_config.has_section('downloadconfig'): gui_config.add_section('downloadconfig') for k, v in DefaultDownloadStartupConfig.getInstance( ).dlconfig._sections['downloadconfig'].iteritems(): if not gui_config.has_option(k, v): gui_config.set('downloadconfig', k, v) # Make sure we use the same ConfigParser instance for both Utility and DefaultDownloadStartupConfig. DefaultDownloadStartupConfig.getInstance().dlconfig = gui_config gui_config.write_file(configfilepath)
class Utility(object): def __init__(self, abcpath, configpath, app=None, session=None): self.version = version_id self.abcpath = abcpath # Find the directory to save config files, etc. self.dir_root = configpath self.setupConfig() # Is ABC in the process of shutting down? self.abcquitting = False self.app = app self.session = session def setupConfig(self): self.configfilepath = os.path.join(self.getConfigPath(), STATEDIR_GUICONFIG) self.config = CallbackConfigParser() # Load the config file. if os.path.exists(self.configfilepath): self.config.read_file(self.configfilepath, 'utf-8-sig') if not self.config.has_section('Tribler'): self.config.add_section('Tribler') # Tribler.conf also contains the default download config. So we need to merge it now. if not self.config.has_section('downloadconfig'): self.config.add_section('downloadconfig') for k, v in DefaultDownloadStartupConfig.getInstance().dlconfig._sections['downloadconfig'].iteritems(): self.config.set('downloadconfig', k, v) # Make sure we use the same ConfigParser instance for both Utility and DefaultDownloadStartupConfig. DefaultDownloadStartupConfig.getInstance().dlconfig = self.config def getVersion(self): return self.version def getConfigPath(self): return self.dir_root def getPath(self): return self.abcpath def set_session(self, session): self.session = session def set_app(self, app): self.app = app def read_config(self, option, section='Tribler', literal_eval=True): if not self.config.has_option(section, option): return tribler_defaults.get(section, {}).get(option, None) return self.config.get(section, option, literal_eval=literal_eval) def write_config(self, option, value, section='Tribler', flush=True): self.config.set(section, option, value) if flush: self.flush_config() def flush_config(self): self.config.write_file(self.configfilepath)
class Utility(object): def __init__(self, abcpath, configpath, app=None, session=None): self.version = version_id self.abcpath = abcpath # Find the directory to save config files, etc. self.dir_root = configpath self.setupConfig() # Is ABC in the process of shutting down? self.abcquitting = False self.app = app self.session = session def setupConfig(self): self.configfilepath = os.path.join(self.getConfigPath(), STATEDIR_GUICONFIG) self.config = CallbackConfigParser() # Load the config file. if os.path.exists(self.configfilepath): self.config.read_file(self.configfilepath, 'utf-8-sig') if not self.config.has_section('Tribler'): self.config.add_section('Tribler') # Tribler.conf also contains the default download config. So we need to merge it now. if not self.config.has_section('downloadconfig'): self.config.add_section('downloadconfig') for k, v in DefaultDownloadStartupConfig.getInstance( ).dlconfig._sections['downloadconfig'].iteritems(): self.config.set('downloadconfig', k, v) # Make sure we use the same ConfigParser instance for both Utility and DefaultDownloadStartupConfig. DefaultDownloadStartupConfig.getInstance().dlconfig = self.config def getVersion(self): return self.version def getConfigPath(self): return self.dir_root def getPath(self): return self.abcpath def set_session(self, session): self.session = session def set_app(self, app): self.app = app def read_config(self, option, section='Tribler', literal_eval=True): if not self.config.has_option(section, option): return tribler_defaults.get(section, {}).get(option, None) return self.config.get(section, option, literal_eval=literal_eval) def write_config(self, option, value, section='Tribler', flush=True): self.config.set(section, option, value) if flush: self.flush_config() def flush_config(self): self.config.write_file(self.configfilepath)