-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
291 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from typing import Dict | ||
|
||
from humblegame import DownloadStruct, HumbleGame, TroveGame, Subproduct, SubproductDownload, TroveDownload, DownloadStruct | ||
from consts import CURRENT_SYSTEM, PlatformNotSupported, TP_PLATFORM | ||
|
||
|
||
class HumbleDownloadResolver: | ||
"""Prepares downloads for specific conditionals""" | ||
def __init__(self, target_platform=CURRENT_SYSTEM, target_bitness=None): | ||
self.platform = target_platform | ||
self.bitness = target_bitness | ||
|
||
def __call__(self, game: HumbleGame) -> DownloadStruct: | ||
if isinstance(game, TroveGame): | ||
return self._find_best_trove_download(game) | ||
elif isinstance(game, Subproduct): | ||
return self._find_best_subproduct_download(game) | ||
|
||
def _find_best_trove_download(self, game: TroveGame) -> TroveDownload: | ||
try: | ||
return game.downloads[self.platform] | ||
except KeyError as e: | ||
self.__platform_not_supporter_handler() | ||
|
||
def _find_best_subproduct_download(self, game: Subproduct) -> SubproductDownload: | ||
try: | ||
system_downloads = game.downloads[self.platform] | ||
except KeyError: | ||
self.__platform_not_supporter_handler() | ||
|
||
assert len(system_downloads) > 0 | ||
|
||
if len(system_downloads) == 1: | ||
return system_downloads[0] | ||
else: | ||
download_items = list(filter(lambda x: x.name == 'Download', download_struct)) | ||
|
||
if len(download_items) == 1: | ||
return download_items[0] | ||
else: | ||
raise NotImplementedError(f'Found downloads: {len(download_items)}. All: {downloads}') | ||
|
||
def __platform_not_supporter_handler(self, game): | ||
raise PlatformNotSupported(f'{self.human_name} has only downloads for [{game.downloads.keys()}]') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.1.2" | ||
__version__ = "0.2.0" |
Oops, something went wrong.