Ejemplo n.º 1
0
async def test_prepare_get_local_size_context_error(plugin, read, write):
    request_id = "31415"
    error_details = {"Details": "Unexpected syntax"}
    error_message, error_code = FailedParsingManifest(
    ).message, FailedParsingManifest().code
    plugin.prepare_local_size_context.side_effect = FailedParsingManifest(
        data=error_details)
    request = {
        "jsonrpc": "2.0",
        "id": request_id,
        "method": "start_local_size_import",
        "params": {
            "game_ids": ["6"]
        }
    }
    read.side_effect = [
        async_return_value(create_message(request)),
        async_return_value(b"", 10)
    ]
    await plugin.run()
    assert get_messages(write) == [{
        "jsonrpc": "2.0",
        "id": request_id,
        "error": {
            "code": error_code,
            "message": error_message,
            "data": {
                "internal_type": "FailedParsingManifest",
                "Details": "Unexpected syntax"
            }
        }
    }]
def get_local_games_manifests(manifests_stats):
    manifests = []
    for filename in manifests_stats.keys():
        try:
            manifests.append(_parse_msft_file(filename))
        except Exception as e:
            logging.exception("Failed to parse file {}".format(filename))
            raise FailedParsingManifest({"file": filename, "exception": e})

    return manifests
Ejemplo n.º 3
0
def _parse_msft_file(filepath):
    with open(filepath, encoding="utf-8") as file:
        data = file.read()
    parsed_url = urllib.parse.urlparse(data)
    parsed_data = dict(urllib.parse.parse_qsl(parsed_url.query))
    try:
        game_id = parsed_data["id"]
    except KeyError as e:
        raise FailedParsingManifest({
            "file": filepath,
            "exception": e,
            "parsed_data": parsed_data
        })
    state = _State[parsed_data.get("currentstate", "<missing currentstate>")]
    prev_state = _State[parsed_data.get("previousstate",
                                        "<missing previousstate>")]
    ddinstallalreadycompleted = parsed_data.get("ddinstallalreadycompleted",
                                                "0")
    dipinstallpath = parsed_data.get("dipinstallpath", "")
    ddinitialdownload = parsed_data.get("ddinitialdownload", "0")

    return _Manifest(game_id, state, prev_state, ddinstallalreadycompleted,
                     dipinstallpath, ddinitialdownload)
 async def get_local_size(self, game_id, context) -> int:
     try:
         game_manifest = context[game_id]
         return int(game_manifest['InstallSize'])
     except (KeyError, ValueError) as e:
         raise FailedParsingManifest(repr(e))