Fixed #22336 -- Added path matching for makemessages ignore option

This fixes a regression introduced by 9012a9e200.
This commit is contained in:
Justin Hamade 2014-08-08 22:47:35 +02:00 committed by Claude Paroz
parent 09c0fa2c53
commit 8fe406864c
3 changed files with 33 additions and 18 deletions

View File

@ -360,7 +360,8 @@ class Command(BaseCommand):
Check if the given path should be ignored or not.
"""
filename = os.path.basename(path)
ignore = lambda pattern: fnmatch.fnmatchcase(filename, pattern)
ignore = lambda pattern: (fnmatch.fnmatchcase(filename, pattern) or
fnmatch.fnmatchcase(path, pattern))
return any(ignore(pattern) for pattern in ignore_patterns)
dir_suffix = '%s*' % os.sep

View File

@ -0,0 +1,2 @@
{% load i18n %}
{% trans "This subdir should be ignored too." %}

View File

@ -360,35 +360,47 @@ class JavascriptExtractorTests(ExtractorTests):
class IgnoredExtractorTests(ExtractorTests):
def test_ignore_option(self):
def _run_makemessages(self, **options):
os.chdir(self.test_dir)
ignore_patterns = [
os.path.join('ignore_dir', '*'),
'xxx_*',
]
stdout = StringIO()
management.call_command('makemessages', locale=[LOCALE], verbosity=2,
ignore_patterns=ignore_patterns, stdout=stdout)
stdout=stdout, **options)
data = stdout.getvalue()
self.assertTrue("ignoring directory ignore_dir" in data)
self.assertTrue("ignoring file xxx_ignored.html" in data)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
po_contents = fp.read()
self.assertMsgId('This literal should be included.', po_contents)
self.assertNotMsgId('This should be ignored.', po_contents)
self.assertNotMsgId('This should be ignored too.', po_contents)
return data, po_contents
def test_ignore_directory(self):
out, po_contents = self._run_makemessages(ignore_patterns=[
os.path.join('ignore_dir', '*'),
])
self.assertTrue("ignoring directory ignore_dir" in out)
self.assertMsgId('This literal should be included.', po_contents)
self.assertNotMsgId('This should be ignored.', po_contents)
def test_ignore_subdirectory(self):
out, po_contents = self._run_makemessages(ignore_patterns=[
'templates/*/ignore.html',
'templates/subdir/*',
])
self.assertTrue("ignoring directory subdir" in out)
self.assertNotMsgId('This subdir should be ignored too.', po_contents)
def test_ignore_file_patterns(self):
out, po_contents = self._run_makemessages(ignore_patterns=[
'xxx_*',
])
self.assertTrue("ignoring file xxx_ignored.html" in out)
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)
out, _ = self._run_makemessages()
self.assertIn("ignoring directory static_root", out)
self.assertIn("ignoring directory media_root", out)
class SymlinkExtractorTests(ExtractorTests):