diff --git a/src/importer/sources/bottles_source.py b/src/importer/sources/bottles_source.py index 5769077..48d00ba 100644 --- a/src/importer/sources/bottles_source.py +++ b/src/importer/sources/bottles_source.py @@ -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) diff --git a/src/importer/sources/flatpak_source.py b/src/importer/sources/flatpak_source.py index c0840f2..bb7bf32 100644 --- a/src/importer/sources/flatpak_source.py +++ b/src/importer/sources/flatpak_source.py @@ -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) diff --git a/src/importer/sources/heroic_source.py b/src/importer/sources/heroic_source.py index 6b8002b..b2ac629 100644 --- a/src/importer/sources/heroic_source.py +++ b/src/importer/sources/heroic_source.py @@ -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) diff --git a/src/importer/sources/itch_source.py b/src/importer/sources/itch_source.py index e39d090..1f7e135 100644 --- a/src/importer/sources/itch_source.py +++ b/src/importer/sources/itch_source.py @@ -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) diff --git a/src/importer/sources/legendary_source.py b/src/importer/sources/legendary_source.py index bfaaa66..bdf10e5 100644 --- a/src/importer/sources/legendary_source.py +++ b/src/importer/sources/legendary_source.py @@ -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 = {} diff --git a/src/importer/sources/lutris_source.py b/src/importer/sources/lutris_source.py index 5e00ee5..358f178 100644 --- a/src/importer/sources/lutris_source.py +++ b/src/importer/sources/lutris_source.py @@ -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) diff --git a/src/importer/sources/source.py b/src/importer/sources/source.py index 4f6be55..c1c0522 100644 --- a/src/importer/sources/source.py +++ b/src/importer/sources/source.py @@ -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 diff --git a/src/importer/sources/steam_source.py b/src/importer/sources/steam_source.py index 3d10aa4..19bb63e 100644 --- a/src/importer/sources/steam_source.py +++ b/src/importer/sources/steam_source.py @@ -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) diff --git a/src/logging/session_file_handler.py b/src/logging/session_file_handler.py index a6f46b3..d207e29 100644 --- a/src/logging/session_file_handler.py +++ b/src/logging/session_file_handler.py @@ -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( - 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()) + with lzma.open( + compressed_path, + "wt", + format=FORMAT_XZ, + preset=PRESET_DEFAULT, + encoding="utf-8", + ) as lzma_file: + lzma_file.write(original_data) path.unlink() path = compressed_path