🚧 More fixes
This commit is contained in:
@@ -3,6 +3,7 @@ import logging
|
|||||||
from gi.repository import Adw, Gio, Gtk
|
from gi.repository import Adw, Gio, Gtk
|
||||||
from requests import HTTPError
|
from requests import HTTPError
|
||||||
|
|
||||||
|
import src.shared as shared
|
||||||
from src.utils.create_dialog import create_dialog
|
from src.utils.create_dialog import create_dialog
|
||||||
from src.utils.steamgriddb import SGDBAuthError, SGDBError, SGDBHelper
|
from src.utils.steamgriddb import SGDBAuthError, SGDBError, SGDBHelper
|
||||||
from src.utils.task import Task
|
from src.utils.task import Task
|
||||||
@@ -16,7 +17,6 @@ class Importer:
|
|||||||
import_statuspage = None
|
import_statuspage = None
|
||||||
import_dialog = None
|
import_dialog = None
|
||||||
|
|
||||||
win = None
|
|
||||||
sources = None
|
sources = None
|
||||||
|
|
||||||
n_games_added = 0
|
n_games_added = 0
|
||||||
@@ -27,8 +27,7 @@ class Importer:
|
|||||||
sgdb_cancellable = None
|
sgdb_cancellable = None
|
||||||
sgdb_error = None
|
sgdb_error = None
|
||||||
|
|
||||||
def __init__(self, win):
|
def __init__(self):
|
||||||
self.win = win
|
|
||||||
self.sources = set()
|
self.sources = set()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -82,7 +81,7 @@ class Importer:
|
|||||||
modal=True,
|
modal=True,
|
||||||
default_width=350,
|
default_width=350,
|
||||||
default_height=-1,
|
default_height=-1,
|
||||||
transient_for=self.win,
|
transient_for=shared.win,
|
||||||
deletable=False,
|
deletable=False,
|
||||||
)
|
)
|
||||||
self.import_dialog.present()
|
self.import_dialog.present()
|
||||||
@@ -123,14 +122,14 @@ class Importer:
|
|||||||
|
|
||||||
# Avoid duplicates
|
# Avoid duplicates
|
||||||
if (
|
if (
|
||||||
game.game_id in self.win.games
|
game.game_id in shared.win.games
|
||||||
and not self.win.games[game.game_id].removed
|
and not shared.win.games[game.game_id].removed
|
||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Register game
|
# Register game
|
||||||
logging.info("New game registered %s (%s)", game.name, game.game_id)
|
logging.info("New game registered %s (%s)", game.name, game.game_id)
|
||||||
self.win.games[game.game_id] = game
|
shared.win.games[game.game_id] = game
|
||||||
game.save()
|
game.save()
|
||||||
self.n_games_added += 1
|
self.n_games_added += 1
|
||||||
|
|
||||||
@@ -156,7 +155,7 @@ class Importer:
|
|||||||
"""SGDB query code"""
|
"""SGDB query code"""
|
||||||
game, *_rest = data
|
game, *_rest = data
|
||||||
game.set_loading(1)
|
game.set_loading(1)
|
||||||
sgdb = SGDBHelper(self.win)
|
sgdb = SGDBHelper()
|
||||||
try:
|
try:
|
||||||
sgdb.conditionaly_update_cover(game)
|
sgdb.conditionaly_update_cover(game)
|
||||||
except SGDBAuthError as error:
|
except SGDBAuthError as error:
|
||||||
@@ -208,12 +207,12 @@ class Importer:
|
|||||||
# The variable is the number of games
|
# The variable is the number of games
|
||||||
toast.set_title(_("{} games imported").format(self.n_games_added))
|
toast.set_title(_("{} games imported").format(self.n_games_added))
|
||||||
|
|
||||||
self.win.toast_overlay.add_toast(toast)
|
shared.win.toast_overlay.add_toast(toast)
|
||||||
|
|
||||||
def create_sgdb_error_dialog(self):
|
def create_sgdb_error_dialog(self):
|
||||||
"""SGDB error dialog"""
|
"""SGDB error dialog"""
|
||||||
create_dialog(
|
create_dialog(
|
||||||
self.win,
|
shared.win,
|
||||||
_("Couldn't Connect to SteamGridDB"),
|
_("Couldn't Connect to SteamGridDB"),
|
||||||
str(self.sgdb_error),
|
str(self.sgdb_error),
|
||||||
"open_preferences",
|
"open_preferences",
|
||||||
@@ -221,7 +220,7 @@ class Importer:
|
|||||||
).connect("response", self.dialog_response_callback, "sgdb")
|
).connect("response", self.dialog_response_callback, "sgdb")
|
||||||
|
|
||||||
def open_preferences(self, page=None, expander_row=None):
|
def open_preferences(self, page=None, expander_row=None):
|
||||||
self.win.get_application().on_preferences_action(
|
shared.win.get_application().on_preferences_action(
|
||||||
page_name=page, expander_row=expander_row
|
page_name=page, expander_row=expander_row
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ from collections.abc import Iterable, Iterator, Sized
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from src.game import Game
|
from src.game import Game
|
||||||
from src.window import CartridgesWindow
|
|
||||||
|
|
||||||
|
|
||||||
class SourceIterator(Iterator, Sized):
|
class SourceIterator(Iterator, Sized):
|
||||||
@@ -33,14 +32,9 @@ class SourceIterator(Iterator, Sized):
|
|||||||
class Source(Iterable):
|
class Source(Iterable):
|
||||||
"""Source of games. E.g an installed app with a config file that lists game directories"""
|
"""Source of games. E.g an installed app with a config file that lists game directories"""
|
||||||
|
|
||||||
win: "CartridgesWindow" = None
|
|
||||||
name: str
|
name: str
|
||||||
variant: str
|
variant: str
|
||||||
|
|
||||||
def __init__(self, win) -> None:
|
|
||||||
super().__init__()
|
|
||||||
self.win = win
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def full_name(self) -> str:
|
def full_name(self) -> str:
|
||||||
"""The source's full name"""
|
"""The source's full name"""
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from sqlite3 import connect
|
|||||||
from time import time
|
from time import time
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
import src.shared as shared
|
||||||
from src.game import Game
|
from src.game import Game
|
||||||
from src.importer.source import Source, SourceIterator
|
from src.importer.source import Source, SourceIterator
|
||||||
from src.utils.decorators import replaced_by_path, replaced_by_schema_key
|
from src.utils.decorators import replaced_by_path, replaced_by_schema_key
|
||||||
@@ -41,7 +42,7 @@ class LutrisSourceIterator(SourceIterator):
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.import_steam = self.source.win.schema.get_boolean("lutris-import-steam")
|
self.import_steam = shared.schema.get_boolean("lutris-import-steam")
|
||||||
self.db_location = self.source.location / "pga.db"
|
self.db_location = self.source.location / "pga.db"
|
||||||
self.db_connection = connect(self.db_location)
|
self.db_connection = connect(self.db_location)
|
||||||
self.db_request_params = {"import_steam": self.import_steam}
|
self.db_request_params = {"import_steam": self.import_steam}
|
||||||
@@ -77,13 +78,12 @@ class LutrisSourceIterator(SourceIterator):
|
|||||||
"executable": self.source.executable_format.format(game_id=row[2]),
|
"executable": self.source.executable_format.format(game_id=row[2]),
|
||||||
"developer": None, # TODO get developer metadata on Lutris
|
"developer": None, # TODO get developer metadata on Lutris
|
||||||
}
|
}
|
||||||
game = Game(self.source.win, values, allow_side_effects=False)
|
game = Game(values, allow_side_effects=False)
|
||||||
|
|
||||||
# Save official image
|
# Save official image
|
||||||
image_path = self.source.location / "covers" / "coverart" / f"{row[2]}.jpg"
|
image_path = self.source.location / "covers" / "coverart" / f"{row[2]}.jpg"
|
||||||
if image_path.exists():
|
if image_path.exists():
|
||||||
resized = resize_cover(self.source.win, image_path)
|
save_cover(values["game_id"], resize_cover(image_path))
|
||||||
save_cover(self.source.win, values["game_id"], resized)
|
|
||||||
|
|
||||||
return game
|
return game
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class SteamSourceIterator(SourceIterator):
|
|||||||
"game_id": self.source.game_id_format.format(game_id=appid),
|
"game_id": self.source.game_id_format.format(game_id=appid),
|
||||||
"executable": self.source.executable_format.format(game_id=appid),
|
"executable": self.source.executable_format.format(game_id=appid),
|
||||||
}
|
}
|
||||||
game = Game(self.source.win, values, allow_side_effects=False)
|
game = Game(values, allow_side_effects=False)
|
||||||
|
|
||||||
# Add official cover image
|
# Add official cover image
|
||||||
cover_path = (
|
cover_path = (
|
||||||
@@ -94,9 +94,7 @@ class SteamSourceIterator(SourceIterator):
|
|||||||
/ f"{appid}_library_600x900.jpg"
|
/ f"{appid}_library_600x900.jpg"
|
||||||
)
|
)
|
||||||
if cover_path.is_file():
|
if cover_path.is_file():
|
||||||
save_cover(
|
save_cover(game.game_id, resize_cover(cover_path))
|
||||||
self.source.win, game.game_id, resize_cover(self.source.win, cover_path)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Get online metadata
|
# Get online metadata
|
||||||
# TODO move to its own manager
|
# TODO move to its own manager
|
||||||
|
|||||||
16
src/main.py
16
src/main.py
@@ -157,14 +157,14 @@ class CartridgesApplication(Adw.Application):
|
|||||||
DetailsWindow()
|
DetailsWindow()
|
||||||
|
|
||||||
def on_import_action(self, *_args):
|
def on_import_action(self, *_args):
|
||||||
importer = Importer(self.win)
|
importer = Importer()
|
||||||
if self.win.schema.get_boolean("lutris"):
|
if shared.schema.get_boolean("lutris"):
|
||||||
importer.add_source(LutrisNativeSource(self.win))
|
importer.add_source(LutrisNativeSource())
|
||||||
importer.add_source(LutrisFlatpakSource(self.win))
|
importer.add_source(LutrisFlatpakSource())
|
||||||
if self.win.schema.get_boolean("steam"):
|
if shared.schema.get_boolean("steam"):
|
||||||
importer.add_source(SteamNativeSource(self.win))
|
importer.add_source(SteamNativeSource())
|
||||||
importer.add_source(SteamFlatpakSource(self.win))
|
importer.add_source(SteamFlatpakSource())
|
||||||
importer.add_source(SteamWindowsSource(self.win))
|
importer.add_source(SteamWindowsSource())
|
||||||
importer.run()
|
importer.run()
|
||||||
|
|
||||||
def on_remove_game_action(self, *_args):
|
def on_remove_game_action(self, *_args):
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ from pathlib import Path
|
|||||||
from os import PathLike, environ
|
from os import PathLike, environ
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
|
import src.shared as shared
|
||||||
|
|
||||||
|
|
||||||
def replaced_by_path(override: PathLike): # Decorator builder
|
def replaced_by_path(override: PathLike): # Decorator builder
|
||||||
"""Replace the method's returned path with the override
|
"""Replace the method's returned path with the override
|
||||||
@@ -42,9 +44,8 @@ def replaced_by_schema_key(key: str): # Decorator builder
|
|||||||
def decorator(original_function): # Built decorator (closure)
|
def decorator(original_function): # Built decorator (closure)
|
||||||
@wraps(original_function)
|
@wraps(original_function)
|
||||||
def wrapper(*args, **kwargs): # func's override
|
def wrapper(*args, **kwargs): # func's override
|
||||||
schema = args[0].win.schema
|
|
||||||
try:
|
try:
|
||||||
override = schema.get_string(key)
|
override = shared.schema.get_string(key)
|
||||||
except Exception: # pylint: disable=broad-exception-caught
|
except Exception: # pylint: disable=broad-exception-caught
|
||||||
return original_function(*args, **kwargs)
|
return original_function(*args, **kwargs)
|
||||||
return replaced_by_path(override)(original_function)(*args, **kwargs)
|
return replaced_by_path(override)(original_function)(*args, **kwargs)
|
||||||
|
|||||||
@@ -34,14 +34,10 @@ class SGDBHelper:
|
|||||||
"""Helper class to make queries to SteamGridDB"""
|
"""Helper class to make queries to SteamGridDB"""
|
||||||
|
|
||||||
base_url = "https://www.steamgriddb.com/api/v2/"
|
base_url = "https://www.steamgriddb.com/api/v2/"
|
||||||
win = None
|
|
||||||
|
|
||||||
def __init__(self, win):
|
|
||||||
self.win = win
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def auth_headers(self):
|
def auth_headers(self):
|
||||||
key = self.win.schema.get_string("sgdb-key")
|
key = shared.schema.get_string("sgdb-key")
|
||||||
headers = {"Authorization": f"Bearer {key}"}
|
headers = {"Authorization": f"Bearer {key}"}
|
||||||
return headers
|
return headers
|
||||||
|
|
||||||
@@ -82,14 +78,14 @@ class SGDBHelper:
|
|||||||
"""Update the game's cover if appropriate"""
|
"""Update the game's cover if appropriate"""
|
||||||
|
|
||||||
# Obvious skips
|
# Obvious skips
|
||||||
use_sgdb = self.win.schema.get_boolean("sgdb")
|
use_sgdb = shared.schema.get_boolean("sgdb")
|
||||||
if not use_sgdb or game.blacklisted:
|
if not use_sgdb or game.blacklisted:
|
||||||
return
|
return
|
||||||
|
|
||||||
image_trunk = self.win.covers_dir / game.game_id
|
image_trunk = shared.covers_dir / game.game_id
|
||||||
still = image_trunk.with_suffix(".tiff")
|
still = image_trunk.with_suffix(".tiff")
|
||||||
uri_kwargs = image_trunk.with_suffix(".gif")
|
uri_kwargs = image_trunk.with_suffix(".gif")
|
||||||
prefer_sgdb = self.win.schema.get_boolean("sgdb-prefer")
|
prefer_sgdb = shared.schema.get_boolean("sgdb-prefer")
|
||||||
|
|
||||||
# Do nothing if file present and not prefer SGDB
|
# Do nothing if file present and not prefer SGDB
|
||||||
if not prefer_sgdb and (still.is_file() or uri_kwargs.is_file()):
|
if not prefer_sgdb and (still.is_file() or uri_kwargs.is_file()):
|
||||||
@@ -106,7 +102,7 @@ class SGDBHelper:
|
|||||||
|
|
||||||
# Build different SGDB options to try
|
# Build different SGDB options to try
|
||||||
image_uri_kwargs_sets = [{"animated": False}]
|
image_uri_kwargs_sets = [{"animated": False}]
|
||||||
if self.win.schema.get_boolean("sgdb-animated"):
|
if shared.schema.get_boolean("sgdb-animated"):
|
||||||
image_uri_kwargs_sets.insert(0, {"animated": True})
|
image_uri_kwargs_sets.insert(0, {"animated": True})
|
||||||
|
|
||||||
# Download covers
|
# Download covers
|
||||||
@@ -117,9 +113,7 @@ class SGDBHelper:
|
|||||||
tmp_file = Gio.File.new_tmp()[0]
|
tmp_file = Gio.File.new_tmp()[0]
|
||||||
tmp_file_path = tmp_file.get_path()
|
tmp_file_path = tmp_file.get_path()
|
||||||
Path(tmp_file_path).write_bytes(response.content)
|
Path(tmp_file_path).write_bytes(response.content)
|
||||||
save_cover(
|
save_cover(game.game_id, resize_cover(tmp_file_path))
|
||||||
self.win, game.game_id, resize_cover(self.win, tmp_file_path)
|
|
||||||
)
|
|
||||||
except SGDBAuthError as error:
|
except SGDBAuthError as error:
|
||||||
# Let caller handle auth errors
|
# Let caller handle auth errors
|
||||||
raise error
|
raise error
|
||||||
|
|||||||
Reference in New Issue
Block a user