🐛 Fixed some imports

This commit is contained in:
GeoffreyCoulaud
2023-05-08 13:48:51 +02:00
parent 74afc8b6ea
commit 48ca1d938f
3 changed files with 10 additions and 4 deletions

View File

@@ -1,54 +0,0 @@
"""
A decorator takes a callable A and returns a callable B that will override the name of A.
A decorator with arguments returns a closure decorator having access to the arguments.
Example usage for the location decorators:
class MyClass():
@cached_property
@replaced_by_schema_key(key="source-location")
@replaced_by_path(override="/somewhere/that/doesnt/exist")
@replaced_by_path(override="/somewhere/that/exists")
def location(self):
return None
"""
from pathlib import Path
from os import PathLike
from functools import wraps
def replaced_by_path(path: PathLike): # Decorator builder
"""Replace the method's returned path with the override if the override exists on disk"""
def decorator(original_function): # Built decorator (closure)
@wraps(original_function)
def wrapper(*args, **kwargs): # func's override
p = Path(path).expanduser()
if p.exists():
return p
else:
return original_function(*args, **kwargs)
return wrapper
return decorator
def replaced_by_schema_key(key: str): # Decorator builder
"""Replace the method's returned path with the path pointed by the key if it exists on disk"""
def decorator(original_function): # Built decorator (closure)
@wraps(original_function)
def wrapper(*args, **kwargs): # func's override
schema = args[0].win.schema
try:
override = schema.get_string(key)
except Exception:
return original_function(*args, **kwargs)
else:
return replaced_by_path(override)(*args, **kwargs)
return wrapper
return decorator

View File

@@ -2,10 +2,10 @@ from functools import cached_property, cache
from sqlite3 import connect
from time import time
from src.game import Game
from src.utils.save_cover import resize_cover, save_cover
from src.importer.source import Source, SourceIterator
from src.importer.decorators import replaced_by_schema_key, replaced_by_path
from .game import Game
from .save_cover import resize_cover, save_cover
from .source import Source, SourceIterator
from .decorators import replaced_by_schema_key, replaced_by_path
class LutrisSourceIterator(SourceIterator):