🎨 Sorted imports, made pylint happy
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
from threading import Thread, Lock
|
from threading import Lock, Thread
|
||||||
from gi.repository import Adw, Gtk, Gio
|
|
||||||
|
from gi.repository import Adw, Gtk
|
||||||
|
|
||||||
from .game import Game
|
|
||||||
from .steamgriddb import SGDBHelper
|
from .steamgriddb import SGDBHelper
|
||||||
|
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ class Importer:
|
|||||||
games_lock = None
|
games_lock = None
|
||||||
games = None
|
games = None
|
||||||
|
|
||||||
def __init__(self, win) -> None:
|
def __init__(self, win):
|
||||||
self.games = set()
|
self.games = set()
|
||||||
self.sources = set()
|
self.sources = set()
|
||||||
self.counts = dict()
|
self.counts = dict()
|
||||||
@@ -77,12 +77,12 @@ class Importer:
|
|||||||
print(f"{source.full_name}, installed: {source.is_installed}")
|
print(f"{source.full_name}, installed: {source.is_installed}")
|
||||||
if not source.is_installed:
|
if not source.is_installed:
|
||||||
continue
|
continue
|
||||||
t = Thread(target=self.__import_source__, args=tuple([source])) # fmt: skip
|
thread = Thread(target=self.__import_source__, args=tuple([source])) # fmt: skip
|
||||||
threads.append(t)
|
threads.append(thread)
|
||||||
t.start()
|
thread.start()
|
||||||
|
|
||||||
for t in threads:
|
for thread in threads:
|
||||||
t.join()
|
thread.join()
|
||||||
|
|
||||||
# Save games
|
# Save games
|
||||||
for game in self.games:
|
for game in self.games:
|
||||||
@@ -95,11 +95,11 @@ class Importer:
|
|||||||
|
|
||||||
self.close_dialog()
|
self.close_dialog()
|
||||||
|
|
||||||
def __import_source__(self, *args, **kwargs):
|
def __import_source__(self, *args, **_kwargs):
|
||||||
"""Source import thread entry point"""
|
"""Source import thread entry point"""
|
||||||
# TODO error handling in source iteration
|
# TODO error handling in source iteration
|
||||||
# TODO add SGDB image (move to a game manager)
|
# TODO add SGDB image (move to a game manager)
|
||||||
source, *rest = args
|
source, *_rest = args
|
||||||
iterator = source.__iter__()
|
iterator = source.__iter__()
|
||||||
with self.progress_lock:
|
with self.progress_lock:
|
||||||
self.counts[source.id]["total"] = len(iterator)
|
self.counts[source.id]["total"] = len(iterator)
|
||||||
|
|||||||
@@ -38,41 +38,38 @@ class Source(Iterable):
|
|||||||
@property
|
@property
|
||||||
def full_name(self):
|
def full_name(self):
|
||||||
"""The source's full name"""
|
"""The source's full name"""
|
||||||
s = self.name
|
full_name_ = self.name
|
||||||
if self.variant is not None:
|
if self.variant is not None:
|
||||||
s += f" ({self.variant})"
|
full_name_ += f" ({self.variant})"
|
||||||
return s
|
return full_name_
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def id(self):
|
def id(self): # pylint: disable=invalid-name
|
||||||
"""The source's identifier"""
|
"""The source's identifier"""
|
||||||
s = self.name.lower()
|
id_ = self.name.lower()
|
||||||
if self.variant is not None:
|
if self.variant is not None:
|
||||||
s += f"_{self.variant.lower()}"
|
id_ += f"_{self.variant.lower()}"
|
||||||
return s
|
return id_
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def game_id_format(self):
|
def game_id_format(self):
|
||||||
"""The string format used to construct game IDs"""
|
"""The string format used to construct game IDs"""
|
||||||
f = self.name.lower()
|
format_ = self.name.lower()
|
||||||
if self.variant is not None:
|
if self.variant is not None:
|
||||||
f += f"_{self.variant.lower()}"
|
format_ += f"_{self.variant.lower()}"
|
||||||
f += "_{game_id}"
|
format_ += "_{game_id}"
|
||||||
return f
|
return format_
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def executable_format(self):
|
def executable_format(self):
|
||||||
"""The executable format used to construct game executables"""
|
"""The executable format used to construct game executables"""
|
||||||
pass
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def is_installed(self):
|
def is_installed(self):
|
||||||
"""Whether the source is detected as installed"""
|
"""Whether the source is detected as installed"""
|
||||||
pass
|
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
"""Get the source's iterator, to use in for loops"""
|
"""Get the source's iterator, to use in for loops"""
|
||||||
pass
|
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ from functools import cache
|
|||||||
from sqlite3 import connect
|
from sqlite3 import connect
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
|
from .decorators import replaced_by_path, replaced_by_schema_key
|
||||||
from .game import Game
|
from .game import Game
|
||||||
from .save_cover import resize_cover, save_cover
|
from .save_cover import resize_cover, save_cover
|
||||||
from .source import Source, SourceIterator
|
from .source import Source, SourceIterator
|
||||||
from .decorators import replaced_by_schema_key, replaced_by_path
|
|
||||||
|
|
||||||
|
|
||||||
class LutrisSourceIterator(SourceIterator):
|
class LutrisSourceIterator(SourceIterator):
|
||||||
@@ -128,7 +128,7 @@ class LutrisNativeSource(LutrisSource):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
@replaced_by_schema_key("lutris-cache-location")
|
@replaced_by_schema_key("lutris-cache-location")
|
||||||
@replaced_by_path("~/.local/share/lutris/covers")
|
@replaced_by_path("~/.local/share/lutris/covers/")
|
||||||
def cache_location(self):
|
def cache_location(self):
|
||||||
raise FileNotFoundError()
|
raise FileNotFoundError()
|
||||||
|
|
||||||
@@ -140,12 +140,12 @@ class LutrisFlatpakSource(LutrisSource):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
@replaced_by_schema_key("lutris-flatpak-location")
|
@replaced_by_schema_key("lutris-flatpak-location")
|
||||||
@replaced_by_path("~/.var/app/net.lutris.Lutris/data/lutris")
|
@replaced_by_path("~/.var/app/net.lutris.Lutris/data/lutris/")
|
||||||
def location(self):
|
def location(self):
|
||||||
raise FileNotFoundError()
|
raise FileNotFoundError()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@replaced_by_schema_key("lutris-flatpak-cache-location")
|
@replaced_by_schema_key("lutris-flatpak-cache-location")
|
||||||
@replaced_by_path("~/.var/app/net.lutris.Lutris/data/lutris/covers")
|
@replaced_by_path("~/.var/app/net.lutris.Lutris/data/lutris/covers/")
|
||||||
def cache_location(self):
|
def cache_location(self):
|
||||||
raise FileNotFoundError()
|
raise FileNotFoundError()
|
||||||
|
|||||||
@@ -18,18 +18,17 @@ from os import PathLike
|
|||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
|
|
||||||
def replaced_by_path(path: 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
|
||||||
if the override exists on disk"""
|
if the override exists on disk"""
|
||||||
|
|
||||||
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
|
||||||
p = Path(path).expanduser()
|
path = Path(override).expanduser()
|
||||||
if p.exists():
|
if path.exists():
|
||||||
return p
|
return path
|
||||||
else:
|
return original_function(*args, **kwargs)
|
||||||
return original_function(*args, **kwargs)
|
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
@@ -46,10 +45,9 @@ def replaced_by_schema_key(key: str): # Decorator builder
|
|||||||
schema = args[0].win.schema
|
schema = args[0].win.schema
|
||||||
try:
|
try:
|
||||||
override = schema.get_string(key)
|
override = schema.get_string(key)
|
||||||
except Exception:
|
except Exception: # pylint: disable=broad-exception-caught
|
||||||
return original_function(*args, **kwargs)
|
return original_function(*args, **kwargs)
|
||||||
else:
|
return replaced_by_path(override)(original_function)(*args, **kwargs)
|
||||||
return replaced_by_path(override)(original_function)(*args, **kwargs)
|
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user