Added cleanup items
This commit is contained in:
parent
40a941786a
commit
cba11a1ad0
2 changed files with 69 additions and 3 deletions
|
|
@ -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,81 @@ 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)
|
||||
|
||||
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}")
|
||||
|
||||
|
||||
|
||||
|
||||
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/')
|
||||
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/')
|
||||
|
|
@ -1 +0,0 @@
|
|||
Subproject commit 052f5fc4e8d36f4ac983f1c5c019f8e73963d237
|
||||
Loading…
Add table
Add a link
Reference in a new issue