branch_cleanup.py 1007 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#!/usr/bin/env python
"""
Utility for cleaning up your local directory after switching between
branches with different translation levels (eg master branch, with only
reviewed translations, versus dev branch, with all translations)
"""
from __future__ import print_function
import os

from i18n.config import CONFIGURATION
from i18n.execute import execute


def clean_conf_folder(locale):
    """Remove the configuration directory for `locale`"""
    dirname = CONFIGURATION.get_messages_dir(locale)
    command = "rm -rf {}".format(dirname)
    print(command)
    try:
        execute(command)
    except Exception as exc:
        print("Encountered error {}; continuing...".format(exc))
        return


def clean_configuration_directory():
    """
    Remove the configuration directories for all locales
    in CONFIGURATION.translated_locales
    """
    for locale in CONFIGURATION.translated_locales:
        clean_conf_folder(locale)


if __name__ == '__main__':
    clean_configuration_directory()