Beispiel #1
0
 def _get_scummvm_arguments(self, gog_config_path):
     """Return a ScummVM configuration from the GOG config files"""
     with open(gog_config_path) as gog_config_file:
         gog_config = json.loads(gog_config_file.read())
     game_tasks = [
         task for task in gog_config["playTasks"]
         if task["category"] == "game"
     ]
     arguments = game_tasks[0]["arguments"]
     logger.info("ScummVM arguments from GOG: %s", arguments)
     if "-c " in arguments:
         config_path = arguments.split("\"")[1].replace("..\\", "")
         config_section = arguments.split()[-1]
     else:
         raise RuntimeError(
             "Unable to read config path from arguments: '%s'" % arguments)
     parser = EvilConfigParser(allow_no_value=True,
                               dict_type=MultiOrderedDict,
                               strict=False)
     parser.optionxform = str  # Preserve text case
     base_dir = os.path.dirname(gog_config_path)
     scummvm_config_path = os.path.join(base_dir, config_path)
     if not system.path_exists(scummvm_config_path):
         raise RuntimeError("ScummVM config file %s not found" %
                            scummvm_config_path)
     parser.read(scummvm_config_path)
     game_id = parser.get(config_section, "gameid")
     return {
         "game_id": game_id,
         "path": base_dir,
         "arguments": "-c \"%s\"" % config_path
     }
Beispiel #2
0
    def write_config(self, params):
        """Write a key-value pair into an INI type config file."""
        self._check_required_params(['file', 'section', 'key', 'value'],
                                    params, 'write_config')
        # Get file
        config_file = self._get_file(params['file'])
        if not config_file:
            config_file = self._substitute(params['file'])

        # Create it if necessary
        basedir = os.path.dirname(config_file)
        if not os.path.exists(basedir):
            os.makedirs(basedir)

        parser = EvilConfigParser(allow_no_value=True,
                                  dict_type=MultiOrderedDict,
                                  strict=False)
        parser.optionxform = str  # Preserve text case
        parser.read(config_file)

        value = self._substitute(params['value'])

        if not parser.has_section(params['section']):
            parser.add_section(params['section'])
        parser.set(params['section'], params['key'], value)

        with open(config_file, 'wb') as f:
            parser.write(f)
Beispiel #3
0
    def write_config(self, params):
        self._check_required_params(["file", "section", "key", "value"], params, "move")
        """Write a key-value pair into an INI type config file."""
        # Get file
        config_file = self._get_file(params["file"])
        if not config_file:
            config_file = self._substitute(params["file"])

        # Create it if necessary
        basedir = os.path.dirname(config_file)
        if not os.path.exists(basedir):
            os.makedirs(basedir)

        parser = EvilConfigParser(allow_no_value=True, dict_type=MultiOrderedDict)
        parser.optionxform = str  # Preserve text case
        parser.read(config_file)

        if not parser.has_section(params["section"]):
            parser.add_section(params["section"])
        parser.set(params["section"], params["key"], params["value"])

        with open(config_file, "wb") as f:
            parser.write(f)
Beispiel #4
0
    def write_config(self, params):
        """Writes a key-value pair into an INI type config file."""
        # Get file
        if 'file' not in params:
            raise ScriptingError('"file" parameter is mandatory for the '
                                 'write_conf command', params)
        config_file = self._get_file(params['file'])
        if not config_file:
            config_file = self._substitute(params['file'])

        # Create it if necessary
        basedir = os.path.dirname(config_file)
        if not os.path.exists(basedir):
            os.makedirs(basedir)

        parser = EvilConfigParser(allow_no_value=True,
                                  dict_type=MultiOrderedDict)
        parser.optionxform = str  # Preserve text case
        parser.read(config_file)

        if not parser.has_section(params['section']):
            parser.add_section(params['section'])
        parser.set(params['section'], params['key'], params['value'])

        with open(config_file, 'wb') as f:
            parser.write(f)
Beispiel #5
0
    def write_config(self, params):
        """Write a key-value pair into an INI type config file."""
        if params.get("data"):
            self._check_required_params(["file", "data"], params, "write_config")
        else:
            self._check_required_params(["file", "section", "key", "value"], params, "write_config")
        # Get file
        config_file_path = self._get_file(params["file"])

        # Create dir if necessary
        basedir = os.path.dirname(config_file_path)
        if not os.path.exists(basedir):
            os.makedirs(basedir)

        merge = params.get("merge", True)

        parser = EvilConfigParser(allow_no_value=True, dict_type=MultiOrderedDict, strict=False)
        parser.optionxform = str  # Preserve text case
        if merge:
            parser.read(config_file_path)

        data = {}
        if params.get("data"):
            data = params["data"]
        else:
            data[params["section"]] = {}
            data[params["section"]][params["key"]] = params["value"]

        for section, keys in data.items():
            if not parser.has_section(section):
                parser.add_section(section)
            for key, value in keys.items():
                value = self._substitute(value)
                parser.set(section, key, value)

        with open(config_file_path, "wb") as config_file:
            parser.write(config_file)
Beispiel #6
0
    def write_config(self, params):
        """Write a key-value pair into an INI type config file."""
        self._check_required_params(['file', 'section', 'key', 'value'],
                                    params, 'write_config')
        # Get file
        config_file_path = self._get_file(params['file'])

        # Create dir if necessary
        basedir = os.path.dirname(config_file_path)
        if not os.path.exists(basedir):
            os.makedirs(basedir)

        parser = EvilConfigParser(allow_no_value=True,
                                  dict_type=MultiOrderedDict,
                                  strict=False)
        parser.optionxform = str  # Preserve text case
        parser.read(config_file_path)

        value = self._substitute(params['value'])

        if not parser.has_section(params['section']):
            parser.add_section(params['section'])
        parser.set(params['section'], params['key'], value)

        with open(config_file_path, 'wb') as config_file:
            parser.write(config_file)
Beispiel #7
0
    def write_config(self, params):
        """Write a key-value pair into an INI type config file."""
        if params.get("data", None):
            self._check_required_params(["file", "data"], params, "write_config")
        else:
            self._check_required_params(
                ["file", "section", "key", "value"], params, "write_config"
            )
        # Get file
        config_file_path = self._get_file(params["file"])

        # Create dir if necessary
        basedir = os.path.dirname(config_file_path)
        if not os.path.exists(basedir):
            os.makedirs(basedir)

        merge = params.get("merge", True)

        parser = EvilConfigParser(
            allow_no_value=True, dict_type=MultiOrderedDict, strict=False
        )
        parser.optionxform = str  # Preserve text case
        if merge:
            parser.read(config_file_path)

        data = {}
        if params.get("data", None):
            data = params["data"]
        else:
            data[params["section"]] = {}
            data[params["section"]][params["key"]] = params["value"]

        for section, keys in data.items():
            if not parser.has_section(section):
                parser.add_section(section)
            for key, value in keys.items():
                value = self._substitute(value)
                parser.set(section, key, value)

        with open(config_file_path, "wb") as config_file:
            parser.write(config_file)
Beispiel #8
0
    def write_config(self, params):
        """Writes a key-value pair into an INI type config file."""
        # Get file
        if 'file' not in params:
            raise ScriptingError('"file" parameter is mandatory for the '
                                 'write_conf command', params)
        config_file = self._get_file(params['file'])
        if not config_file:
            config_file = self._substitute(params['file'])

        # Create it if necessary
        basedir = os.path.dirname(config_file)
        if not os.path.exists(basedir):
            os.makedirs(basedir)

        parser = EvilConfigParser(allow_no_value=True,
                                  dict_type=MultiOrderedDict)
        parser.optionxform = str  # Preserve text case
        parser.read(config_file)

        if not parser.has_section(params['section']):
            parser.add_section(params['section'])
        parser.set(params['section'], params['key'], params['value'])

        with open(config_file, 'wb') as f:
            parser.write(f)