Author: jezdez
Date: 2010-02-16 06:14:27 -0600 (Tue, 16 Feb 2010)
New Revision: 12443

Added:
   django/trunk/tests/regressiontests/makemessages/templates/
   django/trunk/tests/regressiontests/makemessages/templates/test.html
Modified:
   django/trunk/django/core/management/commands/makemessages.py
   django/trunk/docs/man/django-admin.1
   django/trunk/docs/ref/django-admin.txt
   django/trunk/docs/topics/i18n/localization.txt
   django/trunk/tests/regressiontests/makemessages/tests.py
Log:
Fixed #6380 - Follow symlinks when examining source code and templates for 
translation strings.

Modified: django/trunk/django/core/management/commands/makemessages.py
===================================================================
--- django/trunk/django/core/management/commands/makemessages.py        
2010-02-16 12:13:48 UTC (rev 12442)
+++ django/trunk/django/core/management/commands/makemessages.py        
2010-02-16 12:14:27 UTC (rev 12443)
@@ -43,8 +43,32 @@
     p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, close_fds=os.name != 
'nt', universal_newlines=True)
     return p.communicate()
 
-def make_messages(locale=None, domain='django', verbosity='1', all=False, 
extensions=None):
+def walk(root, topdown=True, onerror=None, followlinks=False):
     """
+    A version of os.walk that can follow symlinks for Python < 2.6
+    """
+    for dirpath, dirnames, filenames in os.walk(root, topdown, onerror):
+        yield (dirpath, dirnames, filenames)
+        if followlinks:
+            for d in dirnames:
+                p = os.path.join(dirpath, d)
+                if os.path.islink(p):
+                    for link_dirpath, link_dirnames, link_filenames in walk(p):
+                        yield (link_dirpath, link_dirnames, link_filenames)
+
+def find_files(root, symlinks=False):
+    """
+    Helper function to get all files in the given root.
+    """
+    all_files = []
+    for (dirpath, dirnames, filenames) in walk(".", followlinks=symlinks):
+        all_files.extend([(dirpath, f) for f in filenames])
+    all_files.sort()
+    return all_files
+
+def make_messages(locale=None, domain='django', verbosity='1', all=False,
+        extensions=None, symlinks=False):
+    """
     Uses the locale directory from the Django SVN tree or an application/
     project to process all
     """
@@ -103,11 +127,7 @@
         if os.path.exists(potfile):
             os.unlink(potfile)
 
-        all_files = []
-        for (dirpath, dirnames, filenames) in os.walk("."):
-            all_files.extend([(dirpath, f) for f in filenames])
-        all_files.sort()
-        for dirpath, file in all_files:
+        for dirpath, file in find_files(".", symlinks=symlinks):
             file_base, file_ext = os.path.splitext(file)
             if domain == 'djangojs' and file_ext in extensions:
                 if verbosity > 1:
