Last active
August 29, 2015 13:57
-
-
Save dolph/9915293 to your computer and use it in GitHub Desktop.
De-duplicate transifex *.po files.
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
""" | |
Adapted from https://bugs.launchpad.net/ironic/+bug/1298645/comments/2 | |
""" | |
import argparse | |
import os | |
import shutil | |
import tempfile | |
def patch_po_files(input_dir_name): | |
affected_paths = [] | |
for root, dirs, files in os.walk(input_dir_name): | |
for file_name in files: | |
path = os.path.join(root, file_name) | |
with open(path, "r") as input_file: | |
with tempfile.NamedTemporaryFile(delete=False) as tmp_file: | |
matchee = '#~ msg' | |
match_yet = False | |
for line in input_file: | |
if match_yet: | |
continue | |
if not line.startswith(matchee): | |
tmp_file.write(line) | |
else: | |
match_yet = True | |
shutil.move(tmp_file.name, path) | |
affected_paths.append(path) | |
return affected_paths | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser(description='De-duplicate *.po files.') | |
parser.add_argument('locale_dir') | |
args = parser.parse_args() | |
for path in patch_po_files(args.locale_dir): | |
print('Patched: %s' % path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment