From 38ff33f17bed1f1dba3712a201c6427a2963e114 Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Mon, 15 Apr 2024 10:36:28 +0000 Subject: [PATCH] Supprimer commands/tinfoil.py --- commands/tinfoil.py | 133 -------------------------------------------- 1 file changed, 133 deletions(-) delete mode 100755 commands/tinfoil.py diff --git a/commands/tinfoil.py b/commands/tinfoil.py deleted file mode 100755 index 769f83b..0000000 --- a/commands/tinfoil.py +++ /dev/null @@ -1,133 +0,0 @@ -#!/usr/bin/env python3 -import argparse -import os -import re -import subprocess -import sys -import time - -import requests - -parser = argparse.ArgumentParser() -parser.add_argument("-r", "--remote", type=str, required=True) -parser.add_argument("-f", "--force", action=argparse.BooleanOptionalAction) -args = parser.parse_args() -remote = args.remote -force = args.force - - -def drive_list(path): - proc = subprocess.run( - ["rclone", "lsf", f"{remote}:{path}"], - check=True, - capture_output=True, - ) - return proc.stdout.decode().split("\n") - - -def download(path, file): - if not force and os.path.isfile(os.path.join(path, file)): - return - - try: - print(f"Download {path}/{file}") - subprocess.run( - ["rclone", "copy", "-P", "-v", f"{remote}:{path}/{file}", f"{path}/"], - check=True, - stdout=sys.stdout, - ) - except subprocess.CalledProcessError: - print("Waiting for 10 minutes ...") - time.sleep(10 * 60) - download(path, file) - - -def remove(path, file): - if os.path.isfile(os.path.join(path, file)): - print(f"Removing {path}/{file}") - os.remove(os.path.join(path, file)) - - -def clean(path, database): - for file in os.listdir(path): - if os.path.isfile(os.path.join(path, file)) and file not in database: - remove(path, file) - - -req_titles = requests.get( - "https://raw.githubusercontent.com/blawar/titledb/master/FR.fr.json" -) -json_titles = req_titles.json() -titles = [] -for json_title in json_titles: - titles.append(json_titles[json_title]["id"]) -print("Titles OK") - -bases = drive_list("nsz/base") -print("Base OK") - -dlcs = drive_list("nsz/dlc") -print("DLC OK") - -updates = drive_list("nsz/updates") -print("Updates OK") - - -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 get_title_shortid(name): - id = get_title_fullid(name) - - return id[0:-4] if id and id in titles else None - - -clean("nsz/base", bases) -clean("nsz/dlc", dlcs) -clean("nsz/updates", updates) - - -try: - subprocess.run( - ["rclone", "sync", "-P", "-v", f"{remote}:nsz/homebrew", "nsz/homebrew/"], - check=True, - stdout=sys.stdout, - ) -except subprocess.CalledProcessError: - pass - - -for base in bases: - ascii = base[0:1].isascii() - shortid = get_title_shortid(base) - - if shortid and ascii: - download("nsz/base", base) - - for dlc in dlcs: - if shortid in dlc: - download("nsz/dlc", dlc) - - for update in updates: - if shortid in update: - download("nsz/updates", update) - else: - remove("nsz/base", base) - - fullid = get_title_fullid(base) - - if not fullid: - continue - - shortid = fullid[0:-4] - - for dlc in dlcs: - if shortid in dlc: - remove("nsz/dlc", dlc) - - for update in updates: - if shortid in update: - remove("nsz/updates", update)