diff --git a/src/importer/importer.py b/src/importer/importer.py index c18e912..843da70 100644 --- a/src/importer/importer.py +++ b/src/importer/importer.py @@ -19,6 +19,7 @@ # SPDX-License-Identifier: GPL-3.0-or-later import logging +from time import time from typing import Any, Optional from gi.repository import Adw, Gio, GLib, Gtk @@ -55,6 +56,8 @@ class Importer(ErrorProducer): def __init__(self) -> None: super().__init__() + shared.import_time = int(time()) + # TODO: make this stateful shared.store.new_game_ids = set() shared.store.duplicate_game_ids = set() diff --git a/src/importer/sources/bottles_source.py b/src/importer/sources/bottles_source.py index 48d00ba..be33f6a 100644 --- a/src/importer/sources/bottles_source.py +++ b/src/importer/sources/bottles_source.py @@ -19,7 +19,6 @@ # SPDX-License-Identifier: GPL-3.0-or-later from pathlib import Path -from time import time from typing import NamedTuple import yaml @@ -38,13 +37,12 @@ class BottlesSourceIterable(SourceIterable): data = self.source.locations.data["library.yml"].read_text("utf-8") library: dict = yaml.safe_load(data) - added_time = int(time()) for entry in library.values(): # Build game values = { "source": self.source.source_id, - "added": added_time, + "added": shared.import_time, "name": entry["name"], "game_id": self.source.game_id_format.format(game_id=entry["id"]), "executable": self.source.make_executable( diff --git a/src/importer/sources/desktop_source.py b/src/importer/sources/desktop_source.py index 3a50dee..15465c6 100644 --- a/src/importer/sources/desktop_source.py +++ b/src/importer/sources/desktop_source.py @@ -21,7 +21,6 @@ import os import shlex import subprocess from pathlib import Path -from time import time from typing import NamedTuple from gi.repository import GLib, Gtk @@ -37,8 +36,6 @@ class DesktopSourceIterable(SourceIterable): def __iter__(self): """Generator method producing games""" - added_time = int(time()) - icon_theme = Gtk.IconTheme.new() search_paths = [ @@ -125,7 +122,7 @@ class DesktopSourceIterable(SourceIterable): values = { "source": self.source.source_id, - "added": added_time, + "added": shared.import_time, "name": name, "game_id": f"desktop_{entry.stem}", "executable": f"{launch_command} {launch_arg}", diff --git a/src/importer/sources/flatpak_source.py b/src/importer/sources/flatpak_source.py index bb7bf32..de5583d 100644 --- a/src/importer/sources/flatpak_source.py +++ b/src/importer/sources/flatpak_source.py @@ -18,7 +18,6 @@ # SPDX-License-Identifier: GPL-3.0-or-later from pathlib import Path -from time import time from typing import NamedTuple from gi.repository import GLib, Gtk @@ -35,8 +34,6 @@ class FlatpakSourceIterable(SourceIterable): def __iter__(self): """Generator method producing games""" - added_time = int(time()) - icon_theme = Gtk.IconTheme.new() icon_theme.add_search_path(str(self.source.locations.data["icons"])) @@ -79,7 +76,7 @@ class FlatpakSourceIterable(SourceIterable): values = { "source": self.source.source_id, - "added": added_time, + "added": shared.import_time, "name": name, "game_id": self.source.game_id_format.format(game_id=flatpak_id), "executable": self.source.make_executable(flatpak_id=flatpak_id), diff --git a/src/importer/sources/heroic_source.py b/src/importer/sources/heroic_source.py index b2ac629..eefa1ea 100644 --- a/src/importer/sources/heroic_source.py +++ b/src/importer/sources/heroic_source.py @@ -25,7 +25,6 @@ from functools import cached_property from hashlib import sha256 from json import JSONDecodeError from pathlib import Path -from time import time from typing import Iterable, NamedTuple, Optional, TypedDict from src import shared @@ -91,9 +90,7 @@ class SubSourceIterable(Iterable): logging.debug("Using Heroic %s library.json path %s", self.name, path) return path - def process_library_entry( - self, entry: HeroicLibraryEntry, added_time: int - ) -> SourceIterationResult: + def process_library_entry(self, entry: HeroicLibraryEntry) -> SourceIterationResult: """Build a Game from a Heroic library entry""" app_name = entry["app_name"] @@ -102,7 +99,7 @@ class SubSourceIterable(Iterable): # Build game values = { "source": f"{self.source.source_id}_{self.service}", - "added": added_time, + "added": shared.import_time, "name": entry["title"], "developer": entry.get("developer", None), "game_id": self.source.game_id_format.format( @@ -127,7 +124,7 @@ class SubSourceIterable(Iterable): Iterate through the games with a generator :raises InvalidLibraryFileError: on initial call if the library file is bad """ - added_time = int(time()) + try: iterator = iter( path_json_load(self.library_path)[self.library_json_entries_key] @@ -138,7 +135,7 @@ class SubSourceIterable(Iterable): ) from error for entry in iterator: try: - yield self.process_library_entry(entry, added_time) + yield self.process_library_entry(entry) except KeyError as error: logging.warning( "Skipped invalid %s game %s", @@ -176,7 +173,7 @@ class StoreSubSourceIterable(SubSourceIterable): def is_installed(self, app_name: str) -> bool: return app_name in self.installed_app_names - def process_library_entry(self, entry, added_time): + def process_library_entry(self, entry): # Skip games that are not installed app_name = entry["app_name"] if not self.is_installed(app_name): @@ -188,7 +185,7 @@ class StoreSubSourceIterable(SubSourceIterable): ) return None # Process entry as normal - return super().process_library_entry(entry, added_time) + return super().process_library_entry(entry) def __iter__(self): """ diff --git a/src/importer/sources/itch_source.py b/src/importer/sources/itch_source.py index 1f7e135..aa59803 100644 --- a/src/importer/sources/itch_source.py +++ b/src/importer/sources/itch_source.py @@ -20,7 +20,6 @@ from shutil import rmtree from sqlite3 import connect -from time import time from typing import NamedTuple from src import shared @@ -56,12 +55,10 @@ class ItchSourceIterable(SourceIterable): connection = connect(db_path) cursor = connection.execute(db_request) - added_time = int(time()) - # Create games from the db results for row in cursor: values = { - "added": added_time, + "added": shared.import_time, "source": self.source.source_id, "name": row[1], "game_id": self.source.game_id_format.format(game_id=row[0]), diff --git a/src/importer/sources/legendary_source.py b/src/importer/sources/legendary_source.py index bdf10e5..8a6dae0 100644 --- a/src/importer/sources/legendary_source.py +++ b/src/importer/sources/legendary_source.py @@ -20,7 +20,6 @@ import json import logging from json import JSONDecodeError -from time import time from typing import NamedTuple from src import shared @@ -36,9 +35,7 @@ from src.importer.sources.source import ( class LegendarySourceIterable(SourceIterable): source: "LegendarySource" - def game_from_library_entry( - self, entry: dict, added_time: int - ) -> SourceIterationResult: + def game_from_library_entry(self, entry: dict) -> SourceIterationResult: # Skip non-games if entry["is_dlc"]: return None @@ -46,7 +43,7 @@ class LegendarySourceIterable(SourceIterable): # Build game app_name = entry["app_name"] values = { - "added": added_time, + "added": shared.import_time, "source": self.source.source_id, "name": entry["title"], "game_id": self.source.game_id_format.format(game_id=app_name), @@ -78,12 +75,10 @@ class LegendarySourceIterable(SourceIterable): logging.warning("Couldn't open Legendary file: %s", str(file)) return - added_time = int(time()) - # Generate games from library for entry in library.values(): try: - result = self.game_from_library_entry(entry, added_time) + result = self.game_from_library_entry(entry) except KeyError as error: # Skip invalid games logging.warning( diff --git a/src/importer/sources/lutris_source.py b/src/importer/sources/lutris_source.py index 358f178..63d9df5 100644 --- a/src/importer/sources/lutris_source.py +++ b/src/importer/sources/lutris_source.py @@ -19,7 +19,6 @@ # SPDX-License-Identifier: GPL-3.0-or-later from shutil import rmtree from sqlite3 import connect -from time import time from typing import NamedTuple from src import shared @@ -56,13 +55,11 @@ class LutrisSourceIterable(SourceIterable): connection = connect(db_path) cursor = connection.execute(request, params) - added_time = int(time()) - # Create games from the DB results for row in cursor: # Create game values = { - "added": added_time, + "added": shared.import_time, "hidden": row[4], "name": row[1], "source": f"{self.source.source_id}_{row[3]}", diff --git a/src/importer/sources/retroarch_source.py b/src/importer/sources/retroarch_source.py index 93b6065..44d6f56 100644 --- a/src/importer/sources/retroarch_source.py +++ b/src/importer/sources/retroarch_source.py @@ -24,9 +24,7 @@ from hashlib import md5 from json import JSONDecodeError from pathlib import Path from shlex import quote as shell_quote -from time import time from typing import NamedTuple -from urllib.parse import quote as url_quote from src import shared from src.errors.friendly_error import FriendlyError @@ -54,7 +52,6 @@ class RetroarchSourceIterable(SourceIterable): raise KeyError(f"Key not found in RetroArch config: {key}") def __iter__(self): - added_time = int(time()) bad_playlists = set() config_file = self.source.locations.config["retroarch.cfg"] @@ -102,7 +99,7 @@ class RetroarchSourceIterable(SourceIterable): values = { "source": self.source.source_id, - "added": added_time, + "added": shared.import_time, "name": item["label"], "game_id": self.source.game_id_format.format(game_id=game_id), "executable": self.source.make_executable( diff --git a/src/importer/sources/steam_source.py b/src/importer/sources/steam_source.py index 19bb63e..6d7dec1 100644 --- a/src/importer/sources/steam_source.py +++ b/src/importer/sources/steam_source.py @@ -21,7 +21,6 @@ import logging import re from pathlib import Path -from time import time from typing import Iterable, NamedTuple from src import shared @@ -64,8 +63,6 @@ class SteamSourceIterable(SourceIterable): appid_cache = set() manifests = self.get_manifests() - added_time = int(time()) - for manifest in manifests: # Get metadata from manifest steam = SteamFileHelper() @@ -90,7 +87,7 @@ class SteamSourceIterable(SourceIterable): # Build game from local data values = { - "added": added_time, + "added": shared.import_time, "name": local_data["name"], "source": self.source.source_id, "game_id": self.source.game_id_format.format(game_id=appid), diff --git a/src/shared.py.in b/src/shared.py.in index 91e7b6d..c3b7a3c 100644 --- a/src/shared.py.in +++ b/src/shared.py.in @@ -52,5 +52,6 @@ image_size = (200 * scale_factor, 300 * scale_factor) # pylint: disable=invalid-name win = None importer = None +import_time = None store = None log_files = None diff --git a/src/window.py b/src/window.py index 52a27ea..5318897 100644 --- a/src/window.py +++ b/src/window.py @@ -258,7 +258,7 @@ class CartridgesWindow(Adw.ApplicationWindow): ).lower() if var != "name" and get_value(0) == get_value(1): - var, order = "name", True + var, order = "name", False return ((get_value(0) > get_value(1)) ^ order) * 2 - 1