Ticket #11869: 11869-1.diff

File 11869-1.diff, 3.7 KB (added by ramiro, 5 years ago)

Patch that fixes this issue

  • django/core/management/commands/makemessages.py

    diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py
    a b  
    22import os
    33import sys
    44import glob
    5 import warnings
    65from itertools import dropwhile
    76from optparse import make_option
    87from subprocess import PIPE, Popen
     
    3635    # trick xgettext to parse them as Python files)
    3736    return set([x for x in ext_list if x != '.py'])
    3837
     38def _popen3(cmd):
     39    p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, close_fds=os.name != 'nt', universal_newlines=True)
     40    return p.communicate()
     41
    3942def make_messages(locale=None, domain='django', verbosity='1', all=False, extensions=None):
    4043    """
    4144    Uses the locale directory from the Django SVN tree or an application/
     
    6972        raise CommandError(message)
    7073
    7174    # 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())
     75    output = _popen3('xgettext --version')[0]
     76    match = re.search(r'(?P<major>\d+)\.(?P<minor>\d+)', output)
    7477    if match:
    7578        xversion = (int(match.group('major')), int(match.group('minor')))
    7679        if xversion < (0, 15):
     
    110113                thefile = '%s.py' % file
    111114                open(os.path.join(dirpath, thefile), "w").write(src)
    112115                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()
     116                msgs, errors = _popen3(cmd)
    116117                if errors:
    117118                    raise CommandError("errors happened while running xgettext on %s\n%s" % (file, errors))
    118119                old = '#: '+os.path.join(dirpath, thefile)[2:]
     
    140141                    sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
    141142                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"' % (
    142143                    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()
     144                msgs, errors = _popen3(cmd)
    146145                if errors:
    147146                    raise CommandError("errors happened while running xgettext on %s\n%s" % (file, errors))
    148147
     
    161160                    os.unlink(os.path.join(dirpath, thefile))
    162161
    163162        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()
     163            msgs, errors = _popen3('msguniq --to-code=utf-8 "%s"' % potfile)
    167164            if errors:
    168165                raise CommandError("errors happened while running msguniq\n%s" % errors)
    169166            open(potfile, 'w').write(msgs)
    170167            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()
     168                msgs, errors = _popen3('msgmerge -q "%s" "%s"' % (pofile, potfile))
    174169                if errors:
    175170                    raise CommandError("errors happened while running msgmerge\n%s" % errors)
    176171            open(pofile, 'wb').write(msgs)
Back to Top