mirror of https://github.com/django/django.git
Fixed #11869 - Prevent deadlocks when calling gettext utilities on Windows. Also fixes #12783. Thanks Ramiro Morales and soulburner.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12383 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
a28bd76bb6
commit
cdeb90e345
|
@ -2,7 +2,6 @@ import re
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import glob
|
import glob
|
||||||
import warnings
|
|
||||||
from itertools import dropwhile
|
from itertools import dropwhile
|
||||||
from optparse import make_option
|
from optparse import make_option
|
||||||
from subprocess import PIPE, Popen
|
from subprocess import PIPE, Popen
|
||||||
|
@ -36,6 +35,13 @@ def handle_extensions(extensions=('html',)):
|
||||||
# trick xgettext to parse them as Python files)
|
# trick xgettext to parse them as Python files)
|
||||||
return set([x for x in ext_list if x != '.py'])
|
return set([x for x in ext_list if x != '.py'])
|
||||||
|
|
||||||
|
def _popen(cmd):
|
||||||
|
"""
|
||||||
|
Friendly wrapper around Popen for Windows
|
||||||
|
"""
|
||||||
|
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 make_messages(locale=None, domain='django', verbosity='1', all=False, extensions=None):
|
||||||
"""
|
"""
|
||||||
Uses the locale directory from the Django SVN tree or an application/
|
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
|
||||||
raise CommandError(message)
|
raise CommandError(message)
|
||||||
|
|
||||||
# We require gettext version 0.15 or newer.
|
# We require gettext version 0.15 or newer.
|
||||||
p = Popen('xgettext --version', shell=True, stdout=PIPE, stderr=PIPE)
|
output = _popen('xgettext --version')[0]
|
||||||
match = re.search(r'(?P<major>\d+)\.(?P<minor>\d+)', p.stdout.read())
|
match = re.search(r'(?P<major>\d+)\.(?P<minor>\d+)', output)
|
||||||
if match:
|
if match:
|
||||||
xversion = (int(match.group('major')), int(match.group('minor')))
|
xversion = (int(match.group('major')), int(match.group('minor')))
|
||||||
if xversion < (0, 15):
|
if xversion < (0, 15):
|
||||||
|
@ -110,9 +116,7 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False, extens
|
||||||
thefile = '%s.py' % file
|
thefile = '%s.py' % file
|
||||||
open(os.path.join(dirpath, thefile), "w").write(src)
|
open(os.path.join(dirpath, thefile), "w").write(src)
|
||||||
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))
|
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))
|
||||||
p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
|
msgs, errors = _popen(cmd)
|
||||||
msgs = p.stdout.read()
|
|
||||||
errors = p.stderr.read()
|
|
||||||
if errors:
|
if errors:
|
||||||
raise CommandError("errors happened while running xgettext on %s\n%s" % (file, errors))
|
raise CommandError("errors happened while running xgettext on %s\n%s" % (file, errors))
|
||||||
old = '#: '+os.path.join(dirpath, thefile)[2:]
|
old = '#: '+os.path.join(dirpath, thefile)[2:]
|
||||||
|
@ -140,9 +144,7 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False, extens
|
||||||
sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
|
sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
|
||||||
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"' % (
|
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"' % (
|
||||||
domain, os.path.join(dirpath, thefile))
|
domain, os.path.join(dirpath, thefile))
|
||||||
p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
|
msgs, errors = _popen(cmd)
|
||||||
msgs = p.stdout.read()
|
|
||||||
errors = p.stderr.read()
|
|
||||||
if errors:
|
if errors:
|
||||||
raise CommandError("errors happened while running xgettext on %s\n%s" % (file, errors))
|
raise CommandError("errors happened while running xgettext on %s\n%s" % (file, errors))
|
||||||
|
|
||||||
|
@ -161,16 +163,12 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False, extens
|
||||||
os.unlink(os.path.join(dirpath, thefile))
|
os.unlink(os.path.join(dirpath, thefile))
|
||||||
|
|
||||||
if os.path.exists(potfile):
|
if os.path.exists(potfile):
|
||||||
p = Popen('msguniq --to-code=utf-8 "%s"' % potfile, shell=True, stdout=PIPE, stderr=PIPE)
|
msgs, errors = _popen('msguniq --to-code=utf-8 "%s"' % potfile)
|
||||||
msgs = p.stdout.read()
|
|
||||||
errors = p.stderr.read()
|
|
||||||
if errors:
|
if errors:
|
||||||
raise CommandError("errors happened while running msguniq\n%s" % errors)
|
raise CommandError("errors happened while running msguniq\n%s" % errors)
|
||||||
open(potfile, 'w').write(msgs)
|
open(potfile, 'w').write(msgs)
|
||||||
if os.path.exists(pofile):
|
if os.path.exists(pofile):
|
||||||
p = Popen('msgmerge -q "%s" "%s"' % (pofile, potfile), shell=True, stdout=PIPE, stderr=PIPE)
|
msgs, errors = _popen('msgmerge -q "%s" "%s"' % (pofile, potfile))
|
||||||
msgs = p.stdout.read()
|
|
||||||
errors = p.stderr.read()
|
|
||||||
if errors:
|
if errors:
|
||||||
raise CommandError("errors happened while running msgmerge\n%s" % errors)
|
raise CommandError("errors happened while running msgmerge\n%s" % errors)
|
||||||
open(pofile, 'wb').write(msgs)
|
open(pofile, 'wb').write(msgs)
|
||||||
|
|
Loading…
Reference in New Issue