config file for exclude added

This commit is contained in:
zurdi zurdo
2023-03-29 19:39:15 +02:00
parent 6958018465
commit b9de7f605d
6 changed files with 42 additions and 43 deletions

5
.gitignore vendored
View File

@@ -40,4 +40,7 @@ envs.env
mariadb
# data test
library
library
# config test
romm

View File

@@ -2,4 +2,5 @@ requests==2.28.2
fastapi==0.92.0
uvicorn==0.20.0
mariadb==1.1.6
SQLAlchemy==2.0.7
SQLAlchemy==2.0.7
PyYAML==6.0

View File

@@ -1,8 +1,10 @@
import os
import sys
import pathlib
import yaml
from yaml.loader import SafeLoader
from urllib.parse import quote_plus
from logger.logger import log
# Uvicorn
@@ -11,9 +13,14 @@ DEV_HOST: str = "0.0.0.0"
# PATHS
LIBRARY_BASE_PATH: str = f"{pathlib.Path(__file__).parent.parent.parent.parent.resolve()}/library"
ROMM_USER_CONFIG_PATH: str = f"{pathlib.Path(__file__).parent.parent.parent.parent.resolve()}/romm/config.yml"
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
DEFAULT_URL_LOGO: str = "https://images.igdb.com/igdb/image/upload/t_cover_big/nocover.png"
DEFAULT_PATH_LOGO: str = f"/assets/library/resources/default/logo_l.png"
RESERVED_FOLDERS: list = ['resources', 'database']
DEFAULT_URL_COVER_L: str = "https://images.igdb.com/igdb/image/upload/t_cover_big/nocover.png"
DEFAULT_PATH_COVER_L: str = f"/assets/library/resources/default/cover_l.png"
@@ -27,7 +34,6 @@ CLIENT_SECRET: str = os.getenv('CLIENT_SECRET')
STEAMGRIDDB_API_KEY: str = os.getenv('STEAMGRIDDB_API_KEY')
RESERVED_FOLDERS: list = ['resources', 'database']
# DB DRIVERS

View File

@@ -1,6 +1,6 @@
from sqlalchemy import Column, String, Integer, Text
from config.config import DEFAULT_PATH_LOGO
from config.config import DEFAULT_PATH_COVER
from models.base import BaseModel
@@ -10,5 +10,5 @@ class Platform(BaseModel):
sgdb_id = Column(String(length=50), default="")
slug = Column(String(length=100), primary_key=True)
name = Column(String(length=350), default="")
path_logo = Column(Text, default=DEFAULT_PATH_LOGO)
path_logo = Column(Text, default=DEFAULT_PATH_COVER)
n_roms = Column(Integer, default=0)

View File

@@ -5,7 +5,7 @@ from pathlib import Path
import requests
from fastapi import HTTPException
from config.config import LIBRARY_BASE_PATH, RESERVED_FOLDERS, DEFAULT_URL_LOGO, DEFAULT_URL_COVER_L, DEFAULT_PATH_COVER_L, DEFAULT_URL_COVER_S, DEFAULT_PATH_COVER_S
from config.config import user_config, LIBRARY_BASE_PATH, RESERVED_FOLDERS, DEFAULT_URL_COVER_L, DEFAULT_PATH_COVER_L, DEFAULT_URL_COVER_S, DEFAULT_PATH_COVER_S
from logger.logger import log
@@ -16,8 +16,6 @@ def store_default_resources(overwrite: bool) -> None:
Args:
overwrite: flag to overwrite or not default resources
"""
if overwrite or not p_logo_exists('default'):
store_p_logo('default', DEFAULT_URL_LOGO)
if overwrite or not r_cover_exists('default', 'cover', 'l'):
store_r_cover('default', 'cover', DEFAULT_URL_COVER_L, 'l')
if overwrite or not r_cover_exists('default', 'cover', 's'):
@@ -25,37 +23,6 @@ def store_default_resources(overwrite: bool) -> None:
# ========= Platforms utils =========
def p_logo_exists(slug: str) -> bool:
"""Check if platform logo exists in filesystem
Args:
slug: shor name of the platform
Returns
True if logo exists in filesystem else False
"""
logo_path: str = f"{LIBRARY_BASE_PATH}/resources/{slug}/logo.png"
return True if os.path.exists(logo_path) else False
def store_p_logo(slug: str, url_logo: str) -> None:
"""Store platform resources in filesystem
Args:
slug: shor name of the platform
url_logo: url to get logo
"""
logo_file: str = f"logo.png"
logo_path: str = f"{LIBRARY_BASE_PATH}/resources/{slug}"
res = requests.get(url_logo, stream=True)
if res.status_code == 200:
Path(logo_path).mkdir(parents=True, exist_ok=True)
with open(f"{logo_path}/{logo_file}", 'wb') as f:
shutil.copyfileobj(res.raw, f)
log.info(f"{slug} logo downloaded successfully!")
else:
log.warning(f"{slug} logo couldn't be downloaded")
def get_platforms() -> list[str]:
"""Gets all filesystem platforms
@@ -68,6 +35,14 @@ def get_platforms() -> list[str]:
else:
platforms: list[str] = list(os.walk(LIBRARY_BASE_PATH))[0][1]
[platforms.remove(reserved) for reserved in RESERVED_FOLDERS if reserved in platforms]
try:
excluded_folders: list = user_config['exclude']['platforms']
try:
[platforms.remove(excluded) for excluded in excluded_folders if excluded in platforms]
except TypeError:
pass
except KeyError:
pass
log.info(f"filesystem platforms found: {platforms}")
return platforms
except IndexError:
@@ -155,6 +130,18 @@ def get_roms(p_slug: str, only_amount: bool = False) -> list[dict]:
else:
roms_path: str = f"{LIBRARY_BASE_PATH}/{p_slug}/roms"
roms_filename = list(os.walk(f"{LIBRARY_BASE_PATH}/{p_slug}/roms"))[0][2]
try:
try:
excluded_files: list = user_config['exclude']['rom_files']
filtered_files: list = []
for filename in roms_filename:
if filename.split('.')[-1] in excluded_files:
filtered_files.append(filename)
roms_filename = [f for f in roms_filename if f not in filtered_files]
except TypeError:
pass
except KeyError:
pass
if only_amount: return len(roms_filename)
[roms.append({'filename': rom, 'size': str(round(os.stat(f"{roms_path}/{rom}").st_size / (1024 * 1024), 2))}) for rom in roms_filename]
log.info(f"filesystem roms found for {p_slug}: {roms}")

View File

@@ -6,7 +6,7 @@ In order to make the new folder structure to work, it is mandatory this time to
I apologize for the inconveniences this may cause, as this is a new software, it may change a little bit the first weeks, at least until I can develop a proper way to migrate between versions. I hope you can understand these initial wipes in order to make a better tool.
## Added
- Now RomM folder structure is more flexible to match two different patrons by priority:
- Now RomM folder structure is more flexible to match two different patrons by priority. This change makes RomM Emudeck compatible at least with single file games platforms:
- Structure 1 (priority high) - roms folder at root of library folder:
```
library/
@@ -42,6 +42,8 @@ I apologize for the inconveniences this may cause, as this is a new software, it
│ ├─ rom_1.gb
```
- Config file support to exclude folders and specific extension files to be scanned. To reload config file RomM reload is needed. Check config section.
# v1.4.1 (_29-03-2023_)
## Added