diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py
index 95c1da0..fa4ae19 100644
a
|
b
|
def _popen(cmd):
|
44 | 44 | p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, close_fds=os.name != 'nt', universal_newlines=True) |
45 | 45 | return p.communicate() |
46 | 46 | |
47 | | def walk(root, topdown=True, onerror=None, followlinks=False): |
| 47 | def walk(root, topdown=True, onerror=None, followlinks=False, ignore_patterns=[], verbosity=0, stdout=None): |
48 | 48 | """ |
49 | 49 | A version of os.walk that can follow symlinks for Python < 2.6 |
50 | 50 | """ |
| 51 | norm_patterns = map(lambda p:p.endswith('/*') and p[:-2] or p, ignore_patterns) |
51 | 52 | for dirpath, dirnames, filenames in os.walk(root, topdown, onerror): |
| 53 | remove_dirs = [] |
| 54 | for dirname in dirnames: |
| 55 | if is_ignored(os.path.normpath(os.path.join(dirpath, dirname)), norm_patterns): |
| 56 | remove_dirs.append(dirname) |
| 57 | for dirname in remove_dirs: |
| 58 | dirnames.remove(dirname) |
| 59 | if verbosity > 1: |
| 60 | stdout.write('ignoring directory %s\n' % dirname) |
52 | 61 | yield (dirpath, dirnames, filenames) |
53 | 62 | if followlinks: |
54 | 63 | for d in dirnames: |
… |
… |
def is_ignored(path, ignore_patterns):
|
66 | 75 | return True |
67 | 76 | return False |
68 | 77 | |
69 | | def find_files(root, ignore_patterns, verbosity, symlinks=False): |
| 78 | def find_files(root, ignore_patterns, verbosity, stdout, symlinks=False): |
70 | 79 | """ |
71 | 80 | Helper function to get all files in the given root. |
72 | 81 | """ |
73 | 82 | all_files = [] |
74 | | for (dirpath, dirnames, filenames) in walk(".", followlinks=symlinks): |
| 83 | for (dirpath, dirnames, filenames) in walk(".", followlinks=symlinks, |
| 84 | ignore_patterns=ignore_patterns, verbosity=verbosity, stdout=stdout): |
75 | 85 | for f in filenames: |
76 | 86 | norm_filepath = os.path.normpath(os.path.join(dirpath, f)) |
77 | 87 | if is_ignored(norm_filepath, ignore_patterns): |
78 | 88 | if verbosity > 1: |
79 | | sys.stdout.write('ignoring file %s in %s\n' % (f, dirpath)) |
| 89 | stdout.write('ignoring file %s in %s\n' % (f, dirpath)) |
80 | 90 | else: |
81 | 91 | all_files.extend([(dirpath, f)]) |
82 | 92 | all_files.sort() |
83 | 93 | return all_files |
84 | 94 | |
85 | | def copy_plural_forms(msgs, locale, domain, verbosity): |
| 95 | def copy_plural_forms(msgs, locale, domain, verbosity, stdout): |
86 | 96 | """ |
87 | 97 | Copies plural forms header contents from a Django catalog of locale to |
88 | 98 | the msgs string, inserting it at the right place. msgs should be the |
… |
… |
def copy_plural_forms(msgs, locale, domain, verbosity):
|
100 | 110 | m = plural_forms_re.search(open(django_po, 'rU').read()) |
101 | 111 | if m: |
102 | 112 | if verbosity > 1: |
103 | | sys.stderr.write("copying plural forms: %s\n" % m.group('value')) |
| 113 | stdout.write("copying plural forms: %s\n" % m.group('value')) |
104 | 114 | lines = [] |
105 | 115 | seen = False |
106 | 116 | for line in msgs.split('\n'): |
… |
… |
def write_pot_file(potfile, msgs, file, work_file, is_templatized):
|
133 | 143 | f.close() |
134 | 144 | |
135 | 145 | def process_file(file, dirpath, potfile, domain, verbosity, extensions, wrap, |
136 | | location): |
| 146 | location, stdout): |
137 | 147 | """ |
138 | 148 | Extract translatable literals from :param file: for :param domain: |
139 | 149 | creating or updating the :param potfile: POT file. |
… |
… |
def process_file(file, dirpath, potfile, domain, verbosity, extensions, wrap,
|
144 | 154 | from django.utils.translation import templatize |
145 | 155 | |
146 | 156 | if verbosity > 1: |
147 | | sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) |
| 157 | stdout.write('processing file %s in %s\n' % (file, dirpath)) |
148 | 158 | _, file_ext = os.path.splitext(file) |
149 | 159 | if domain == 'djangojs' and file_ext in extensions: |
150 | 160 | is_templatized = True |
… |
… |
def process_file(file, dirpath, potfile, domain, verbosity, extensions, wrap,
|
206 | 216 | if is_templatized: |
207 | 217 | os.unlink(work_file) |
208 | 218 | |
209 | | def write_po_file(pofile, potfile, domain, locale, verbosity, |
| 219 | def write_po_file(pofile, potfile, domain, locale, verbosity, stdout, |
210 | 220 | copy_pforms, wrap, location, no_obsolete): |
211 | 221 | """ |
212 | 222 | Creates of updates the :param pofile: PO file for :param domain: and :param |
… |
… |
def write_po_file(pofile, potfile, domain, locale, verbosity,
|
232 | 242 | raise CommandError( |
233 | 243 | "errors happened while running msgmerge\n%s" % errors) |
234 | 244 | elif copy_pforms: |
235 | | msgs = copy_plural_forms(msgs, locale, domain, verbosity) |
| 245 | msgs = copy_plural_forms(msgs, locale, domain, verbosity, stdout) |
236 | 246 | msgs = msgs.replace( |
237 | 247 | "#. #-#-#-#-# %s.pot (PACKAGE VERSION) #-#-#-#-#\n" % domain, "") |
238 | 248 | f = open(pofile, 'wb') |
… |
… |
def write_po_file(pofile, potfile, domain, locale, verbosity,
|
250 | 260 | |
251 | 261 | def make_messages(locale=None, domain='django', verbosity=1, all=False, |
252 | 262 | extensions=None, symlinks=False, ignore_patterns=None, no_wrap=False, |
253 | | no_location=False, no_obsolete=False): |
| 263 | no_location=False, no_obsolete=False, stdout=sys.stdout): |
254 | 264 | """ |
255 | 265 | Uses the ``locale/`` directory from the Django SVN tree or an |
256 | 266 | application/project to process all files with translatable literals for |
… |
… |
def make_messages(locale=None, domain='django', verbosity=1, all=False,
|
312 | 322 | |
313 | 323 | for locale in locales: |
314 | 324 | if verbosity > 0: |
315 | | print "processing language", locale |
| 325 | stdout.write("processing language %s" % locale) |
316 | 326 | basedir = os.path.join(localedir, locale, 'LC_MESSAGES') |
317 | 327 | if not os.path.isdir(basedir): |
318 | 328 | os.makedirs(basedir) |
… |
… |
def make_messages(locale=None, domain='django', verbosity=1, all=False,
|
324 | 334 | os.unlink(potfile) |
325 | 335 | |
326 | 336 | for dirpath, file in find_files(".", ignore_patterns, verbosity, |
327 | | symlinks=symlinks): |
| 337 | stdout, symlinks=symlinks): |
328 | 338 | process_file(file, dirpath, potfile, domain, verbosity, extensions, |
329 | | wrap, location) |
| 339 | wrap, location, stdout) |
330 | 340 | |
331 | 341 | if os.path.exists(potfile): |
332 | | write_po_file(pofile, potfile, domain, locale, verbosity, |
| 342 | write_po_file(pofile, potfile, domain, locale, verbosity, stdout, |
333 | 343 | not invoked_for_django, wrap, location, no_obsolete) |
334 | 344 | |
335 | 345 | |
… |
… |
class Command(NoArgsCommand):
|
386 | 396 | extensions = handle_extensions(extensions or ['html', 'txt']) |
387 | 397 | |
388 | 398 | if verbosity > 1: |
389 | | sys.stdout.write('examining files with the extensions: %s\n' |
| 399 | self.stdout.write('examining files with the extensions: %s\n' |
390 | 400 | % get_text_list(list(extensions), 'and')) |
391 | 401 | |
392 | | make_messages(locale, domain, verbosity, process_all, extensions, symlinks, ignore_patterns, no_wrap, no_location, no_obsolete) |
| 402 | make_messages(locale, domain, verbosity, process_all, extensions, symlinks, ignore_patterns, no_wrap, no_location, no_obsolete, self.stdout) |
diff --git a/tests/regressiontests/i18n/commands/extraction.py b/tests/regressiontests/i18n/commands/extraction.py
index b1fc002..4eb7abc 100644
a
|
b
|
from __future__ import with_statement
|
4 | 4 | import os |
5 | 5 | import re |
6 | 6 | import shutil |
| 7 | from StringIO import StringIO |
7 | 8 | |
8 | 9 | from django.core import management |
9 | 10 | from django.test import TestCase |
… |
… |
class IgnoredExtractorTests(ExtractorTests):
|
177 | 178 | def test_ignore_option(self): |
178 | 179 | os.chdir(self.test_dir) |
179 | 180 | pattern1 = os.path.join('ignore_dir', '*') |
180 | | management.call_command('makemessages', locale=LOCALE, verbosity=0, ignore_patterns=[pattern1]) |
| 181 | stdout = StringIO() |
| 182 | management.call_command('makemessages', locale=LOCALE, verbosity=2, |
| 183 | ignore_patterns=[pattern1], stdout=stdout) |
| 184 | data = stdout.getvalue() |
| 185 | self.assertTrue("ignoring directory ignore_dir" in data) |
181 | 186 | self.assertTrue(os.path.exists(self.PO_FILE)) |
182 | 187 | with open(self.PO_FILE, 'r') as fp: |
183 | 188 | po_contents = fp.read() |