rewrite removing
dl / lint (push) Successful in 1m39s Details
dl / docker (push) Successful in 54s Details

This commit is contained in:
Michel Roux 2023-10-02 16:36:22 +02:00
parent bed1ecc552
commit fadb481c0f
1 changed files with 33 additions and 32 deletions

View File

@ -42,6 +42,27 @@ def download(path, file):
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
req_titles = requests.get(
"https://raw.githubusercontent.com/blawar/titledb/master/FR.fr.json"
)
@ -61,41 +82,21 @@ updates = drive_list("nsz/updates")
print("Updates OK")
def get_title_shortid(name):
re_id = re.search(r"\[([0-9A-F]*)\]", name)
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)
if not re_id:
return
if not short_id:
remove("nsz/base", base)
id = re_id.group(1)
for dlc in os.listdir("nsz/dlc"):
if extract_shortid(full_id) in dlc:
remove("nsz/dlc", dlc)
return id[0:-4] if id in titles else None
def remove(path):
to_remove = []
for name in os.listdir(path):
if os.path.isfile(os.path.join(path, name)):
id = get_title_shortid(name)
if not id:
to_remove.append(os.path.join(path, name))
if len(to_remove) > 100:
print("Too much to delete:")
for be_removed in to_remove:
print(be_removed)
else:
for be_removed in to_remove:
print(f"Removing {be_removed}")
os.remove(be_removed)
remove("nsz/base")
remove("nsz/dlc")
remove("nsz/updates")
for update in os.listdir("nsz/updates"):
if extract_shortid(full_id) in update:
remove("nsz/updates", update)
try:
subprocess.run(