Make i18n tests quieter
This commit is contained in:
committed by
David Baumgold
parent
c87a1138a3
commit
561ecc7682
@@ -22,7 +22,7 @@ $ ./dummy.py
|
||||
generates output conf/locale/$DUMMY_LOCALE/LC_MESSAGES,
|
||||
where $DUMMY_LOCALE is the dummy_locale value set in the i18n config
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
import re
|
||||
import sys
|
||||
|
||||
@@ -197,17 +197,20 @@ def new_filename(original_filename, new_locale):
|
||||
return new_file.abspath()
|
||||
|
||||
|
||||
def main():
|
||||
def main(verbosity=1):
|
||||
"""
|
||||
Generate dummy strings for all source po files.
|
||||
"""
|
||||
SOURCE_MSGS_DIR = CONFIGURATION.source_messages_dir
|
||||
for locale, converter in zip(CONFIGURATION.dummy_locales, [Dummy(), Dummy2()]):
|
||||
print "Processing source language files into dummy strings, locale {}:".format(locale)
|
||||
if verbosity:
|
||||
print("Processing source language files into dummy strings, locale {}:".format(locale))
|
||||
for source_file in CONFIGURATION.source_messages_dir.walkfiles('*.po'):
|
||||
print ' ', source_file.relpath()
|
||||
if verbosity:
|
||||
print(' ', source_file.relpath())
|
||||
make_dummy(SOURCE_MSGS_DIR.joinpath(source_file), locale, converter)
|
||||
print
|
||||
if verbosity:
|
||||
print()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -4,7 +4,7 @@ from i18n.config import BASE_DIR
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
def execute(command, working_directory=BASE_DIR):
|
||||
def execute(command, working_directory=BASE_DIR, stderr=subprocess.STDOUT):
|
||||
"""
|
||||
Executes shell command in a given working_directory.
|
||||
Command is a string to pass to the shell.
|
||||
@@ -12,7 +12,7 @@ def execute(command, working_directory=BASE_DIR):
|
||||
"""
|
||||
LOG.info("Executing in %s ...", working_directory)
|
||||
LOG.info(command)
|
||||
subprocess.check_call(command, cwd=working_directory, stderr=subprocess.STDOUT, shell=True)
|
||||
subprocess.check_call(command, cwd=working_directory, stderr=stderr, shell=True)
|
||||
|
||||
|
||||
def call(command, working_directory=BASE_DIR):
|
||||
|
||||
@@ -21,6 +21,7 @@ import os
|
||||
import os.path
|
||||
import logging
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
from path import path
|
||||
from polib import pofile
|
||||
@@ -31,39 +32,48 @@ from i18n.segment import segment_pofiles
|
||||
|
||||
|
||||
EDX_MARKER = "edX translation file"
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
DEVNULL = open(os.devnull, 'wb')
|
||||
|
||||
def base(path1, *paths):
|
||||
"""Return a relative path from BASE_DIR to path1 / paths[0] / ... """
|
||||
return BASE_DIR.relpathto(path1.joinpath(*paths))
|
||||
|
||||
def main():
|
||||
|
||||
def main(verbosity=1):
|
||||
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
|
||||
create_dir_if_necessary(LOCALE_DIR)
|
||||
source_msgs_dir = CONFIGURATION.source_messages_dir
|
||||
remove_file(source_msgs_dir.joinpath('django.po'))
|
||||
|
||||
# Extract strings from mako templates.
|
||||
babel_mako_cmd = 'pybabel extract -F {config} -c "Translators:" . -o {output}'
|
||||
verbosity_map = {
|
||||
0: "-q",
|
||||
1: "",
|
||||
2: "-v",
|
||||
}
|
||||
babel_verbosity = verbosity_map.get(verbosity, "")
|
||||
|
||||
babel_mako_cmd = 'pybabel {verbosity} extract -F {config} -c "Translators:" . -o {output}'
|
||||
babel_mako_cmd = babel_mako_cmd.format(
|
||||
verbosity=babel_verbosity,
|
||||
config=base(LOCALE_DIR, 'babel_mako.cfg'),
|
||||
output=base(CONFIGURATION.source_messages_dir, 'mako.po'),
|
||||
)
|
||||
execute(babel_mako_cmd, working_directory=BASE_DIR)
|
||||
execute(babel_mako_cmd, working_directory=BASE_DIR, stderr=DEVNULL)
|
||||
|
||||
makemessages = "django-admin.py makemessages -l en"
|
||||
makemessages = "django-admin.py makemessages -l en -v{}".format(verbosity)
|
||||
ignores = " ".join('--ignore="{}/*"'.format(d) for d in CONFIGURATION.ignore_dirs)
|
||||
if ignores:
|
||||
makemessages += " " + ignores
|
||||
|
||||
# Extract strings from django source files, including .py files.
|
||||
make_django_cmd = makemessages + ' --extension html'
|
||||
execute(make_django_cmd, working_directory=BASE_DIR)
|
||||
execute(make_django_cmd, working_directory=BASE_DIR, stderr=DEVNULL)
|
||||
|
||||
# Extract strings from Javascript source files.
|
||||
make_djangojs_cmd = makemessages + ' -d djangojs --extension js'
|
||||
execute(make_djangojs_cmd, working_directory=BASE_DIR)
|
||||
execute(make_djangojs_cmd, working_directory=BASE_DIR, stderr=DEVNULL)
|
||||
|
||||
# makemessages creates 'django.po'. This filename is hardcoded.
|
||||
# Rename it to django-partial.po to enable merging into django.po later.
|
||||
@@ -90,13 +100,14 @@ def main():
|
||||
output_file = source_msgs_dir / (app_name + ".po")
|
||||
files_to_clean.add(output_file)
|
||||
|
||||
babel_cmd = 'pybabel extract -F {config} -c "Translators:" {app} -o {output}'
|
||||
babel_cmd = 'pybabel {verbosity} extract -F {config} -c "Translators:" {app} -o {output}'
|
||||
babel_cmd = babel_cmd.format(
|
||||
verbosity=babel_verbosity,
|
||||
config=LOCALE_DIR / 'babel_third_party.cfg',
|
||||
app=app_name,
|
||||
output=output_file,
|
||||
)
|
||||
execute(babel_cmd, working_directory=app_dir)
|
||||
execute(babel_cmd, working_directory=app_dir, stderr=DEVNULL)
|
||||
|
||||
# Segment the generated files.
|
||||
segmented_files = segment_pofiles("en")
|
||||
@@ -191,4 +202,7 @@ def is_key_string(string):
|
||||
return len(string) > 1 and string[0] == '_'
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--verbose', '-v', action='count', default=0)
|
||||
args = parser.parse_args()
|
||||
main(verbosity=args.verbose)
|
||||
|
||||
@@ -24,6 +24,7 @@ from i18n.config import BASE_DIR, CONFIGURATION
|
||||
from i18n.execute import execute
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
DEVNULL = open(os.devnull, "wb")
|
||||
|
||||
|
||||
def merge(locale, target='django.po', sources=('django-partial.po',), fail_if_missing=True):
|
||||
@@ -124,8 +125,8 @@ def main(argv=None):
|
||||
for locale in CONFIGURATION.dummy_locales:
|
||||
merge_files(locale, fail_if_missing=False)
|
||||
|
||||
compile_cmd = 'django-admin.py compilemessages'
|
||||
execute(compile_cmd, working_directory=BASE_DIR)
|
||||
compile_cmd = 'django-admin.py compilemessages -v0'
|
||||
execute(compile_cmd, working_directory=BASE_DIR, stderr=DEVNULL)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -33,7 +33,7 @@ class TestExtract(TestCase):
|
||||
super(TestExtract, self).setUp()
|
||||
if not SETUP_HAS_RUN:
|
||||
# Run extraction script. Warning, this takes 1 minute or more
|
||||
extract.main()
|
||||
extract.main(verbosity=0)
|
||||
SETUP_HAS_RUN = True
|
||||
|
||||
def get_files(self):
|
||||
|
||||
@@ -23,8 +23,8 @@ class TestGenerate(TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
extract.main()
|
||||
dummy.main()
|
||||
extract.main(verbosity=0)
|
||||
dummy.main(verbosity=0)
|
||||
|
||||
def setUp(self):
|
||||
# Subtract 1 second to help comparisons with file-modify time succeed,
|
||||
|
||||
@@ -10,7 +10,11 @@ namespace :i18n do
|
||||
|
||||
desc "Extract localizable strings from sources"
|
||||
task :extract => ["i18n:validate:gettext", "assets:coffee"] do
|
||||
sh(File.join(REPO_ROOT, "i18n", "extract.py"))
|
||||
command = File.join(REPO_ROOT, "i18n", "extract.py")
|
||||
if verbose == true
|
||||
command += " -vv"
|
||||
end
|
||||
sh(command)
|
||||
end
|
||||
|
||||
desc "Compile localizable strings from sources, extracting strings first."
|
||||
|
||||
Reference in New Issue
Block a user