@@ -184,6 +204,8 @@
             help='The domain of the message files (default: "django").'),
         make_option('--all', '-a', action='store_true', dest='all',
             default=False, help='Reexamines all source code and templates for 
new translation strings and updates all message files for all available 
languages.'),
+        make_option('--symlinks', '-s', action='store_true', dest='symlinks',
+            default=False, help='Follows symlinks to directories when 
examining source code and templates for translation strings.'),
         make_option('--extension', '-e', dest='extensions',
             help='The file extension(s) to examine (default: ".html", separate 
multiple extensions with commas, or use -e multiple times)',
             action='append'),
@@ -202,6 +224,7 @@
         verbosity = int(options.get('verbosity'))
         process_all = options.get('all')
         extensions = options.get('extensions')
+        symlinks = options.get('symlinks')
 
         if domain == 'djangojs':
             extensions = handle_extensions(extensions or ['js'])
@@ -211,4 +234,4 @@
         if verbosity > 1:
             sys.stdout.write('examining files with the extensions: %s\n' % 
get_text_list(list(extensions), 'and'))
 
-        make_messages(locale, domain, verbosity, process_all, extensions)
+        make_messages(locale, domain, verbosity, process_all, extensions, 
symlinks)

Modified: django/trunk/docs/man/django-admin.1
===================================================================
--- django/trunk/docs/man/django-admin.1        2010-02-16 12:13:48 UTC (rev 
12442)
+++ django/trunk/docs/man/django-admin.1        2010-02-16 12:14:27 UTC (rev 
12443)
@@ -46,7 +46,7 @@
 .B sqlall
 for the given app(s) in the current database.
 .TP
-.BI "makemessages [" "\-\-locale=LOCALE" "] [" "\-\-domain=DOMAIN" "] [" 
"\-\-extension=EXTENSION" "] [" "\-\-all" "]"
+.BI "makemessages [" "\-\-locale=LOCALE" "] [" "\-\-domain=DOMAIN" "] [" 
"\-\-extension=EXTENSION" "] [" "\-\-all" "] [" "\-\-symlinks" "]"
 Runs over the entire source tree of the current directory and pulls out all
 strings marked for translation. It creates (or updates) a message file in the
 conf/locale (in the django tree) or locale (for project and application) 
directory.
@@ -155,6 +155,10 @@
 The file extension(s) to examine (default: ".html", separate multiple
 extensions with commas, or use -e multiple times).
 .TP
+.I \-e, \-\-symlinks
+Follows symlinks to directories when examining source code and templates for
+translation strings.
+.TP
 .I \-a, \-\-all
 Process all available locales when using makemessages..SH "ENVIRONMENT"
 .TP

Modified: django/trunk/docs/ref/django-admin.txt
===================================================================
--- django/trunk/docs/ref/django-admin.txt      2010-02-16 12:13:48 UTC (rev 
12442)
+++ django/trunk/docs/ref/django-admin.txt      2010-02-16 12:14:27 UTC (rev 
12443)
@@ -471,9 +471,18 @@
 Use the ``--domain`` or ``-d`` option to change the domain of the messages 
files.
 Currently supported:
 
-       * ``django`` for all ``*.py`` and ``*.html`` files (default)
-       * ``djangojs`` for ``*.js`` files
+    * ``django`` for all ``*.py`` and ``*.html`` files (default)
+    * ``djangojs`` for ``*.js`` files
 
+.. django-admin-option:: --symlinks
+
+Use the ``--symlinks`` or ``-s`` option to follow symlinks to directories when
+looking for new translation strings.
+
+Example usage::
+
+    django-admin.py makemessages --locale=de --symlinks
+
 reset <appname appname ...>
 ---------------------------
 

Modified: django/trunk/docs/topics/i18n/localization.txt
===================================================================
--- django/trunk/docs/topics/i18n/localization.txt      2010-02-16 12:13:48 UTC 
(rev 12442)
+++ django/trunk/docs/topics/i18n/localization.txt      2010-02-16 12:14:27 UTC 
(rev 12443)
@@ -78,10 +78,10 @@
     * The root directory of your Django project.
     * The root directory of your Django app.
 
-Th script runs over your project source tree or your application source tree 
and
-pulls out all strings marked for translation. It creates (or updates) a message
-file in the directory ``locale/LANG/LC_MESSAGES``. In the ``de`` example, the
-file will be ``locale/de/LC_MESSAGES/django.po``.
+The script runs over your project source tree or your application source tree
+and pulls out all strings marked for translation. It creates (or updates) a
+message file in the directory ``locale/LANG/LC_MESSAGES``. In the ``de``
+example, the file will be ``locale/de/LC_MESSAGES/django.po``.
 
 By default ``django-admin.py makemessages`` examines every file that has the
 ``.html`` file extension. In case you want to override that default, use the

Added: django/trunk/tests/regressiontests/makemessages/templates/test.html
===================================================================
--- django/trunk/tests/regressiontests/makemessages/templates/test.html         
                (rev 0)
+++ django/trunk/tests/regressiontests/makemessages/templates/test.html 
2010-02-16 12:14:27 UTC (rev 12443)
@@ -0,0 +1,2 @@
+{% load i18n %}
+{% trans "This literal should be included." %}
\ No newline at end of file

Modified: django/trunk/tests/regressiontests/makemessages/tests.py
===================================================================
--- django/trunk/tests/regressiontests/makemessages/tests.py    2010-02-16 
12:13:48 UTC (rev 12442)
+++ django/trunk/tests/regressiontests/makemessages/tests.py    2010-02-16 
12:14:27 UTC (rev 12443)
@@ -40,3 +40,34 @@
         po_contents = open(self.PO_FILE, 'r').read()
         self.assertMsgId('This literal should be included.', po_contents)
         self.assertMsgId('This one as well.', po_contents)
+
+class SymlinkExtractorTests(ExtractorTests):
+
+    PO_FILE='locale/%s/LC_MESSAGES/django.po' % LOCALE
+
+    def setUp(self):
+        self._cwd = os.getcwd()
+        self.test_dir = os.path.abspath(os.path.dirname(__file__))
+        self.symlinked_dir = os.path.join(self.test_dir, 'templates_symlinked')
+
+    def tearDown(self):
+        super(SymlinkExtractorTests, self).tearDown()
+        os.chdir(self.test_dir)
+        try:
+            os.remove(self.symlinked_dir)
+        except OSError:
+            pass
+        os.chdir(self._cwd)
+
+    def test_symlink(self):
+        if hasattr(os, 'symlink'):
+            if os.path.exists(self.symlinked_dir):
+                self.assert_(os.path.islink(self.symlinked_dir))
+            else:
+                os.symlink(os.path.join(self.test_dir, 'templates'), 
self.symlinked_dir)
+            os.chdir(self.test_dir)
+            management.call_command('makemessages', locale=LOCALE, 
verbosity=0, symlinks=True)
+            self.assert_(os.path.exists(self.PO_FILE))
+            po_contents = open(self.PO_FILE, 'r').read()
+            self.assertMsgId('This literal should be included.', po_contents)
+            self.assert_('templates_symlinked/test.html' in po_contents)

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to