From 02c5c425479b862bf1699897743042d970c63b60 Mon Sep 17 00:00:00 2001 From: Matt Troutman Date: Mon, 16 Sep 2024 21:01:31 -0500 Subject: [PATCH] no message --- .fontfoldercleanup/2.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/.fontfoldercleanup/2.py b/.fontfoldercleanup/2.py index fddf181..306a60f 100644 --- a/.fontfoldercleanup/2.py +++ b/.fontfoldercleanup/2.py @@ -151,7 +151,7 @@ def add_font_folders_to_each(root_path): continue #get recursive list of files in the directory files = os.listdir(dir_path) - print(files) + # print(files) for file in files: # if file extension is otf, create a folder named oft if it doesn't exist, and move the file there if file.endswith('.otf'): @@ -177,6 +177,30 @@ def add_font_folders_to_each(root_path): new_file_path = os.path.join(new_dir_path, file) os.rename(os.path.join(dir_path, file), new_file_path) +def unzip_if_no_fonts(root_path): + #if there are no font files, find the zip file and unzip it + for dir in os.listdir(root_path): + dir_path = os.path.join(root_path, dir) + if os.path.isdir(dir_path): + if dir.startswith('.'): + continue + #get recursive list of files in the directory + files = os.listdir(dir_path) + # print(files) + font_files = [] + for file in files: + if file.endswith('.otf') or file.endswith('.ttf'): + font_files.append(file) + if len(font_files) == 0: + zip_files = [] + for file in files: + if file.endswith('.zip'): + zip_files.append(file) + if len(zip_files) == 1: + zip_file = zip_files[0] + zip_file_path = os.path.join(dir_path, zip_file) + os.system(f'unzip {zip_file_path} -d {dir_path}') + print(f"Unzipped {zip_file_path}")