mirror of
https://github.com/rommapp/romm.git
synced 2026-11-29 18:11:16 +01:00
more logs improvement
This commit is contained in:
@@ -27,5 +27,5 @@ def get_db_engine():
|
||||
return f"sqlite:////{SQLITE_DB_BASE_PATH}/romm.db"
|
||||
|
||||
else:
|
||||
log.critical(f"Not supported {ROMM_DB_DRIVER} database")
|
||||
log.critical(f"{ROMM_DB_DRIVER} database not supported")
|
||||
sys.exit(3)
|
||||
|
||||
@@ -39,7 +39,7 @@ class IGDBHandler():
|
||||
igdb_id = res_details['id']
|
||||
name = res_details['name']
|
||||
except IndexError:
|
||||
log.warning("Platform not found in IGDB")
|
||||
log.warning(f"{slug} not found in IGDB")
|
||||
if not name: name = slug
|
||||
return {'igdb_id': igdb_id, 'name': name, 'slug': slug, 'logo_path': ''}
|
||||
|
||||
@@ -119,8 +119,7 @@ class IGDBHandler():
|
||||
if p_igdb_id != '':
|
||||
search_term: str = unidecode.unidecode(re.sub('[\(\[].*?[\)\]]', '', file_name.split('.')[0]))
|
||||
matched_roms: list = requests.post("https://api.igdb.com/v4/games/", headers=self.headers,
|
||||
data=f"search \"{search_term}\";fields name, id, slug, summary; where platforms=[{p_igdb_id}];").json()
|
||||
log.info(f"Matched roms for {file_name}: {matched_roms}")
|
||||
data=f"search \"{search_term}\";fields name, id, slug, summary; where platforms=[{p_igdb_id}];").json()
|
||||
for rom in matched_roms:
|
||||
try:
|
||||
res_details: dict = requests.post("https://api.igdb.com/v4/covers/", headers=self.headers,
|
||||
@@ -162,14 +161,14 @@ class TwitchAuth():
|
||||
try:
|
||||
self.token_valid_seconds = res['expires_in']
|
||||
self.token = res['access_token']
|
||||
log.info("twitch token fetched!")
|
||||
log.info("Twitch token fetched!")
|
||||
except KeyError:
|
||||
log.error("could not get twitch auth token: check client_id and client_secret")
|
||||
log.error("Could not get twitch auth token: check client_id and client_secret")
|
||||
sys.exit(2)
|
||||
|
||||
|
||||
def get_oauth_token(self) -> str:
|
||||
if not self._is_token_valid():
|
||||
log.warning("twitch token invalid: fetching a new one")
|
||||
log.warning("Twitch token invalid: fetching a new one")
|
||||
self._update_twitch_token()
|
||||
return self.token
|
||||
@@ -6,6 +6,7 @@ COLORS: dict = {
|
||||
'blue': '\033[94m',
|
||||
'cyan': '\033[96m',
|
||||
'orange': '\033[93m',
|
||||
'orange_i': '\033[3;93m',
|
||||
'red': '\033[91m',
|
||||
'bold_red': '\033[1;91m',
|
||||
'reset': '\033[0m',
|
||||
|
||||
@@ -27,8 +27,8 @@ def scan(platforms_to_scan: str, full_scan: bool=False) -> dict:
|
||||
log.info(emoji.emojize(":magnifying_glass_tilted_right: Scanning "))
|
||||
fs.store_default_resources()
|
||||
fs_platforms: list[str] = fs.get_platforms()
|
||||
log.info(f"Platforms detected: {', '.join(fs_platforms)}")
|
||||
platforms: list[str] = json.loads(platforms_to_scan) if len(json.loads(platforms_to_scan)) > 0 else fs_platforms
|
||||
log.info(f"Platforms detected: {', '.join(platforms)}")
|
||||
for p_slug in platforms:
|
||||
log.info(emoji.emojize(f":video_game: {p_slug} {COLORS['reset']}"))
|
||||
platform: Platform = fastapi.scan_platform(p_slug)
|
||||
@@ -38,7 +38,7 @@ def scan(platforms_to_scan: str, full_scan: bool=False) -> dict:
|
||||
roms: list[dict] = fs.get_roms(p_slug, full_scan)
|
||||
for rom in roms:
|
||||
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']]
|
||||
if rom['multi']: [log.info(f"\t - {COLORS['orange_i']}{file}{COLORS['reset']}") for file in rom['files']]
|
||||
rom = fastapi.scan_rom(platform, rom)
|
||||
dbh.add_rom(rom)
|
||||
log.info(emoji.emojize(":wastebasket: Purging database"))
|
||||
@@ -75,6 +75,7 @@ async def updateRom(req: Request, p_slug: str) -> dict:
|
||||
data: dict = await req.json()
|
||||
rom: dict = data['rom']
|
||||
updatedRom: dict = data['updatedRom']
|
||||
log.info(f"Updating {COLORS['orange']}{updatedRom['file_name']}{COLORS['reset']} details")
|
||||
r_igdb_id, file_name_no_tags, r_slug, r_name, summary, url_cover = igdbh.get_rom_details(updatedRom['file_name'], rom['p_igdb_id'], updatedRom['r_igdb_id'])
|
||||
path_cover_s, path_cover_l, has_cover = fs.get_cover_details(True, p_slug, updatedRom['file_name'], url_cover)
|
||||
updatedRom['file_name_no_tags'] = file_name_no_tags
|
||||
@@ -99,12 +100,14 @@ async def updateRom(req: Request, p_slug: str) -> dict:
|
||||
|
||||
|
||||
@app.delete("/platforms/{p_slug}/roms/{file_name}")
|
||||
def delete_rom(p_slug: str, file_name: str, filesystem: bool=False) -> dict:
|
||||
def remove_rom(p_slug: str, file_name: str, filesystem: bool=False) -> dict:
|
||||
"""Detele rom from filesystem and database"""
|
||||
|
||||
log.info("deleting rom...")
|
||||
if filesystem: fs.delete_rom(p_slug, file_name)
|
||||
log.info(f"Deleting {file_name} from database")
|
||||
dbh.delete_rom(p_slug, file_name)
|
||||
if filesystem:
|
||||
log.info(f"Removing {file_name} from filesystem")
|
||||
fs.remove_rom(p_slug, file_name)
|
||||
return {'msg': 'success'}
|
||||
|
||||
|
||||
@@ -113,8 +116,12 @@ async def search_rom_igdb(req: Request) -> dict:
|
||||
"""Get all the roms matched from igdb."""
|
||||
|
||||
data: dict = await req.json()
|
||||
log.info(f"getting {data['rom']['file_name']} roms from {data['rom']['p_slug']} igdb ...")
|
||||
return {'data': igdbh.get_matched_roms(data['rom']['file_name'], data['rom']['p_igdb_id'], data['rom']['p_slug'])}
|
||||
log.info(emoji.emojize(":magnifying_glass_tilted_right: IGDB Searching"))
|
||||
log.info(emoji.emojize(f":video_game: {data['rom']['p_slug']}: {COLORS['orange']}{data['rom']['file_name']}{COLORS['reset']}"))
|
||||
matched_roms = igdbh.get_matched_roms(data['rom']['file_name'], data['rom']['p_igdb_id'], data['rom']['p_slug'])
|
||||
log.info("Results:")
|
||||
[log.info(f"\t - {COLORS['blue']}{rom['name']}{COLORS['reset']}") for rom in matched_roms]
|
||||
return {'data': matched_roms}
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -16,7 +16,6 @@ def allow_cors(app: FastAPI) -> None:
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
log.info("CORS enabled")
|
||||
|
||||
|
||||
def scan_platform(p_slug: str) -> Platform:
|
||||
|
||||
@@ -35,7 +35,7 @@ def get_platforms() -> list[str]:
|
||||
pass
|
||||
return platforms
|
||||
except IndexError:
|
||||
error: str = "Platforms not found."
|
||||
error: str = "Platforms not found"
|
||||
log.critical(error)
|
||||
raise HTTPException(status_code=404, detail=error)
|
||||
|
||||
@@ -136,11 +136,13 @@ def _rom_exists(p_slug: str, file_name: str) -> bool:
|
||||
def rename_rom(p_slug: str, old_name: str, new_name: str) -> None:
|
||||
if new_name != old_name:
|
||||
rom_path = _get_roms_structure(p_slug)
|
||||
if _rom_exists(p_slug, new_name): raise HTTPException(status_code=500, detail=f"Can't rename: {new_name} already exists.")
|
||||
if _rom_exists(p_slug, new_name):
|
||||
log.info(f"Can't rename {old_name} to {new_name}. {new_name} already exists")
|
||||
raise HTTPException(status_code=500, detail=f"Can't rename: {new_name} already exists.")
|
||||
os.rename(f"{rom_path}/{old_name}", f"{rom_path}/{new_name}")
|
||||
|
||||
|
||||
def delete_rom(p_slug: str, file_name: str) -> None:
|
||||
def remove_rom(p_slug: str, file_name: str) -> None:
|
||||
rom_path = _get_roms_structure(p_slug)
|
||||
try:
|
||||
try:
|
||||
@@ -148,7 +150,7 @@ def delete_rom(p_slug: str, file_name: str) -> None:
|
||||
except IsADirectoryError:
|
||||
shutil.rmtree(f"{rom_path}/{file_name}")
|
||||
except FileNotFoundError:
|
||||
log.warning(f"Rom not found in filesystem: {rom_path}/{file_name}")
|
||||
log.error(f"{rom_path}/{file_name} not found in filesystem")
|
||||
|
||||
|
||||
def _cover_exists(p_slug: str, file_name: str, size: str) -> bool:
|
||||
@@ -184,7 +186,7 @@ def _store_cover(p_slug: str, file_name: str, url_cover: str, size: str) -> None
|
||||
shutil.copyfileobj(res.raw, f)
|
||||
log.info(f"{file_name} {sizes[size]} cover downloaded successfully!")
|
||||
else:
|
||||
log.warning(f"{file_name} {sizes[size]} cover couldn't be downloaded")
|
||||
log.error(f"{file_name} {sizes[size]} cover couldn't be downloaded")
|
||||
|
||||
|
||||
def _get_cover_path(p_slug: str, file_name: str, size: str) -> str:
|
||||
|
||||
Reference in New Issue
Block a user