mirror of
https://github.com/rommapp/romm.git
synced 2026-12-05 23:44:11 +01:00
Merge pull request #571 from zurdi15/romm-567
[ROMM-567] Fix changing folder names by mapping old platform to new one
This commit is contained in:
@@ -43,7 +43,7 @@ async def scan_platforms(
|
||||
log.info(f"Found {len(platform_list)} platforms in file system ")
|
||||
|
||||
for platform_slug in platform_list:
|
||||
scanned_platform = scan_platform(platform_slug)
|
||||
scanned_platform = scan_platform(platform_slug, fs_platforms)
|
||||
_new_platform = dbh.add_platform(scanned_platform)
|
||||
new_platform = dbh.get_platform(_new_platform.slug)
|
||||
|
||||
|
||||
@@ -45,6 +45,10 @@ class DBHandler:
|
||||
@begin_session
|
||||
def get_platform(self, slug: str, session: Session = None):
|
||||
return session.get(Platform, slug)
|
||||
|
||||
@begin_session
|
||||
def get_platform_by_fs_slug(self, fs_slug: str, session: Session = None):
|
||||
return session.scalars(select(Platform).filter_by(fs_slug=fs_slug).limit(1)).first()
|
||||
|
||||
@begin_session
|
||||
def purge_platforms(self, platforms: list[str], session: Session = None):
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import emoji
|
||||
from typing import Any
|
||||
|
||||
from handler import igdbh
|
||||
from handler import igdbh, dbh
|
||||
from utils import fs, parse_tags, get_file_extension, get_file_name_with_no_tags
|
||||
from config.config_loader import config
|
||||
from models import Platform, Rom
|
||||
from logger.logger import log
|
||||
|
||||
SWAPPED_PLATFORM_BINDINGS = dict((v, k) for k, v in config["PLATFORMS_BINDING"].items())
|
||||
|
||||
def scan_platform(fs_slug: str) -> Platform:
|
||||
|
||||
def scan_platform(fs_slug: str, fs_platforms) -> Platform:
|
||||
"""Get platform details
|
||||
|
||||
Args:
|
||||
@@ -22,6 +24,16 @@ def scan_platform(fs_slug: str) -> Platform:
|
||||
platform_attrs: dict[str, Any] = {}
|
||||
platform_attrs["fs_slug"] = fs_slug
|
||||
|
||||
# Sometimes users change the name of the folder, so we try to match it with the config
|
||||
if fs_slug not in fs_platforms:
|
||||
log.warning(
|
||||
f" {fs_slug} not found in file system, trying to match via config..."
|
||||
)
|
||||
if fs_slug in SWAPPED_PLATFORM_BINDINGS.keys():
|
||||
platform = dbh.get_platform_by_fs_slug(fs_slug)
|
||||
if platform:
|
||||
platform_attrs["fs_slug"] = SWAPPED_PLATFORM_BINDINGS[platform.slug]
|
||||
|
||||
try:
|
||||
if fs_slug in config["PLATFORMS_BINDING"].keys():
|
||||
platform_attrs["slug"] = config["PLATFORMS_BINDING"][fs_slug]
|
||||
@@ -29,6 +41,7 @@ def scan_platform(fs_slug: str) -> Platform:
|
||||
platform_attrs["slug"] = fs_slug
|
||||
except (KeyError, TypeError, AttributeError):
|
||||
platform_attrs["slug"] = fs_slug
|
||||
|
||||
platform = igdbh.get_platform(platform_attrs["slug"])
|
||||
|
||||
if platform["igdb_id"]:
|
||||
|
||||
@@ -7,7 +7,7 @@ from models import Platform, Rom
|
||||
|
||||
@pytest.mark.vcr()
|
||||
def test_scan_platform():
|
||||
platform = scan_platform("n64")
|
||||
platform = scan_platform("n64", "n64")
|
||||
|
||||
assert platform.__class__ == Platform
|
||||
assert platform.fs_slug == "n64"
|
||||
@@ -16,7 +16,7 @@ def test_scan_platform():
|
||||
assert platform.igdb_id == 4
|
||||
|
||||
try:
|
||||
platform = scan_platform("")
|
||||
platform = scan_platform("", "")
|
||||
except RomsNotFoundException as e:
|
||||
assert "Roms not found for platform" in str(e)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user