forked from django/django-localflavor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.py
66 lines (51 loc) · 1.89 KB
/
tasks.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import glob
import os
import os.path
import sys
from invoke import task
@task
def clean(c):
c.run('git clean -Xfd')
@task
def test(c, country='all'):
print('Python version: ' + sys.version)
test_cmd = 'coverage run `which django-admin` test --settings=tests.settings'
country = os.environ.get('COUNTRY', country)
# Fix issue #49
cwp = os.path.dirname(os.path.abspath(__name__))
pythonpath = os.environ.get('PYTHONPATH', '').split(os.pathsep)
pythonpath.append(os.path.join(cwp, 'tests'))
os.environ['PYTHONPATH'] = os.pathsep.join(pythonpath)
if country == 'all':
c.run('{0} tests'.format(test_cmd))
c.run('coverage report')
elif country not in os.listdir('localflavor'):
print('The country {0!r} is not supported yet.'.format(country))
else:
c.run('{0} tests.test_{1}'.format(test_cmd, country))
c.run('coverage report -m --include=localflavor/{0}/*'.format(country))
@task
def compile_translations(c):
c.run('cd localflavor; django-admin compilemessages; cd ..')
@task(post=[compile_translations])
def pull_translations(c, locale=None):
if locale:
c.run('tx pull -f -l {0}'.format(locale))
po_files = ['localflavor/locale/{0}/LC_MESSAGES/django.po'.format(locale)]
else:
c.run('tx pull --minimum-perc=1 -f -a')
po_files = glob.glob('localflavor/locale/*/LC_MESSAGES/django.po')
po_files.remove('localflavor/locale/en/LC_MESSAGES/django.po')
# Remove source lines from po files
for po_file in po_files:
c.run('msgcat --no-location -o {0} {0}'.format(po_file))
@task
def make_translations(c, locale='en'):
with c.cd('localflavor'):
if locale == 'all':
c.run('django-admin makemessages -a')
else:
c.run('django-admin makemessages -l {locale}'.format(locale=locale))
@task
def docs(c):
c.run('cd docs; make html; cd ..')