From 3b971bfda62286afe7d359cfb9b320bfd0a5c322 Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Tue, 3 Oct 2023 18:11:40 +0200 Subject: [PATCH] fix remove (again) --- commands/tinfoil.py | 53 ++++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 34 deletions(-) diff --git a/commands/tinfoil.py b/commands/tinfoil.py index dca5145..eb6c9db 100755 --- a/commands/tinfoil.py +++ b/commands/tinfoil.py @@ -43,24 +43,9 @@ def download(path, file): def remove(path, file): - print(f"Removing {path}/{file}") - # os.remove(os.path.join(path, file)) - - -def get_title_fullid(name): - re_id = re.search(r"\[([0-9A-F]*)\]", name) - - return re_id.group(1) if re_id else None - - -def extract_shortid(full_id): - return full_id[0:-4] - - -def get_title_shortid(name): - full_id = get_title_fullid(name) - - return extract_shortid(full_id) if full_id in titles else None + if os.path.isfile(os.path.join(path, file)): + print(f"Removing {path}/{file}") + os.remove(os.path.join(path, file)) req_titles = requests.get( @@ -82,21 +67,16 @@ updates = drive_list("nsz/updates") print("Updates OK") -for base in os.listdir("nsz/base"): - if os.path.isfile(os.path.join("nsz/base", base)): - full_id = get_title_fullid(base) - short_id = get_title_shortid(base) +def get_title_shortid(name): + re_id = re.search(r"\[([0-9A-F]*)\]", name) - if not short_id: - remove("nsz/base", base) + if not re_id: + return - for dlc in os.listdir("nsz/dlc"): - if extract_shortid(full_id) in dlc: - remove("nsz/dlc", dlc) + id = re_id.group(1) + + return id[0:-4] if id in titles else None - for update in os.listdir("nsz/updates"): - if extract_shortid(full_id) in update: - remove("nsz/updates", update) try: subprocess.run( @@ -107,18 +87,23 @@ try: except subprocess.CalledProcessError: pass + for base in bases: id = get_title_shortid(base) - if not id: - continue - - download("nsz/base", base) + if id: + download("nsz/base", base) + else: + remove("nsz/base", base) for dlc in dlcs: if id in dlc: download("nsz/dlc", dlc) + else: + remove("nsz/dlc", dlc) for update in updates: if id in update: download("nsz/updates", update) + else: + remove("nsz/updates", update)