Remove replaced_by_env_path decorator
This commit is contained in:
@@ -11,7 +11,6 @@ from src.importer.sources.source import (
|
||||
URLExecutableSource,
|
||||
)
|
||||
from src.utils.decorators import (
|
||||
replaced_by_env_path,
|
||||
replaced_by_path,
|
||||
replaced_by_schema_key,
|
||||
)
|
||||
@@ -72,7 +71,6 @@ class BottlesSource(URLExecutableSource):
|
||||
@property
|
||||
@replaced_by_schema_key
|
||||
@replaced_by_path("~/.var/app/com.usebottles.bottles/data/bottles/")
|
||||
@replaced_by_env_path("XDG_DATA_HOME", "bottles/")
|
||||
@replaced_by_path("~/.local/share/bottles/")
|
||||
@replaced_by_path(shared.data_dir / "bottles")
|
||||
def location(self) -> Path:
|
||||
raise FileNotFoundError()
|
||||
|
||||
@@ -14,7 +14,6 @@ from src.importer.sources.source import (
|
||||
SourceIterator,
|
||||
)
|
||||
from src.utils.decorators import (
|
||||
replaced_by_env_path,
|
||||
replaced_by_path,
|
||||
replaced_by_schema_key,
|
||||
)
|
||||
@@ -130,8 +129,7 @@ class HeroicSource(URLExecutableSource):
|
||||
@property
|
||||
@replaced_by_schema_key
|
||||
@replaced_by_path("~/.var/app/com.heroicgameslauncher.hgl/config/heroic/")
|
||||
@replaced_by_env_path("XDG_CONFIG_HOME", "heroic/")
|
||||
@replaced_by_path("~/.config/heroic/")
|
||||
@replaced_by_env_path("appdata", "heroic/")
|
||||
@replaced_by_path(shared.config_dir / "heroic")
|
||||
@replaced_by_path(shared.appdata_dir / "heroic")
|
||||
def location(self) -> Path:
|
||||
raise FileNotFoundError()
|
||||
|
||||
@@ -10,7 +10,6 @@ from src.importer.sources.source import (
|
||||
URLExecutableSource,
|
||||
)
|
||||
from src.utils.decorators import (
|
||||
replaced_by_env_path,
|
||||
replaced_by_path,
|
||||
replaced_by_schema_key,
|
||||
)
|
||||
@@ -65,8 +64,7 @@ class ItchSource(URLExecutableSource):
|
||||
@property
|
||||
@replaced_by_schema_key
|
||||
@replaced_by_path("~/.var/app/io.itch.itch/config/itch/")
|
||||
@replaced_by_env_path("XDG_DATA_HOME", "itch/")
|
||||
@replaced_by_path("~/.config/itch")
|
||||
@replaced_by_env_path("appdata", "itch/")
|
||||
@replaced_by_path(shared.config_dir / "itch")
|
||||
@replaced_by_path(shared.appdata_dir / "itch")
|
||||
def location(self) -> Path:
|
||||
raise FileNotFoundError()
|
||||
|
||||
@@ -8,11 +8,7 @@ from typing import Generator
|
||||
from src import shared # pylint: disable=no-name-in-module
|
||||
from src.game import Game
|
||||
from src.importer.sources.source import Source, SourceIterationResult, SourceIterator
|
||||
from src.utils.decorators import (
|
||||
replaced_by_env_path,
|
||||
replaced_by_path,
|
||||
replaced_by_schema_key,
|
||||
)
|
||||
from src.utils.decorators import replaced_by_path, replaced_by_schema_key
|
||||
|
||||
|
||||
class LegendarySourceIterator(SourceIterator):
|
||||
@@ -79,8 +75,6 @@ class LegendarySource(Source):
|
||||
|
||||
@property
|
||||
@replaced_by_schema_key
|
||||
@replaced_by_env_path("XDG_CONFIG_HOME", "legendary/")
|
||||
@replaced_by_path("~/.config/legendary/")
|
||||
@replaced_by_path("~\\.config\\legendary\\")
|
||||
@replaced_by_path(shared.config_dir / "legendary")
|
||||
def location(self) -> Path:
|
||||
raise FileNotFoundError()
|
||||
|
||||
@@ -11,7 +11,6 @@ from src.importer.sources.source import (
|
||||
URLExecutableSource,
|
||||
)
|
||||
from src.utils.decorators import (
|
||||
replaced_by_env_path,
|
||||
replaced_by_path,
|
||||
replaced_by_schema_key,
|
||||
)
|
||||
@@ -102,9 +101,8 @@ class SteamSource(URLExecutableSource):
|
||||
@property
|
||||
@replaced_by_schema_key
|
||||
@replaced_by_path("~/.var/app/com.valvesoftware.Steam/data/Steam/")
|
||||
@replaced_by_env_path("XDG_DATA_HOME", "Steam/")
|
||||
@replaced_by_path(shared.data_dir / "Steam")
|
||||
@replaced_by_path("~/.steam/")
|
||||
@replaced_by_path("~/.local/share/Steam/")
|
||||
@replaced_by_env_path("programfiles(x86)", "Steam")
|
||||
@replaced_by_path(shared.programfiles32_dir / "Steam")
|
||||
def location(self):
|
||||
raise FileNotFoundError()
|
||||
|
||||
@@ -50,6 +50,9 @@ cache_dir = (
|
||||
games_dir = data_dir / "cartridges" / "games"
|
||||
covers_dir = data_dir / "cartridges" / "covers"
|
||||
|
||||
appdata_dir = Path(os.getenv("appdata") or "C:\\Users\\Default\\AppData\\Roaming")
|
||||
programfiles32_dir = Path(os.getenv("programfiles(x86)") or "C:\\Program Files (x86)")
|
||||
|
||||
scale_factor = max(
|
||||
monitor.get_scale_factor() for monitor in Gdk.Display.get_default().get_monitors()
|
||||
)
|
||||
|
||||
@@ -22,24 +22,6 @@ def replaced_by_path(override: PathLike): # Decorator builder
|
||||
return decorator
|
||||
|
||||
|
||||
def replaced_by_env_path(env_var_name: str, suffix: PathLike | None = None):
|
||||
"""Replace the method's returned path with a path whose root is the env variable"""
|
||||
|
||||
def decorator(original_function): # Built decorator (closure)
|
||||
@wraps(original_function)
|
||||
def wrapper(*args, **kwargs): # func's override
|
||||
try:
|
||||
env_var = environ[env_var_name]
|
||||
except KeyError:
|
||||
return original_function(*args, **kwargs)
|
||||
override = Path(env_var) / suffix
|
||||
return replaced_by_path(override)(original_function)(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
def replaced_by_schema_key(original_method): # Built decorator (closure)
|
||||
"""
|
||||
Replace the original method's value by the path pointed at in the schema
|
||||
|
||||
Reference in New Issue
Block a user