From 0477efc1dcff8931dca3d66cff4ef8b9a5f207b7 Mon Sep 17 00:00:00 2001 From: zurdi zurdo Date: Tue, 11 Apr 2023 16:25:41 +0200 Subject: [PATCH] clearer logs --- backend/src/handler/db_handler.py | 3 --- backend/src/logger/logger.py | 20 ++++++++++---------- backend/src/main.py | 15 ++++++++++++--- backend/src/models/platform.py | 7 +------ backend/src/models/rom.py | 11 +---------- backend/src/utils/fastapi.py | 7 ++----- backend/src/utils/fs.py | 5 +---- frontend/src/components/Navigation.vue | 8 ++++++-- frontend/src/components/RomsGallery.vue | 15 ++++++--------- 9 files changed, 39 insertions(+), 52 deletions(-) diff --git a/backend/src/handler/db_handler.py b/backend/src/handler/db_handler.py index eb3d8ff6b..c139c1f74 100644 --- a/backend/src/handler/db_handler.py +++ b/backend/src/handler/db_handler.py @@ -9,7 +9,6 @@ from sqlalchemy.exc import ProgrammingError from config.config_loader import get_db_engine from models.platform import Platform from models.rom import Rom -from logger.logger import log class DBHandler: @@ -42,7 +41,6 @@ class DBHandler: raise HTTPException(status_code=404, detail=f"Platforms table not found: {e}") def purge_platforms(self, platforms: list[str]) -> None: - log.info("Purging platforms") with self.session.begin() as s: s.query(Platform) \ .filter(Platform.slug.not_in(platforms)) \ @@ -74,7 +72,6 @@ class DBHandler: .delete(synchronize_session='evaluate') def purge_roms(self, p_slug: str, roms: list[dict]) -> None: - log.info(f"Purging {p_slug} roms") with self.session.begin() as s: s.query(Rom) \ .filter(Rom.p_slug==p_slug, Rom.file_name.not_in([rom['file_name'] for rom in roms])) \ diff --git a/backend/src/logger/logger.py b/backend/src/logger/logger.py index b6857d9a1..c9360061c 100644 --- a/backend/src/logger/logger.py +++ b/backend/src/logger/logger.py @@ -1,17 +1,17 @@ import logging +COLORS: dict = { + 'grey': '\033[92m', + 'pink': '\033[95m', + 'blue': '\033[94m', + 'cyan': '\033[96m', + 'orange': '\033[93m', + 'red': '\033[91m', + 'bold_red': '\033[1;91m', + 'reset': '\033[0m', +} class CustomFormatter(logging.Formatter): - COLORS: dict = { - 'grey': '\033[92m', - 'pink': '\033[95m', - 'blue': '\033[94m', - 'cyan': '\033[96m', - 'orange': '\033[93m', - 'red': '\033[91m', - 'bold_red': '\033[1;91m', - 'reset': '\033[0m', - } level: str = "%(levelname)s" dots: str = ":" diff --git a/backend/src/main.py b/backend/src/main.py index f56d17c47..9f7076d3e 100644 --- a/backend/src/main.py +++ b/backend/src/main.py @@ -5,7 +5,7 @@ from fastapi import FastAPI, Request import uvicorn import json -from logger.logger import log +from logger.logger import log, COLORS from handler import igdbh, dbh from config import DEV_PORT, DEV_HOST from models.platform import Platform @@ -26,17 +26,26 @@ def startup() -> None: def scan(platforms_to_scan: str, full_scan: bool=False) -> dict: """Scan platforms and roms and write them in database.""" - log.info("scaning...") + log.info("Scaning...") fs.store_default_resources() fs_platforms: list[str] = fs.get_platforms() + log.info(f"Platforms found: {', '.join(fs_platforms)}") platforms: list[str] = json.loads(platforms_to_scan) if len(json.loads(platforms_to_scan)) > 0 else fs_platforms for p_slug in platforms: + log.info(f"{COLORS['pink']}== {p_slug} =={COLORS['reset']}") platform: Platform = fastapi.scan_platform(p_slug) + log.info(f"{p_slug} identified as {COLORS['blue']}{platform}{COLORS['reset']}") dbh.add_platform(platform) + log.info(f"Searching new roms...") roms: list[dict] = fs.get_roms(p_slug, full_scan) for rom in roms: - fastapi.scan_rom(platform, rom) + log.info(f"Getting {COLORS['orange']}{rom['file_name']}{COLORS['reset']} details") + if rom['multi']: [log.info(f"\t - {COLORS['orange']}{file}{COLORS['reset']}") for file in rom['files']] + rom = fastapi.scan_rom(platform, rom) + dbh.add_rom(rom) + log.info(f"Purging {platform} roms") dbh.purge_roms(p_slug, fs.get_roms(p_slug, True)) + log.info("Purging platforms") dbh.purge_platforms(fs_platforms) return {'msg': 'success'} diff --git a/backend/src/models/platform.py b/backend/src/models/platform.py index 1e2e3e45a..e861f867b 100644 --- a/backend/src/models/platform.py +++ b/backend/src/models/platform.py @@ -17,9 +17,4 @@ class Platform(BaseModel): n_roms = Column(Integer, default=0) def __repr__(self) -> str: - return ( - f"igdb_id: {self.igdb_id}," - f"slug: {self.slug}," - f"name: {self.name}," - f"n_roms: {self.n_roms}," - ) + return self.name diff --git a/backend/src/models/rom.py b/backend/src/models/rom.py index 8ceca733c..a22ac19ab 100644 --- a/backend/src/models/rom.py +++ b/backend/src/models/rom.py @@ -40,13 +40,4 @@ class Rom(BaseModel): return f"{self.file_path}/{self.file_name}" def __repr__(self) -> str: - return ( - f"r_igdb_id: {self.r_igdb_id}," - f"p_igdb_id: {self.p_igdb_id}," - f"r_slug: {self.r_slug}," - f"p_slug: {self.p_slug}," - f"file_name: {self.file_name}," - f"file_path: {self.file_path}," - f"multi: {self.multi}," - f"files: {self.files}" - ) + return self.file_name diff --git a/backend/src/utils/fastapi.py b/backend/src/utils/fastapi.py index 8245e155b..002f3fb1a 100644 --- a/backend/src/utils/fastapi.py +++ b/backend/src/utils/fastapi.py @@ -1,7 +1,7 @@ from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware -from handler import igdbh, dbh +from handler import igdbh from utils import fs from models.platform import Platform from models.rom import Rom @@ -27,16 +27,13 @@ def scan_platform(p_slug: str) -> Platform: Returns Platform object """ - log.info(f"Getting {p_slug} details") platform_attrs: dict = igdbh.get_platform_details(p_slug) platform_attrs['n_roms'] = fs.get_roms(p_slug, True, only_amount=True) - log.info(f"Roms found for {platform_attrs['name']}: {platform_attrs['n_roms']}") platform = Platform(**platform_attrs) return platform def scan_rom(platform: Platform, rom: dict, r_igbd_id_search: str = '', overwrite: bool = False) -> None: - log.info(f"Getting {rom['file_name']} details") r_igdb_id, file_name_no_tags, r_slug, r_name, summary, url_cover = igdbh.get_rom_details(rom['file_name'], platform.igdb_id, r_igbd_id_search) path_cover_s, path_cover_l, has_cover = fs.get_cover_details(overwrite, platform.slug, rom['file_name'], url_cover) rom['file_name_no_tags'] = file_name_no_tags @@ -50,4 +47,4 @@ def scan_rom(platform: Platform, rom: dict, r_igbd_id_search: str = '', overwrit rom['path_cover_l'] = path_cover_l rom['has_cover'] = has_cover rom = Rom(**rom) - dbh.add_rom(rom) + return rom diff --git a/backend/src/utils/fs.py b/backend/src/utils/fs.py index 7074ca4de..7e7edf8d9 100644 --- a/backend/src/utils/fs.py +++ b/backend/src/utils/fs.py @@ -33,7 +33,6 @@ def get_platforms() -> list[str]: [platforms.remove(excluded) for excluded in user_config['exclude']['folders'] if excluded in platforms] except (KeyError, TypeError): pass - log.info(f"filesystem platforms found: {platforms}") return platforms except IndexError: error: str = "Platforms not found." @@ -110,15 +109,13 @@ def get_roms(p_slug: str, full_scan: bool, only_amount: bool = False) -> list[di if only_amount: return len(db_roms) for rom in fs_roms: - if rom in db_roms and not full_scan: continue + if rom['file'] in db_roms and not full_scan: continue reg, rev, other_tags = parse_tags(rom['file']) file_extension: str = _get_file_extension(rom['file']) files: list = _get_rom_files(rom['multi'], rom['file'], roms_path) file_size: str = _get_file_size(rom['multi'], rom['file'], files, roms_path) roms.append({'file_name': rom['file'], 'file_path': roms_path, 'multi': rom['multi'], 'files': files, 'file_size': file_size, 'file_extension': file_extension, 'region': reg, 'revision': rev, 'tags': other_tags}) - - log.info(f"Roms found for {p_slug}: {roms}") return roms diff --git a/frontend/src/components/Navigation.vue b/frontend/src/components/Navigation.vue index 0b555bd2f..55abd72e7 100644 --- a/frontend/src/components/Navigation.vue +++ b/frontend/src/components/Navigation.vue @@ -142,9 +142,13 @@ getPlatforms() - + - + + + + + diff --git a/frontend/src/components/RomsGallery.vue b/frontend/src/components/RomsGallery.vue index 0a51dd15a..4a1e9d4df 100644 --- a/frontend/src/components/RomsGallery.vue +++ b/frontend/src/components/RomsGallery.vue @@ -93,16 +93,13 @@ onMounted(() => { if(localStorage.getItem('currentPlatform')){ getRoms(JSON.pars + + + + +
Feels cold here... mdi-emoticon-sad
+
- - - - - - -
Feels cold here... mdi-emoticon-sad
-
-