mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 10:32:57 +01:00
added platform filesystem name association
This commit is contained in:
@@ -20,6 +20,8 @@ depends_on = None
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table("platforms") as batch_op:
|
||||
batch_op.add_column(sa.Column('fs_slug', sa.String(length=200), nullable=True))
|
||||
with op.batch_alter_table("roms") as batch_op:
|
||||
if os.getenv('ROMM_DB_DRIVER') == 'mariadb':
|
||||
batch_op.drop_constraint('PRIMARY', type_="primary")
|
||||
@@ -78,6 +80,8 @@ def upgrade() -> None:
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table("platforms") as batch_op:
|
||||
batch_op.drop_column('fs_slug')
|
||||
with op.batch_alter_table("roms") as batch_op:
|
||||
batch_op.drop_constraint('PRIMARY', type_="primary")
|
||||
batch_op.drop_column('id')
|
||||
|
||||
@@ -5,6 +5,7 @@ from handler import dbh
|
||||
from utils import fs, get_file_name_with_no_tags
|
||||
from utils.exceptions import RomNotFoundError, RomAlreadyExistsException
|
||||
from models.rom import Rom
|
||||
from models.platform import Platform
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -30,8 +31,9 @@ async def updateRom(req: Request, p_slug: str, id: int) -> dict:
|
||||
data: dict = await req.json()
|
||||
updated_rom: dict = data['updatedRom']
|
||||
db_rom: Rom = dbh.get_rom(id)
|
||||
platform: Platform = dbh.get_platform(p_slug)
|
||||
try:
|
||||
fs.rename_rom(p_slug, db_rom.file_name, updated_rom['file_name'])
|
||||
fs.rename_rom(platform.fs_slug, db_rom.file_name, updated_rom['file_name'])
|
||||
except RomAlreadyExistsException as e:
|
||||
error: str = f"{e}"
|
||||
log.error(error)
|
||||
@@ -52,7 +54,8 @@ def delete_rom(p_slug: str, id: int, filesystem: bool=False) -> dict:
|
||||
if filesystem:
|
||||
log.info(f"Deleting {rom.file_name} from filesystem")
|
||||
try:
|
||||
fs.remove_rom(p_slug, rom.file_name)
|
||||
platform: Platform = dbh.get_platform(p_slug)
|
||||
fs.remove_rom(platform.fs_slug, rom.file_name)
|
||||
except RomNotFoundError as e:
|
||||
error: str = f"{e}. Couldn't delete from filesystem."
|
||||
log.error(error)
|
||||
|
||||
@@ -37,14 +37,14 @@ def scan(platforms: str, full_scan: bool=False) -> dict:
|
||||
|
||||
# Scanning roms
|
||||
try:
|
||||
fs_roms: list[str] = fs.get_roms(platform)
|
||||
fs_roms: list[str] = fs.get_roms(scanned_platform.fs_slug)
|
||||
except RomsNotFoundException as e:
|
||||
error: str = f"{e}"
|
||||
log.warning(error)
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=error)
|
||||
for rom in fs_roms:
|
||||
if rom['multi']: [log.info(f"\t - {COLORS['orange_i']}{file}{COLORS['reset']}") for file in rom['files']]
|
||||
rom_id: int = dbh.rom_exists(rom['file_name'], platform)
|
||||
rom_id: int = dbh.rom_exists(rom['file_name'], scanned_platform.slug)
|
||||
if rom_id and not full_scan: continue
|
||||
log.info(f"Scanning {COLORS['orange']}{rom['file_name']}{COLORS['reset']}")
|
||||
scanned_rom: Rom = fastapi.scan_rom(scanned_platform, rom)
|
||||
|
||||
@@ -63,7 +63,7 @@ class DBHandler:
|
||||
try:
|
||||
with self.session.begin() as s:
|
||||
s.query(Platform) \
|
||||
.filter(Platform.slug.not_in(platforms)) \
|
||||
.filter(Platform.fs_slug.not_in(platforms)) \
|
||||
.delete(synchronize_session='evaluate')
|
||||
except ProgrammingError as e:
|
||||
self.raise_error(e)
|
||||
|
||||
@@ -16,5 +16,7 @@ class Platform(BaseModel):
|
||||
|
||||
n_roms = Column(Integer, default=0)
|
||||
|
||||
fs_slug = Column(String(length=50), default="")
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return self.name
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
from handler import igdbh
|
||||
from utils import fs, parse_tags, get_file_extension, get_file_name_with_no_tags
|
||||
from config import user_config
|
||||
from logger.logger import log
|
||||
from models.platform import Platform
|
||||
from models.rom import Rom
|
||||
|
||||
|
||||
def scan_platform(p_slug: str) -> Platform:
|
||||
def scan_platform(fs_slug: str) -> Platform:
|
||||
"""Get platform details
|
||||
|
||||
Args:
|
||||
@@ -12,14 +14,22 @@ def scan_platform(p_slug: str) -> Platform:
|
||||
Returns
|
||||
Platform object
|
||||
"""
|
||||
platform_attrs: dict = igdbh.get_platform_details(p_slug)
|
||||
platform_attrs['n_roms'] = len(fs.get_roms(p_slug))
|
||||
|
||||
platform_attrs: dict = {}
|
||||
platform_attrs['fs_slug'] = fs_slug
|
||||
if fs_slug in user_config['system']['platforms'].keys():
|
||||
platform_attrs['slug'] = user_config['system']['platforms'][fs_slug]
|
||||
else:
|
||||
platform_attrs['slug'] = fs_slug
|
||||
platform_attrs.update(igdbh.get_platform_details(platform_attrs['slug']))
|
||||
platform_attrs['n_roms'] = len(fs.get_roms(platform_attrs['fs_slug']))
|
||||
platform = Platform(**platform_attrs)
|
||||
return platform
|
||||
|
||||
|
||||
def scan_rom(platform: Platform, rom_attrs: dict, r_igbd_id_search: str = '', overwrite: bool = False) -> Rom:
|
||||
roms_path: str = fs.get_roms_structure(platform.slug)
|
||||
p_slug: str = platform.fs_slug if platform.fs_slug else platform.slug
|
||||
roms_path: str = fs.get_roms_structure(p_slug)
|
||||
rom_attrs.update(igdbh.get_rom_details(rom_attrs['file_name'], platform.igdb_id, r_igbd_id_search))
|
||||
rom_attrs.update(fs.get_cover_details(overwrite, platform.slug, rom_attrs['file_name'], rom_attrs['url_cover']))
|
||||
file_size, file_size_units = fs.get_file_size(rom_attrs['multi'], rom_attrs['file_name'], rom_attrs['files'], roms_path)
|
||||
|
||||
@@ -105,7 +105,7 @@ def get_platforms() -> list[str]:
|
||||
|
||||
|
||||
# ========= Roms utils =========
|
||||
def get_roms_structure(p_slug) -> tuple:
|
||||
def get_roms_structure(p_slug: str) -> tuple:
|
||||
return f"{HIGH_PRIO_STRUCTURE_PATH}/{p_slug}" if os.path.exists(HIGH_PRIO_STRUCTURE_PATH) else f"{LIBRARY_BASE_PATH}/{p_slug}/roms"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user