From c80065d2c82f048566ec2791d55b200f048736a4 Mon Sep 17 00:00:00 2001 From: Matt Troutman Date: Mon, 16 Sep 2024 20:40:09 -0500 Subject: [PATCH] Added cleanup items --- .fontfoldercleanup/cleanup.py | 47 +++++++++++++++++++++++++++++++++-- font-template | 1 - 2 files changed, 45 insertions(+), 3 deletions(-) delete mode 160000 font-template diff --git a/.fontfoldercleanup/cleanup.py b/.fontfoldercleanup/cleanup.py index 1f64dd0..fddf181 100644 --- a/.fontfoldercleanup/cleanup.py +++ b/.fontfoldercleanup/cleanup.py @@ -126,7 +126,7 @@ def collect_orphaned_fonts(path): def lowercase_all_the_folders(root_path): """ - Lowercases all the folders in the root path. + Lowercases all the folders in the root path, except those starting with a period. Args: root_path (str): The path to the directory to be checked and cleaned. @@ -137,14 +137,57 @@ def lowercase_all_the_folders(root_path): 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 new_dir_path = os.path.join(root_path, dir.lower()) os.rename(dir_path, new_dir_path) print(f"Renamed directory: {dir_path} -> {new_dir_path}") +def add_font_folders_to_each(root_path): + 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) + 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'): + new_dir_path = os.path.join(dir_path, 'otf') + if not os.path.exists(new_dir_path): + os.mkdir(new_dir_path) + new_file_path = os.path.join(new_dir_path, file) + os.rename(os.path.join(dir_path, file), new_file_path) + print(f"Moved {file} to {new_file_path}") + # if file extension is ttf, create a folder named oft if it doesn't exist, and move the file there + elif file.endswith('.ttf'): + new_dir_path = os.path.join(dir_path, 'ttf') + if not os.path.exists(new_dir_path): + os.mkdir(new_dir_path) + new_file_path = os.path.join(new_dir_path, file) + os.rename(os.path.join(dir_path, file), new_file_path) + print(f"Moved {file} to {new_file_path}") + else: + # if file is not a font file,move it to a folder called "other" + new_dir_path = os.path.join(dir_path, 'other') + if not os.path.exists(new_dir_path): + os.mkdir(new_dir_path) + new_file_path = os.path.join(new_dir_path, file) + os.rename(os.path.join(dir_path, file), new_file_path) + + + + + if __name__ == '__main__': remove_ds_store_files('/Users/fishy/custom_fonts/') remove_empty_folders('/Users/fishy/custom_fonts/') remove_bad_phrases('/Users/fishy/custom_fonts/') collect_orphaned_fonts('/Users/fishy/custom_fonts/') - lowercase_all_the_folders('/Users/fishy/custom_fonts/') \ No newline at end of file + lowercase_all_the_folders('/Users/fishy/custom_fonts/') + add_font_folders_to_each('/Users/fishy/custom_fonts/') + remove_ds_store_files('/Users/fishy/custom_fonts/') + remove_empty_folders('/Users/fishy/custom_fonts/') \ No newline at end of file diff --git a/font-template b/font-template deleted file mode 160000 index 052f5fc..0000000 --- a/font-template +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 052f5fc4e8d36f4ac983f1c5c019f8e73963d237