def readConfig(self, config, section, required_fields, optional_fields): cfg = Settings(config) if not cfg.load(section, required_fields, optional_fields): sys.exit(1) if "log_level" in required_fields: numeric_level = getattr(logging, cfg.log_level.upper(), None) if not isinstance(numeric_level, int): logging.error('Invalid log_level in config: %s' % cfg.log_level) sys.exit(1) cfg.log_level = numeric_level return cfg
def loadSettings(self): # load user settings user_dir = expanduser("~") try: cfg = Settings(join(user_dir, ".danbooru-daemon.cfg")) cfg.load("default", ['download_path'], {'dbname': None}) # Get the base path for image search self.BASE_DIR = cfg.download_path if not cfg.dbname: daemon_dir = join(user_dir, ".local/share/danbooru-daemon") cfg.dbname = join(daemon_dir, "danbooru-db.sqlite") self.db = Database(join(daemon_dir, cfg.dbname)) except DanbooruError: self.statusLabel.setText(self.tr("No config loaded")) self.searchButton.setEnabled(False) self.queryBox.returnPressed.disconnect(self.startSearch)