-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
translation: remove old translations
Remove translated files when the source file get removed. This includes also renaming files.
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/python3 | ||
|
||
import argparse | ||
import os | ||
import sys | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('lang') | ||
parser.add_argument('translation_dir') | ||
parser.add_argument('tx_mapping') | ||
|
||
def main(): | ||
args = parser.parse_args() | ||
|
||
valid_files = set() | ||
with open(args.tx_mapping) as f_mapping: | ||
for line in f_mapping.readlines(): | ||
if line.startswith('file_filter = '): | ||
valid_files.add(line.strip().split(' = ')[1].replace('<lang>', args.lang)) | ||
|
||
if not valid_files: | ||
print('No files found in {}, aborting!'.format(args.tx_mapping)) | ||
return 1 | ||
|
||
existing_files = set() | ||
for dirpath, dirs, files in os.walk(args.translation_dir): | ||
existing_files.update(os.path.join(dirpath, name) for name in files) | ||
|
||
if not existing_files: | ||
print('No files found in {}, aborting!'.format(args.translation_dir)) | ||
return 1 | ||
|
||
for obsolete in existing_files.difference(valid_files): | ||
print('Removing {}'.format(obsolete)) | ||
os.unlink(obsolete) | ||
|
||
|
||
if __name__ == '__main__': | ||
sys.exit(main()) | ||
|