Merge pull request #179 from kra-mo/geoffreys-dev-branch

Improvements to game executable + better handling of corrupted log files
This commit is contained in:
Geoffrey Coulaud
2023-08-27 14:16:59 +02:00
committed by GitHub
9 changed files with 28 additions and 25 deletions

View File

@@ -47,8 +47,9 @@ class BottlesSourceIterable(SourceIterable):
"added": added_time,
"name": entry["name"],
"game_id": self.source.game_id_format.format(game_id=entry["id"]),
"executable": self.source.executable_format.format(
bottle_name=entry["bottle"]["name"], game_name=entry["name"]
"executable": self.source.make_executable(
bottle_name=entry["bottle"]["name"],
game_name=entry["name"],
),
}
game = Game(values)

View File

@@ -82,9 +82,7 @@ class FlatpakSourceIterable(SourceIterable):
"added": added_time,
"name": name,
"game_id": self.source.game_id_format.format(game_id=flatpak_id),
"executable": self.source.executable_format.format(
flatpak_id=flatpak_id
),
"executable": self.source.make_executable(flatpak_id=flatpak_id),
}
game = Game(values)

View File

@@ -108,9 +108,7 @@ class SubSourceIterable(Iterable):
"game_id": self.source.game_id_format.format(
service=self.service, game_id=app_name
),
"executable": self.source.executable_format.format(
runner=runner, app_name=app_name
),
"executable": self.source.make_executable(runner=runner, app_name=app_name),
"hidden": self.source_iterable.is_hidden(app_name),
}
game = Game(values)

View File

@@ -65,7 +65,7 @@ class ItchSourceIterable(SourceIterable):
"source": self.source.source_id,
"name": row[1],
"game_id": self.source.game_id_format.format(game_id=row[0]),
"executable": self.source.executable_format.format(cave_id=row[4]),
"executable": self.source.make_executable(cave_id=row[4]),
}
additional_data = {"online_cover_url": row[3] or row[2]}
game = Game(values)

View File

@@ -28,8 +28,8 @@ from src.game import Game
from src.importer.sources.location import Location, LocationSubPath
from src.importer.sources.source import (
ExecutableFormatSource,
SourceIterationResult,
SourceIterable,
SourceIterationResult,
)
@@ -50,7 +50,7 @@ class LegendarySourceIterable(SourceIterable):
"source": self.source.source_id,
"name": entry["title"],
"game_id": self.source.game_id_format.format(game_id=app_name),
"executable": self.source.executable_format.format(app_name=app_name),
"executable": self.source.make_executable(app_name=app_name),
}
data = {}

View File

@@ -69,7 +69,7 @@ class LutrisSourceIterable(SourceIterable):
"game_id": self.source.game_id_format.format(
runner=row[3], game_id=row[0]
),
"executable": self.source.executable_format.format(game_id=row[0]),
"executable": self.source.make_executable(game_id=row[0]),
}
game = Game(values)

View File

@@ -104,7 +104,7 @@ class ExecutableFormatSource(Source):
def make_executable(self, *args, **kwargs) -> str:
"""Use the executable format to"""
return self.executable_format.format(args, kwargs)
return self.executable_format.format(*args, **kwargs)
# pylint: disable=abstract-method

View File

@@ -94,7 +94,7 @@ class SteamSourceIterable(SourceIterable):
"name": local_data["name"],
"source": self.source.source_id,
"game_id": self.source.game_id_format.format(game_id=appid),
"executable": self.source.executable_format.format(game_id=appid),
"executable": self.source.make_executable(game_id=appid),
}
game = Game(values)

View File

@@ -89,18 +89,24 @@ class SessionFileHandler(StreamHandler):
# If uncompressed, compress
if not path.name.endswith(".xz"):
try:
with open(path, "r", encoding="utf-8") as original_file:
original_data = original_file.read()
except UnicodeDecodeError:
# If the file is corrupted, throw it away
path.unlink()
return
# Compress the file
compressed_path = path.with_suffix(path.suffix + ".xz")
with (
lzma.open(
with lzma.open(
compressed_path,
"wt",
format=FORMAT_XZ,
preset=PRESET_DEFAULT,
encoding="utf-8",
) as lzma_file,
open(path, "r", encoding="utf-8") as original_file,
):
lzma_file.write(original_file.read())
) as lzma_file:
lzma_file.write(original_data)
path.unlink()
path = compressed_path