complete exclude options added

This commit is contained in:
zurdi zurdo
2023-04-14 01:17:41 +02:00
parent e8b8a49e1a
commit 1d43fc67c6
2 changed files with 71 additions and 15 deletions

View File

@@ -21,6 +21,10 @@ def store_default_resources() -> None:
# ========= Platforms utils =========
def _exclude_platforms(platforms) -> list['str']:
[platforms.remove(excluded) for excluded in user_config['exclude']['platforms'] if excluded in platforms]
def get_platforms() -> list[str]:
"""Gets all filesystem platforms
@@ -30,7 +34,7 @@ def get_platforms() -> list[str]:
try:
platforms: list[str] = list(os.walk(HIGH_PRIO_STRUCTURE_PATH))[0][1] if os.path.exists(HIGH_PRIO_STRUCTURE_PATH) else list(os.walk(LIBRARY_BASE_PATH))[0][1]
try:
[platforms.remove(excluded) for excluded in user_config['exclude']['folders'] if excluded in platforms]
_exclude_platforms(platforms)
except (KeyError, TypeError):
pass
return platforms
@@ -45,17 +49,65 @@ def _get_roms_structure(p_slug) -> tuple:
return f"{HIGH_PRIO_STRUCTURE_PATH}/{p_slug}" if os.path.exists(HIGH_PRIO_STRUCTURE_PATH) else f"{LIBRARY_BASE_PATH}/{p_slug}/roms"
def _exclude_files(roms_files) -> list[str]:
def _exclude_single_roms(roms) -> list[str]:
try:
excluded_files: list = user_config['exclude']['files']
filtered_files: list = []
for file_name in roms_files:
if file_name.split('.')[-1] in excluded_files:
filtered_files.append(file_name)
roms_files = [f for f in roms_files if f not in filtered_files]
excluded_extensions: list = []
excluded_extensions = user_config['exclude']['roms']['single_file']['extensions']
except (TypeError, KeyError):
pass
return roms_files
log.warning(f"Config file for excluding single file extensions malformed")
try:
excluded_names: list = []
excluded_names = user_config['exclude']['roms']['single_file']['names']
except (TypeError, KeyError):
log.warning(f"Config file for excluding single file game names malformed")
filtered_files: list = []
for rom in roms:
try:
if rom.split('.')[-1] in excluded_extensions or rom in excluded_names:
filtered_files.append(rom)
except TypeError:
log.warning(f"Config file is malformed")
roms = [f for f in roms if f not in filtered_files]
return roms
def _exclude_multi_roms(roms) -> list[str]:
try:
excluded_names: list = []
excluded_names = user_config['exclude']['roms']['multi_file']['names']
except (TypeError, KeyError):
log.warning(f"Config file for excluding multi file game names malformed")
filtered_files: list = []
for rom in roms:
try:
if rom in excluded_names:
filtered_files.append(rom)
except TypeError:
log.warning(f"Config file is malformed")
roms = [f for f in roms if f not in filtered_files]
return roms
def _exclude_multi_roms_parts(parts) -> list[str]:
try:
excluded_extensions: list = []
excluded_extensions = user_config['exclude']['roms']['multi_file']['parts']['extensions']
except (TypeError, KeyError):
log.warning(f"Config file for excluding multi file game parts extensions malformed")
try:
excluded_names: list = []
excluded_names = user_config['exclude']['roms']['multi_file']['parts']['names']
except (TypeError, KeyError):
log.warning(f"Config file for excluding multi file game parts names malformed")
filtered_files: list = []
for part in parts:
try:
if part.split('.')[-1] in excluded_extensions or part in excluded_names:
filtered_files.append(part)
except TypeError:
log.warning(f"Config file is malformed")
parts = [f for f in parts if f not in filtered_files]
return parts
def parse_tags(file_name: str) -> tuple:
@@ -80,7 +132,7 @@ def _get_file_extension(file: str) -> str:
def _get_rom_files(multi: bool, rom: str, roms_path: str) -> list[str]:
return [] if not multi else _exclude_files(list(os.walk(f"{roms_path}/{rom}"))[0][2])
return [] if not multi else _exclude_multi_roms_parts(list(os.walk(f"{roms_path}/{rom}"))[0][2])
def _get_file_size(multi: bool, rom: str, files: list, roms_path:str) -> str:
@@ -102,14 +154,18 @@ def get_roms(p_slug: str, full_scan: bool, only_amount: bool = False) -> list[di
"""
roms_path = _get_roms_structure(p_slug)
roms: list[dict] = []
db_roms: list[str] = [rom.file_name for rom in dbh.get_roms(p_slug)]
fs_roms: list[dict] = [{'multi': False, 'file': rom} for rom in _exclude_files(list(os.walk(roms_path))[0][2])] + \
[{'multi': True, 'file': rom} for rom in list(os.walk(roms_path))[0][1]]
fs_single_roms: list[str] = list(os.walk(roms_path))[0][2]
fs_multi_roms: list[str] = list(os.walk(roms_path))[0][1]
fs_roms: list[dict] = [{'multi': False, 'file': rom} for rom in _exclude_single_roms(fs_single_roms)] + \
[{'multi': True, 'file': rom} for rom in _exclude_multi_roms(fs_multi_roms)]
if only_amount: return len(fs_roms)
for rom in fs_roms:
if rom['file'] in db_roms and not full_scan: continue
if rom['file'] in db_roms and not full_scan and not rom['multi']: 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)

View File

@@ -178,7 +178,7 @@ async function deleteRom() {
<v-col cols="3" xs="3" sm="2" md="2" lg="2" class="font-weight-medium"><p>Size</p></v-col>
<v-col><p>{{ rom.file_size }} MB</p></v-col>
</v-row>
<v-row class="d-flex align-center text-body-1 mt-0">
<v-row v-if="rom.r_igdb_id!=''" class="d-flex align-center text-body-1 mt-0">
<v-col cols="3" xs="3" sm="2" md="2" lg="2" class="font-weight-medium"><p>IGDB</p></v-col>
<v-col>
<v-chip variant="outlined" :href="'https://www.igdb.com/games/'+rom.r_slug" label>{{ rom.r_igdb_id }}</v-chip>