Skip to content

Commit

Permalink
Merge pull request #211 from zurdi15/develop
Browse files Browse the repository at this point in the history
v1.8.1
  • Loading branch information
zurdi15 authored Apr 28, 2023
2 parents 0c718f0 + 27cc8a5 commit 5ae95bc
Show file tree
Hide file tree
Showing 45 changed files with 667 additions and 763 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# v1.8.1 (_27-04-2023_)

## Added
- Now it is possible to search a rom match by Name and by ID. Solves [#208](https://github.com/zurdi15/romm/issues/208)
- Now screenshots are displayed in screenshots tab (Complete scan needed in order to fetch screenshots from IGDB). Partially solves [#57](https://github.com/zurdi15/romm/issues/57)
- Now more rom properties can be manually edited. Solves [#140](https://github.com/zurdi15/romm/issues/140)

<br>

# v1.8 (_25-04-2023_)

## Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ RomM will try to find the structure 1 and if it doesn't exists, RomM will try to

## ⚙️ Config.yml file

RomM can be configured through a yml file. This is used to exclude platforms and/or roms to be scanned.
RomM can be configured through a yml file.

For a configuration change to take effect, RomM must be restarted.

Expand Down
34 changes: 34 additions & 0 deletions backend/src/alembic/versions/1.8.1_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""update to 1.8.1
Revision ID: 1.8.1
Revises: 1.8
Create Date: 2023-04-17 12:03:19.163501
"""
import os
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import sqlite


# revision identifiers, used by Alembic.
revision = '1.8.1'
down_revision = '1.8'
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("roms") as batch_op:
batch_op.add_column(sa.Column('url_screenshots', sa.JSON(), nullable=False, server_default='[]'))
batch_op.add_column(sa.Column('path_screenshots', sa.JSON(), nullable=False, server_default='[]'))
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("roms") as batch_op:
batch_op.drop_column('url_screenshots')
batch_op.drop_column('path_screenshots')
# ### end Alembic commands ###
13 changes: 2 additions & 11 deletions backend/src/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import os
import yaml
from yaml.loader import SafeLoader

# Uvicorn
DEV_PORT: int = 5000
Expand All @@ -15,23 +13,16 @@

# DEFAULT RESOURCES
DEFAULT_URL_COVER_L: str = "https://images.igdb.com/igdb/image/upload/t_cover_big/nocover.png"
DEFAULT_PATH_COVER_L: str = f"{RESOURCES_BASE_PATH}/default/cover_l.png"
DEFAULT_PATH_COVER_L: str = f"{RESOURCES_BASE_PATH}/default/default/cover/big.png"
DEFAULT_URL_COVER_S: str = "https://images.igdb.com/igdb/image/upload/t_cover_small/nocover.png"
DEFAULT_PATH_COVER_S: str = f"{RESOURCES_BASE_PATH}/default/cover_s.png"
DEFAULT_PATH_COVER_S: str = f"{RESOURCES_BASE_PATH}/default/default/cover/small.png"

# IGDB
CLIENT_ID: str = os.getenv('CLIENT_ID')
CLIENT_SECRET: str = os.getenv('CLIENT_SECRET')
# STEAMGRIDDB
STEAMGRIDDB_API_KEY: str = os.getenv('STEAMGRIDDB_API_KEY')

# USER CONFIG
try:
with open(ROMM_USER_CONFIG_PATH) as config: config = yaml.load(config, Loader=SafeLoader)
except FileNotFoundError:
config = None
user_config: dict = {} if not config else config

# DB DRIVERS
SUPPORTED_DB_DRIVERS: list = ['sqlite', 'mariadb']
ROMM_DB_DRIVER: str = os.getenv('ROMM_DB_DRIVER', 'sqlite')
45 changes: 42 additions & 3 deletions backend/src/config/config_loader.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import os
import sys
import yaml
from yaml.loader import SafeLoader
from urllib.parse import quote_plus

from config import ROMM_DB_DRIVER, SUPPORTED_DB_DRIVERS, SQLITE_DB_BASE_PATH, user_config
from config import ROMM_DB_DRIVER, SUPPORTED_DB_DRIVERS, SQLITE_DB_BASE_PATH, ROMM_USER_CONFIG_PATH
from logger.logger import log


class ConfigLoader:

def __init__(self):
pass
try:
with open(ROMM_USER_CONFIG_PATH) as config_file: self.config: dict = yaml.load(config_file, Loader=SafeLoader)
except FileNotFoundError:
self.config: dict = {}
self._parse_config()


def get_db_engine(self):
@staticmethod
def get_db_engine():
if ROMM_DB_DRIVER in SUPPORTED_DB_DRIVERS:

if ROMM_DB_DRIVER == 'mariadb':
Expand All @@ -35,3 +42,35 @@ def get_db_engine(self):
else:
log.critical(f"{ROMM_DB_DRIVER} database not supported")
sys.exit(3)


def _parse_config(self) -> dict:
try:
self.config['EXCLUDED_PLATFORMS'] = self.config['exclude']['platforms'] if self.config['exclude']['platforms'] else []
except KeyError:
self.config['EXCLUDED_PLATFORMS'] = []
try:
self.config['EXCLUDED_SINGLE_EXT'] = self.config['exclude']['roms']['single_file']['extensions'] if self.config['exclude']['roms']['single_file']['extensions'] else []
except KeyError:
self.config['EXCLUDED_SINGLE_EXT'] = []
try:
self.config['EXCLUDED_SINGLE_FILES'] = self.config['exclude']['roms']['single_file']['names'] if self.config['exclude']['roms']['single_file']['names'] else []
except KeyError:
self.config['EXCLUDED_SINGLE_FILES'] = []
try:
self.config['EXCLUDED_MULTI_FILES'] = self.config['exclude']['roms']['multi_file']['names'] if self.config['exclude']['roms']['multi_file']['names'] else []
except KeyError:
self.config['EXCLUDED_MULTI_FILES'] = []
try:
self.config['EXCLUDED_MULTI_PARTS_EXT'] = self.config['exclude']['roms']['multi_file']['parts']['extensions'] if self.config['exclude']['roms']['multi_file']['parts']['extensions'] else []
except KeyError:
self.config['EXCLUDED_MULTI_PARTS_EXT'] = []
try:
self.config['EXCLUDED_MULTI_PARTS_FILES'] = self.config['exclude']['roms']['multi_file']['parts']['names'] if self.config['exclude']['roms']['multi_file']['parts']['names'] else []
except KeyError:
self.config['EXCLUDED_MULTI_PARTS_FILES'] = []
try:
self.config['PLATFORMS_BINDING'] = self.config['system']['platforms'] if self.config['system']['platforms'] else {}
except KeyError:
self.config['PLATFORMS_BINDING'] = {}

3 changes: 2 additions & 1 deletion backend/src/endpoints/rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ async def updateRom(req: Request, p_slug: str, id: int) -> dict:
log.error(error)
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=error)
updated_rom['file_name_no_tags'] = get_file_name_with_no_tags(updated_rom['file_name'])
updated_rom.update(fs.get_cover_details(True, p_slug, updated_rom['file_name'], updated_rom['url_cover']))
updated_rom.update(fs.get_cover(True, p_slug, updated_rom['file_name'], updated_rom['url_cover']))
updated_rom.update(fs.get_screenshots(p_slug, updated_rom['file_name'], updated_rom['url_screenshots']))
dbh.update_rom(id, updated_rom)
return {'data': dbh.get_rom(id), 'msg': f"{updated_rom['file_name']} updated successfully!"}

Expand Down
11 changes: 5 additions & 6 deletions backend/src/endpoints/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import json

from logger.logger import log, COLORS
from config import user_config
from utils import fs, fastapi
from utils.exceptions import PlatformsNotFoundException, RomsNotFoundException
from handler import dbh
Expand All @@ -14,7 +13,7 @@


@router.get("/scan", status_code=200)
def scan(platforms: str, full_scan: bool=False) -> dict:
def scan(platforms: str, complete_rescan: bool=False) -> dict:
"""Scan platforms and roms and write them in database."""

log.info(emoji.emojize(":magnifying_glass_tilted_right: Scanning "))
Expand Down Expand Up @@ -44,13 +43,13 @@ def scan(platforms: str, full_scan: bool=False) -> dict:
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'], scanned_platform.slug)
if rom_id and not full_scan: continue
rom_id: int = dbh.rom_exists(scanned_platform.slug, rom['file_name'])
if rom_id and not complete_rescan: continue
log.info(f"Scanning {COLORS['orange']}{rom['file_name']}{COLORS['reset']}")
if rom['multi']: [log.info(f"\t - {COLORS['orange_i']}{file}{COLORS['reset']}") for file in rom['files']]
scanned_rom: Rom = fastapi.scan_rom(scanned_platform, rom)
if rom_id: scanned_rom.id = rom_id
dbh.add_rom(scanned_rom)
dbh.purge_roms(scanned_platform.slug, [rom['file_name'] for rom in fs_roms])
dbh.purge_roms(scanned_platform.slug, [rom['file_name'] for rom in fs_roms])
dbh.purge_platforms(fs_platforms)
return {'msg': 'Scan completed successfully!'}
12 changes: 8 additions & 4 deletions backend/src/endpoints/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@


@router.put("/search/roms/igdb", status_code=200)
async def search_rom_igdb(req: Request, igdb_id: str = None) -> dict:
async def search_rom_igdb(req: Request, search_term: str = '', search_by: str = '') -> dict:
"""Get all the roms matched from igdb."""

data: dict = await req.json()
rom: dict = data['rom']
log.info(emoji.emojize(":magnifying_glass_tilted_right: IGDB Searching"))
if igdb_id:
log.info(f"Searching by id: {igdb_id}")
matched_roms = igdbh.get_matched_roms_by_id(igdb_id)
matched_roms: list = []
if search_term:
log.info(f"Searching by {search_by}: {search_term}")
if search_by == 'ID':
matched_roms = igdbh.get_matched_rom_by_id(search_term)
elif search_by == 'Name':
matched_roms = igdbh.get_matched_roms_by_name(search_term, rom['p_igdb_id'])
else:
log.info(emoji.emojize(f":video_game: {rom['p_slug']}: {COLORS['orange']}{rom['file_name']}{COLORS['reset']}"))
matched_roms = igdbh.get_matched_roms(rom['file_name'], rom['p_igdb_id'], rom['p_slug'])
Expand Down
3 changes: 2 additions & 1 deletion backend/src/handler/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from handler.db_handler import DBHandler
from handler.igdb_handler import IGDBHandler
from handler.sgdb_handler import SGDBHandler
from config.config_loader import ConfigLoader

igdbh: IGDBHandler = IGDBHandler()
sgdbh: SGDBHandler = SGDBHandler()
dbh: DBHandler = DBHandler()
dbh: DBHandler = DBHandler(ConfigLoader())
18 changes: 8 additions & 10 deletions backend/src/handler/db_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

class DBHandler:

def __init__(self) -> None:
cl = ConfigLoader()
def __init__(self, cl: ConfigLoader) -> None:
self.engine = create_engine(cl.get_db_engine(), pool_pre_ping=True)
self.session = sessionmaker(bind=self.engine, expire_on_commit=False)

Expand Down Expand Up @@ -123,11 +122,10 @@ def purge_roms(self, p_slug: str, roms: list[str]) -> None:


# ==== Utils ======
def rom_exists(self, file_name: str, platform: str) -> int:
db_roms: list = self.get_roms(platform)
rom_id: int = 0
for db_rom in db_roms:
if db_rom.file_name == file_name:
rom_id = db_rom.id
break
return rom_id
def rom_exists(self, platform: str, file_name: str) -> int:
try:
with self.session.begin() as s:
rom = s.scalar(select(Rom).filter_by(p_slug=platform, file_name=file_name))
return rom.id if rom else None
except ProgrammingError as e:
self.raise_error(e)
Loading

0 comments on commit 5ae95bc

Please sign in to comment.