From 52b6c47c8d805ffdd022261b95865dbc5ebcd2c1 Mon Sep 17 00:00:00 2001 From: GeoffreyCoulaud Date: Thu, 20 Jul 2023 10:58:23 +0200 Subject: [PATCH] More renaming to iterable + fixes to heroic --- src/importer/sources/bottles_source.py | 2 +- src/importer/sources/flatpak_source.py | 2 +- src/importer/sources/heroic_source.py | 40 +++++++++++------------- src/importer/sources/itch_source.py | 2 +- src/importer/sources/legendary_source.py | 2 +- src/importer/sources/lutris_source.py | 2 +- src/importer/sources/source.py | 4 +-- src/importer/sources/steam_source.py | 2 +- 8 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/importer/sources/bottles_source.py b/src/importer/sources/bottles_source.py index 22e071b..8829023 100644 --- a/src/importer/sources/bottles_source.py +++ b/src/importer/sources/bottles_source.py @@ -80,7 +80,7 @@ class BottlesSource(URLExecutableSource): """Generic Bottles source""" name = _("Bottles") - iterator_class = BottlesSourceIterable + iterable_class = BottlesSourceIterable url_format = 'bottles:run/"{bottle_name}"/"{game_name}"' available_on = {"linux"} diff --git a/src/importer/sources/flatpak_source.py b/src/importer/sources/flatpak_source.py index 2c52dab..2c9a4aa 100644 --- a/src/importer/sources/flatpak_source.py +++ b/src/importer/sources/flatpak_source.py @@ -115,7 +115,7 @@ class FlatpakSource(Source): """Generic Flatpak source""" name = _("Flatpak") - iterator_class = FlatpakSourceIterable + iterable_class = FlatpakSourceIterable executable_format = "flatpak run {flatpak_id}" available_on = {"linux"} diff --git a/src/importer/sources/heroic_source.py b/src/importer/sources/heroic_source.py index bb2c053..3e53787 100644 --- a/src/importer/sources/heroic_source.py +++ b/src/importer/sources/heroic_source.py @@ -69,20 +69,20 @@ class HeroicLibraryEntry(TypedDict): art_square: str -class SubSource(Iterable): +class SubSourceIterable(Iterable): """Class representing a Heroic sub-source""" source: "HeroicSource" - source_iterator: "HeroicSourceIterable" + source_iterable: "HeroicSourceIterable" name: str service: str image_uri_params: str = "" relative_library_path: Path library_json_entries_key: str = "library" - def __init__(self, source, source_iterator) -> None: + def __init__(self, source, source_iterable) -> None: self.source = source - self.source_iterator = source_iterator + self.source_iterable = source_iterable @property def library_path(self) -> Path: @@ -105,7 +105,7 @@ class SubSource(Iterable): service=self.service, game_id=app_name ), "executable": self.source.executable_format.format(app_name=app_name), - "hidden": self.source_iterator.is_hidden(app_name), + "hidden": self.source_iterable.is_hidden(app_name), } game = Game(values) @@ -120,7 +120,7 @@ class SubSource(Iterable): def __iter__(self): """ - Iterate through the installed games with a generator + Iterate through the games with a generator :raises InvalidLibraryFileError: on initial call if the library file is bad """ added_time = int(time()) @@ -145,13 +145,13 @@ class SubSource(Iterable): continue -class StoreSubSource(SubSource): +class StoreSubSourceIterable(SubSourceIterable): """ - Class representing a "store" sub source iterator. + Class representing a "store" sub source. Games can be installed or not, this class does the check accordingly. """ - relative_installed_path: Optional[Path] + relative_installed_path: Path installed_app_names: set[str] @property @@ -194,28 +194,27 @@ class StoreSubSource(SubSource): yield from super().__iter__() -class SideloadIterable(SubSource): +class SideloadIterable(SubSourceIterable): name = "sideload" service = "sideload" relative_library_path = Path("sideload_apps") / "library.json" -class LegendaryIterable(StoreSubSource): +class LegendaryIterable(StoreSubSourceIterable): name = "legendary" service = "epic" image_uri_params = "?h=400&resize=1&w=300" relative_library_path = Path("store_cache") / "legendary_library.json" # TODO simplify Heroic 2.9 has been out for a while - # (uncomment value and remove the library_path property override) + # (uncomment value and remove the installed_path property override) # # relative_installed_path = ( # Path("legendary") / "legendaryConfig" / "legendary" / "installed.json" # ) - relative_installed_path = None @property - def library_path(self) -> Path: + def installed_path(self) -> Path: """Get the right path depending on the Heroic version""" heroic_config_path = self.source.config_location.root if (path := heroic_config_path / "legendaryConfig").is_dir(): @@ -243,7 +242,7 @@ class LegendaryIterable(StoreSubSource): ) from error -class GogIterable(StoreSubSource): +class GogIterable(StoreSubSourceIterable): name = "gog" service = "gog" library_json_entries_key = "games" @@ -263,7 +262,7 @@ class GogIterable(StoreSubSource): ) from error -class NileIterable(StoreSubSource): +class NileIterable(StoreSubSourceIterable): name = "nile" service = "amazon" relative_library_path = Path("store_cache") / "nile_library.json" @@ -316,24 +315,23 @@ class HeroicSourceIterable(SourceIterable): if not shared.schema.get_boolean("heroic-import-" + sub_source.service): logging.debug("Skipping Heroic %s: disabled", sub_source.service) continue - try: - sub_source_iterator = iter(sub_source) + sub_source_iterable = iter(sub_source) + yield from sub_source_iterable except (InvalidLibraryFileError, InvalidInstalledFileError) as error: logging.error( "Skipping bad Heroic sub-source %s", sub_source.service, exc_info=error, ) - - yield from sub_source_iterator + continue class HeroicSource(URLExecutableSource): """Generic Heroic Games Launcher source""" name = _("Heroic") - iterator_class = HeroicSourceIterable + iterable_class = HeroicSourceIterable url_format = "heroic://launch/{app_name}" available_on = {"linux", "win32"} diff --git a/src/importer/sources/itch_source.py b/src/importer/sources/itch_source.py index b6c0ad3..a6d8990 100644 --- a/src/importer/sources/itch_source.py +++ b/src/importer/sources/itch_source.py @@ -76,7 +76,7 @@ class ItchSourceIterable(SourceIterable): class ItchSource(URLExecutableSource): name = _("itch") - iterator_class = ItchSourceIterable + iterable_class = ItchSourceIterable url_format = "itch://caves/{cave_id}/launch" available_on = {"linux", "win32"} diff --git a/src/importer/sources/legendary_source.py b/src/importer/sources/legendary_source.py index 72eae35..c7e06de 100644 --- a/src/importer/sources/legendary_source.py +++ b/src/importer/sources/legendary_source.py @@ -93,7 +93,7 @@ class LegendarySource(Source): executable_format = "legendary launch {app_name}" available_on = {"linux"} - iterator_class = LegendarySourceIterable + iterable_class = LegendarySourceIterable config_location: Location = Location( schema_key="legendary-location", candidates=( diff --git a/src/importer/sources/lutris_source.py b/src/importer/sources/lutris_source.py index 8696aef..7c100a8 100644 --- a/src/importer/sources/lutris_source.py +++ b/src/importer/sources/lutris_source.py @@ -87,7 +87,7 @@ class LutrisSource(URLExecutableSource): """Generic Lutris source""" name = _("Lutris") - iterator_class = LutrisSourceIterable + iterable_class = LutrisSourceIterable url_format = "lutris:rungameid/{game_id}" available_on = {"linux"} diff --git a/src/importer/sources/source.py b/src/importer/sources/source.py index 383dc1c..d7ba467 100644 --- a/src/importer/sources/source.py +++ b/src/importer/sources/source.py @@ -57,7 +57,7 @@ class Source(Iterable): data_location: Optional[Location] = None cache_location: Optional[Location] = None config_location: Optional[Location] = None - iterator_class: type[SourceIterable] + iterable_class: type[SourceIterable] @property def full_name(self) -> str: @@ -99,7 +99,7 @@ class Source(Iterable): if location is None: continue location.resolve() - return iter(self.iterator_class(self)) + return iter(self.iterable_class(self)) # pylint: disable=abstract-method diff --git a/src/importer/sources/steam_source.py b/src/importer/sources/steam_source.py index 040edcb..7e65e5b 100644 --- a/src/importer/sources/steam_source.py +++ b/src/importer/sources/steam_source.py @@ -112,7 +112,7 @@ class SteamSourceIterable(SourceIterable): class SteamSource(URLExecutableSource): name = _("Steam") available_on = {"linux", "win32"} - iterator_class = SteamSourceIterable + iterable_class = SteamSourceIterable url_format = "steam://rungameid/{game_id}" data_location = Location(