More renaming to iterable + fixes to heroic

This commit is contained in:
GeoffreyCoulaud
2023-07-20 10:58:23 +02:00
parent 0df123975c
commit 52b6c47c8d
8 changed files with 27 additions and 29 deletions

View File

@@ -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"}

View File

@@ -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"}

View File

@@ -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"}

View File

@@ -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"}

View File

@@ -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=(

View File

@@ -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"}

View File

@@ -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

View File

@@ -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(