Created
October 16, 2025 05:50
-
-
Save flodolo/e1f72aaefa7d647f54623bf728946acc to your computer and use it in GitHub Desktop.
Remove thunderbird-l10n obsolete files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
def extractFileList(repository_path): | |
""" | |
Extract the list of supported files. Store the relative path and ignore | |
specific paths. | |
""" | |
excluded_paths = () | |
supported_formats = [ | |
".dtd", | |
".ftl", | |
".ini", | |
".ini", | |
".properties", | |
] | |
file_list = [] | |
for root, dirs, files in os.walk(repository_path, followlinks=True): | |
# Exclude hidden folders and files | |
files = [f for f in files if not f[0] == "."] | |
dirs[:] = [d for d in dirs if not d[0] == "."] | |
for filename in files: | |
if os.path.splitext(filename)[1] in supported_formats: | |
filename = os.path.relpath( | |
os.path.join(root, filename), repository_path | |
) | |
# Ignore excluded folders | |
if filename.startswith(excluded_paths): | |
continue | |
file_list.append(filename) | |
file_list.sort() | |
return file_list | |
def get_locale_folders(path): | |
return sorted( | |
[ | |
x | |
for x in os.listdir(path) | |
if os.path.isdir(os.path.join(path, x)) and not x.startswith(".") | |
] | |
) | |
def main(): | |
# Update paths accordingly to local setup | |
commit_changes = True | |
l10n_path = "thunderbird-l10n" | |
quarantine_path = "thunderbird-l10n-source" | |
locales = get_locale_folders(l10n_path) | |
# Store the list of files in quarantine | |
source_file_list = extractFileList(quarantine_path) | |
for locale in locales: | |
print("Locale: {}".format(locale)) | |
locale_path = os.path.join(l10n_path, locale) | |
target_file_list = extractFileList(locale_path) | |
# Remove obsolete files (file in the locale, but not available in quarantine) | |
obsolete_files_list = [] | |
for filename in target_file_list: | |
if filename not in source_file_list: | |
obsolete_files_list.append(filename) | |
if commit_changes: | |
os.remove(os.path.join(locale_path, filename)) | |
obsolete_files_list.sort() | |
if obsolete_files_list: | |
print("Obsolete files:") | |
print("\n".join(obsolete_files_list)) | |
if not commit_changes: | |
print("(dry run)") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment