Skip to content

Commit

Permalink
Ignored STATIC_ROOT and MEDIA_ROOT in makemessages
Browse files Browse the repository at this point in the history
Also alleviate issues with weird file names typically found in
MEDIA_ROOT directories (#23010).
Thanks Tim Graham for the review.
  • Loading branch information
claudep committed Jul 16, 2014
1 parent 0154965 commit 28efafa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
21 changes: 12 additions & 9 deletions django/core/management/commands/makemessages.py
Expand Up @@ -9,6 +9,7 @@
from itertools import dropwhile

import django
from django.conf import settings
from django.core.management.base import CommandError, BaseCommand
from django.core.management.utils import (handle_extensions, find_command,
popen_wrapper)
Expand Down Expand Up @@ -56,8 +57,6 @@ def process(self, command, domain):
Uses the xgettext GNU gettext utility.
"""

from django.conf import settings
from django.utils.translation import templatize

if command.verbosity > 1:
Expand Down Expand Up @@ -218,9 +217,20 @@ def handle(self, *args, **options):
process_all = options.get('all')
extensions = options.get('extensions')
self.symlinks = options.get('symlinks')

# Need to ensure that the i18n framework is enabled
if settings.configured:
settings.USE_I18N = True
else:
settings.configure(USE_I18N=True)

ignore_patterns = options.get('ignore_patterns')
if options.get('use_default_ignore_patterns'):
ignore_patterns += ['CVS', '.*', '*~', '*.pyc']
base_path = os.path.abspath('.')
for path in (settings.MEDIA_ROOT, settings.STATIC_ROOT):
if path and path.startswith(base_path):
ignore_patterns.append('%s*' % path[len(base_path) + 1:])
self.ignore_patterns = list(set(ignore_patterns))

# Avoid messing with mutable class variables
Expand Down Expand Up @@ -251,13 +261,6 @@ def handle(self, *args, **options):
raise CommandError("Type '%s help %s' for usage information." % (
os.path.basename(sys.argv[0]), sys.argv[1]))

# Need to ensure that the i18n framework is enabled
from django.conf import settings
if settings.configured:
settings.USE_I18N = True
else:
settings.configure(USE_I18N=True)

if self.verbosity > 1:
self.stdout.write('examining files with the extensions: %s\n'
% get_text_list(list(self.extensions), 'and'))
Expand Down
20 changes: 16 additions & 4 deletions tests/i18n/test_extraction.py
Expand Up @@ -25,12 +25,13 @@

LOCALE = 'de'
has_xgettext = find_command('xgettext')
this_directory = os.path.dirname(upath(__file__))


@skipUnless(has_xgettext, 'xgettext is mandatory for extraction tests')
class ExtractorTests(SimpleTestCase):

test_dir = os.path.abspath(os.path.join(os.path.dirname(upath(__file__)), 'commands'))
test_dir = os.path.abspath(os.path.join(this_directory, 'commands'))

PO_FILE = 'locale/%s/LC_MESSAGES/django.po' % LOCALE

Expand Down Expand Up @@ -378,6 +379,17 @@ def test_ignore_option(self):
self.assertNotMsgId('This should be ignored.', po_contents)
self.assertNotMsgId('This should be ignored too.', po_contents)

@override_settings(
STATIC_ROOT=os.path.join(this_directory, 'commands', 'static_root/'),
MEDIA_ROOT=os.path.join(this_directory, 'commands', 'media_root/'))
def test_media_static_dirs_ignored(self):
os.chdir(self.test_dir)
stdout = StringIO()
management.call_command('makemessages', locale=[LOCALE], verbosity=2, stdout=stdout)
data = stdout.getvalue()
self.assertIn("ignoring directory static_root", data)
self.assertIn("ignoring directory media_root", data)


class SymlinkExtractorTests(ExtractorTests):

Expand Down Expand Up @@ -550,7 +562,7 @@ class ExcludedLocaleExtractionTests(ExtractorTests):
LOCALES = ['en', 'fr', 'it']
PO_FILE = 'locale/%s/LC_MESSAGES/django.po'

test_dir = os.path.abspath(os.path.join(os.path.dirname(upath(__file__)), 'exclude'))
test_dir = os.path.abspath(os.path.join(this_directory, 'exclude'))

def _set_times_for_all_po_files(self):
"""
Expand Down Expand Up @@ -608,7 +620,7 @@ class CustomLayoutExtractionTests(ExtractorTests):

def setUp(self):
self._cwd = os.getcwd()
self.test_dir = os.path.join(os.path.dirname(upath(__file__)), 'project_dir')
self.test_dir = os.path.join(this_directory, 'project_dir')

def test_no_locale_raises(self):
os.chdir(self.test_dir)
Expand All @@ -618,7 +630,7 @@ def test_no_locale_raises(self):

@override_settings(
LOCALE_PATHS=(os.path.join(
os.path.dirname(upath(__file__)), 'project_dir', 'project_locale'),)
this_directory, 'project_dir', 'project_locale'),)
)
def test_project_locale_paths(self):
"""
Expand Down

0 comments on commit 28efafa

Please sign in to comment.