Coverage for lutris.config : 48%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/bin/python # -*- coding:Utf-8 -*- # # Copyright (C) 2010 Mathieu Comandon <strider@strycore.com> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. #
""" Register the lutris: protocol to open with the application. """ logger.debug("registering protocol") executable = os.path.abspath(sys.argv[0]) base_key = "desktop.gnome.url-handlers.lutris" schema_directory = "/usr/share/glib-2.0/schemas/" schema_source = Gio.SettingsSchemaSource.new_from_directory( schema_directory, None, True ) schema = schema_source.lookup(base_key, True) if schema: settings = Gio.Settings.new(base_key) settings.set_string('command', executable) else: logger.warning("Schema not installed, cannot register url-handler")
"""Check if initial configuration is correct.""" directories = [CONFIG_DIR, join(CONFIG_DIR, "runners"), join(CONFIG_DIR, "games"), DATA_DIR, join(DATA_DIR, "covers"), join(DATA_DIR, "icons"), join(DATA_DIR, "banners"), join(DATA_DIR, "runners"), join(DATA_DIR, "lib"), CACHE_DIR, join(CACHE_DIR, "installer"), join(CACHE_DIR, "tmp")] for directory in directories: if not os.path.exists(directory): logger.debug("creating directory %s" % directory) os.mkdir(directory)
if force_wipe: os.remove(PGA_DB) pga.syncdb()
"""Read filename and return parsed yaml"""
"""Class where all the configuration handling happens.
Lutris configuration uses a cascading mecanism where each higher, more specific level override the lower ones.
The config files are stored in a YAML format and are easy to edit manually.
""" #Initialize configuration
#By default config type is system, it can also be runner and game #this means that when you call lutris_config_instance["key"] it will #pick up the right configuration depending of config_type self.config_type = "game" else:
#Read system configuration "system.yml")) "runners/%s.yml" % runner)) else: if os.path.exists(game_config_path): self.game_config = read_yaml_from_file(game_config_path) self.runner = self.game_config.get("runner")
"""Allow to access config data directly by keys.""" if key in ('game', 'runner', 'system'): return self.config[key] try: if self.config_type == "game": value = self.game_config[key] elif self.config_type == "runner": value = self.runner_config[key] else: value = self.system_config[key] except KeyError: value = default return value
self.game_config[key] = value elif self.config_type == "runner": self.runner_config[key] = value elif self.config_type == "system": self.system_config = value self.update_global_config()
def game_config_file(self): return join(CONFIG_DIR, "games/%s.yml" % self.game)
"""Return the value of 'key' for system config""" try: value = self.config["system"][key] if str(value).lower() in ("false", "none", "no"): value = False except KeyError: value = None return value
"""Update the global config dict.""" else: self.config[key] = self.system_config[key]
else:
if type(self.config[key]) is dict: self.config[key].update(self.game_config[key]) else: self.config[key] = self.game_config[key]
"""Return name of game""" name = self.config["realname"] return name
"""Delete the configuration file from disk.""" if game is None: game = self.game logging.debug("removing config for %s", game) if os.path.exists(self.game_config_file): os.remove(self.game_config_file) else: logger.debug("No config file at %s" % self.game_config_file)
"""Check the config data and return True if config is ok.""" return "runner" in self.game_config
"""Save configuration file
The way to save config files can be set by the type argument or with self.config_type """
self.update_global_config() logging.debug("Saving config (type %s)", config_type) logging.debug(self.config) if config_type is None: config_type = self.config_type yaml_config = yaml.dump(self.config, default_flow_style=False)
if config_type == "system": filename = join(CONFIG_DIR, "system.yml") self.write_to_disk(filename, yaml_config) elif config_type == "runner": runner_config_path = join(CONFIG_DIR, "runners/%s.yml" % self.runner) self.write_to_disk(runner_config_path, yaml_config)
elif config_type == "game": if not self.game: self.game = slugify(self.config['realname']) self.write_to_disk(self.game_config_file, yaml_config) return self.game else: print("Config type is %s or %s" % (self.config_type, type)) print("i don't know how to save this yet")
filehandler.write(content)
"""Get the path to install games for a given runner.
Return False if it can't find an installation path """
else: return default |