refactoring a bit

This commit is contained in:
Matt Troutman 2024-10-02 16:27:49 -05:00
parent 1f18110229
commit 46156f7bdd
No known key found for this signature in database

View file

@ -264,7 +264,8 @@ def dont_use_dots_for_font_files(root_path=font_location):
for root, dirs, files in os.walk(root_path):
for file in files:
file_path = os.path.join(root, file)
if file_path.endswith('.otf') or file_path.endswith('.ttf') or file_path.endswith('.ttc') or file_path.endswith('.pdf'):
extensions = ['.otf', '.ttf', '.ttc', '.pdf', '.woff', '.woff2']
if any(file_path.endswith(ext) for ext in extensions):
new_file_path = None
for x in ['.','_', ' ', '-', '.-','--']:
if file.startswith(x):
@ -276,6 +277,20 @@ def dont_use_dots_for_font_files(root_path=font_location):
print(f"Skipped renaming {file_path} as {new_file_path} already exists")
new_file_path = None
def remove_double_and_triple_dashes(root_path=font_location):
## remove double and triple dashes from file names
## should loop until no more double or triple dashes are found
for root, dirs, files in os.walk(root_path):
for file in files:
file_path = os.path.join(root, file)
#replace -- or --- with -
if '--' in file or '---' in file:
new_file = file.replace('--','-')
new_file = new_file.replace('---','-')
new_file_path = os.path.join(root, new_file)
os.rename(file_path, new_file_path)
print(f"Renamed file: {file_path} -> {new_file_path}")
if __name__ == '__main__':
remove_ds_store_files()
remove_empty_folders()
@ -286,5 +301,7 @@ if __name__ == '__main__':
lowercase_and_dash_file_names()
prepend_folder_name_to_font_dash()
dont_use_dots_for_font_files()
remove_double_and_triple_dashes()
remove_double_and_triple_dashes()
remove_ds_store_files()
remove_empty_folders()