Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #11869 - Prevent deadlocks when calling gettext utilities on Wi…

…ndows. Also fixes #12783. Thanks Ramiro Morales and soulburner.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12383 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit cdeb90e345b5458b0177347c9c630262a4913a56 1 parent a28bd76
Jannis Leidel authored February 05, 2010
28  django/core/management/commands/makemessages.py
@@ -2,7 +2,6 @@
2 2
 import os
3 3
 import sys
4 4
 import glob
5  
-import warnings
6 5
 from itertools import dropwhile
7 6
 from optparse import make_option
8 7
 from subprocess import PIPE, Popen
@@ -36,6 +35,13 @@ def handle_extensions(extensions=('html',)):
36 35
     # trick xgettext to parse them as Python files)
37 36
     return set([x for x in ext_list if x != '.py'])
38 37
 
  38
+def _popen(cmd):
  39
+    """
  40
+    Friendly wrapper around Popen for Windows
  41
+    """
  42
+    p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, close_fds=os.name != 'nt', universal_newlines=True)
  43
+    return p.communicate()
  44
+
39 45
 def make_messages(locale=None, domain='django', verbosity='1', all=False, extensions=None):
40 46
     """
41 47
     Uses the locale directory from the Django SVN tree or an application/
@@ -69,8 +75,8 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False, extens
69 75
         raise CommandError(message)
70 76
 
71 77
     # We require gettext version 0.15 or newer.
72  
-    p = Popen('xgettext --version', shell=True, stdout=PIPE, stderr=PIPE)
73  
-    match = re.search(r'(?P<major>\d+)\.(?P<minor>\d+)', p.stdout.read())
  78
+    output = _popen('xgettext --version')[0]
  79
+    match = re.search(r'(?P<major>\d+)\.(?P<minor>\d+)', output)
74 80
     if match:
75 81
         xversion = (int(match.group('major')), int(match.group('minor')))
76 82
         if xversion < (0, 15):
@@ -110,9 +116,7 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False, extens
110 116
                 thefile = '%s.py' % file
111 117
                 open(os.path.join(dirpath, thefile), "w").write(src)
112 118
                 cmd = 'xgettext -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (domain, os.path.join(dirpath, thefile))
113  
-                p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
114  
-                msgs = p.stdout.read()
115  
-                errors = p.stderr.read()
  119
+                msgs, errors = _popen(cmd)
116 120
                 if errors:
117 121
                     raise CommandError("errors happened while running xgettext on %s\n%s" % (file, errors))
118 122
                 old = '#: '+os.path.join(dirpath, thefile)[2:]
@@ -140,9 +144,7 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False, extens
140 144
                     sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
141 145
                 cmd = 'xgettext -d %s -L Python --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --keyword=ugettext_noop --keyword=ugettext_lazy --keyword=ungettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (
142 146
                     domain, os.path.join(dirpath, thefile))
143  
-                p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
144  
-                msgs = p.stdout.read()
145  
-                errors = p.stderr.read()
  147
+                msgs, errors = _popen(cmd)
146 148
                 if errors:
147 149
                     raise CommandError("errors happened while running xgettext on %s\n%s" % (file, errors))
148 150
 
@@ -161,16 +163,12 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False, extens
161 163
                     os.unlink(os.path.join(dirpath, thefile))
162 164
 
163 165
         if os.path.exists(potfile):
164  
-            p = Popen('msguniq --to-code=utf-8 "%s"' % potfile, shell=True, stdout=PIPE, stderr=PIPE)
165  
-            msgs = p.stdout.read()
166  
-            errors = p.stderr.read()
  166
+            msgs, errors = _popen('msguniq --to-code=utf-8 "%s"' % potfile)
167 167
             if errors:
168 168
                 raise CommandError("errors happened while running msguniq\n%s" % errors)
169 169
             open(potfile, 'w').write(msgs)
170 170
             if os.path.exists(pofile):
171  
-                p = Popen('msgmerge -q "%s" "%s"' % (pofile, potfile), shell=True, stdout=PIPE, stderr=PIPE)
172  
-                msgs = p.stdout.read()
173  
-                errors = p.stderr.read()
  171
+                msgs, errors = _popen('msgmerge -q "%s" "%s"' % (pofile, potfile))
174 172
                 if errors:
175 173
                     raise CommandError("errors happened while running msgmerge\n%s" % errors)
176 174
             open(pofile, 'wb').write(msgs)

0 notes on commit cdeb90e

Please sign in to comment.
Something went wrong with that request. Please try again.