mirror of
https://github.com/rommapp/romm.git
synced 2026-11-29 10:01:00 +01:00
clearer logs
This commit is contained in:
@@ -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])) \
|
||||
|
||||
@@ -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 = ":"
|
||||
|
||||
@@ -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'}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -142,9 +142,13 @@ getPlatforms()
|
||||
|
||||
<!-- Mobile -->
|
||||
<!-- Platforms drawer toggle -->
|
||||
<v-app-bar-nav-icon @click="drawer = !drawer" class="ma-2 hidden-lg-and-up" rounded="0"/>
|
||||
<!-- <v-app-bar-nav-icon @click="drawer = !drawer" class="ma-2 hidden-lg-and-up" rounded="0"/> -->
|
||||
<!-- Platform icon -->
|
||||
<v-avatar class="ma-2 hidden-lg-and-up" :rounded="0" :image="'/assets/platforms/'+currentPlatform.slug+'.ico'"/>
|
||||
<v-btn @click="drawer = !drawer" class="ma-4 hidden-lg-and-up" rounded="0" icon>
|
||||
<v-avatar rounded="0">
|
||||
<v-img :src="'/assets/platforms/'+currentPlatform.slug+'.ico'"/>
|
||||
</v-avatar>
|
||||
</v-btn>
|
||||
|
||||
<v-spacer class="hidden-xs-and-down"></v-spacer>
|
||||
|
||||
|
||||
@@ -93,16 +93,13 @@ onMounted(() => { if(localStorage.getItem('currentPlatform')){ getRoms(JSON.pars
|
||||
</v-card>
|
||||
</v-hover>
|
||||
</v-col>
|
||||
<v-col v-if="gettingRoms" class="d-flex justify-center align-center mt-16">
|
||||
<v-progress-circular :width="3" :size="70" indeterminate/>
|
||||
</v-col>
|
||||
<v-col v-if="noRoms" class="d-flex justify-center align-center mt-16">
|
||||
<div class="text-h6">Feels cold here... <v-icon>mdi-emoticon-sad</v-icon></div>
|
||||
</v-col>
|
||||
</v-row>
|
||||
|
||||
<v-dialog v-model="gettingRoms" scroll-strategy="none" width="auto" :scrim="false" persistent>
|
||||
<v-progress-circular :width="3" :size="70" indeterminate/>
|
||||
</v-dialog>
|
||||
|
||||
<v-dialog v-model="noRoms" scroll-strategy="none" width="auto" :scrim="false" persistent>
|
||||
<div class="text-h6">Feels cold here... <v-icon>mdi-emoticon-sad</v-icon></div>
|
||||
</v-dialog>
|
||||
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in New Issue
Block a user