diff --git a/i18n/execute.py b/i18n/execute.py index 1ff439ef38..8e7f0f52de 100644 --- a/i18n/execute.py +++ b/i18n/execute.py @@ -4,28 +4,24 @@ from config import CONFIGURATION, BASE_DIR LOG = logging.getLogger(__name__) -def execute(command, working_directory=BASE_DIR, log=True): +def execute(command, working_directory=BASE_DIR): """ Executes shell command in a given working_directory. Command is a string to pass to the shell. - log is boolean. If true, the command's invocation string is logged. Output is ignored. """ - if log: - LOG.info(command) + LOG.info(command) subprocess.call(command.split(' '), cwd=working_directory) -def call(command, working_directory=BASE_DIR, log=True): +def call(command, working_directory=BASE_DIR): """ Executes shell command in a given working_directory. Command is a string to pass to the shell. Returns a tuple of two strings: (stdout, stderr) - log is boolean. If true, the command's invocation string is logged. """ - if log: - LOG.info(command) + LOG.info(command) p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=working_directory) out, err = p.communicate() return (out, err) @@ -36,7 +32,7 @@ def create_dir_if_necessary(pathname): os.makedirs(dirname) -def remove_file(filename, log=LOG, verbose=True): +def remove_file(filename, verbose=True): """ Attempt to delete filename. log is boolean. If true, removal is logged. @@ -44,8 +40,8 @@ def remove_file(filename, log=LOG, verbose=True): Logging filenames are releative to BASE_DIR to cut down on noise in output. """ if verbose: - log.info('Deleting file %s' % os.path.relpath(filename, BASE_DIR)) + LOG.info('Deleting file %s' % os.path.relpath(filename, BASE_DIR)) if not os.path.exists(filename): - log.warn("File does not exist: %s" % os.path.relpath(filename, BASE_DIR)) + LOG.warn("File does not exist: %s" % os.path.relpath(filename, BASE_DIR)) else: os.remove(filename) diff --git a/i18n/extract.py b/i18n/extract.py index c517de3b51..c28c3868e2 100755 --- a/i18n/extract.py +++ b/i18n/extract.py @@ -32,8 +32,9 @@ BABEL_OUT = BASE_DIR.relpathto(CONFIGURATION.source_messages_dir.joinpath('mako. SOURCE_WARN = 'This English source file is machine-generated. Do not check it into github' +LOG = logging.getLogger(__name__) + def main (): - log = logging.getLogger(__name__) logging.basicConfig(stream=sys.stdout, level=logging.INFO) create_dir_if_necessary(LOCALE_DIR) source_msgs_dir = CONFIGURATION.source_messages_dir @@ -63,7 +64,7 @@ def main (): execute(make_djangojs_cmd, working_directory=BASE_DIR) for filename in generated_files: - log.info('Cleaning %s' % filename) + LOG.info('Cleaning %s' % filename) po = pofile(source_msgs_dir.joinpath(filename)) # replace default headers with edX headers fix_header(po) diff --git a/i18n/generate.py b/i18n/generate.py index 48470796a2..65c65c00d6 100755 --- a/i18n/generate.py +++ b/i18n/generate.py @@ -17,9 +17,11 @@ import os, sys, logging from polib import pofile from config import BASE_DIR, CONFIGURATION -from execute import execute, remove_file +from execute import execute -def merge(locale, target='django.po', fail_if_missing=True, log=None): +LOG = logging.getLogger(__name__) + +def merge(locale, target='django.po', fail_if_missing=True): """ For the given locale, merge django-partial.po, messages.po, mako.po -> django.po target is the resulting filename @@ -28,8 +30,7 @@ def merge(locale, target='django.po', fail_if_missing=True, log=None): If fail_if_missing is False, and the files to be merged are missing, just return silently. """ - if log: - log.info('Merging locale={0}'.format(locale)) + LOG.info('Merging locale={0}'.format(locale)) locale_directory = CONFIGURATION.get_messages_dir(locale) files_to_merge = ('django-partial.po', 'messages.po', 'mako.po') try: @@ -71,13 +72,12 @@ def validate_files(dir, files_to_merge): raise Exception("I18N: Cannot generate because file not found: {0}".format(pathname)) def main (): - log = logging.getLogger(__name__) logging.basicConfig(stream=sys.stdout, level=logging.INFO) for locale in CONFIGURATION.locales: merge(locale) # Dummy text is not required. Don't raise exception if files are missing. - merge(CONFIGURATION.dummy_locale, fail_if_missing=False, log=log) + merge(CONFIGURATION.dummy_locale, fail_if_missing=False) compile_cmd = 'django-admin.py compilemessages' execute(compile_cmd, working_directory=BASE_DIR) diff --git a/i18n/tests/test_validate.py b/i18n/tests/test_validate.py index 7d970c8de2..bef563faea 100644 --- a/i18n/tests/test_validate.py +++ b/i18n/tests/test_validate.py @@ -28,7 +28,7 @@ def validate_po_file(filename, log): raise SkipTest() # Use relative paths to make output less noisy. rfile = os.path.relpath(filename, LOCALE_DIR) - (out, err) = call(['msgfmt','-c', rfile], log=False, working_directory=LOCALE_DIR) + (out, err) = call(['msgfmt','-c', rfile], working_directory=LOCALE_DIR) if err != '': log.warn('\n'+err)