From cf7887c8df614d49944d99fd894bcc0df758c19c Mon Sep 17 00:00:00 2001 From: zhengxie Date: Sat, 1 Nov 2014 11:50:56 +0800 Subject: [PATCH] Add fabric file --- fabfile.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 fabfile.py diff --git a/fabfile.py b/fabfile.py new file mode 100644 index 0000000000..6a2b85d1c1 --- /dev/null +++ b/fabfile.py @@ -0,0 +1,38 @@ +""" +Tools for automating daily tasks. +""" +from fabric.api import local +from fabric.colors import red, green + +def i18n_upload(): + """Update source language, and upload to Transifex. + """ + _debug('django-admin.py makemessages -l en -e py,html -i "thirdpart*"') + local('django-admin.py makemessages -l en -e py,html -i "thirdpart*"') + + # some version of makemessages will produce "%%" in the string, replace that + # to "%". + _inplace_change('locale/en/LC_MESSAGES/django.po', '%%', '%') + + _debug('tx push -s') + local('tx push -s') + +def i18n_pull(): + """Update local po files with Transifex. + """ + _debug('tx pull') + local('tx pull') + +########## utility functions +def _inplace_change(filename, old_string, new_string): + s = open(filename).read() + if old_string in s: + print(green('Changing "{old_string}" to "{new_string}" in "{filename}"'.format(**locals()))) + s = s.replace(old_string, new_string) + f = open(filename, 'w') + f.write(s) + f.flush() + f.close() + +def _debug(msg): + print(red('Running: {msg}'.format(**locals())))