Commit 204e83e3 authored by Jannis Leidel's avatar Jannis Leidel
Browse files

Fixed #8536 -- Made sure the makemessages management command cleans up after...

Fixed #8536 -- Made sure the makemessages management command cleans up after throwing an error. Thanks to Ramiro for the initial patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15506 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 632d9f99
Loading
Loading
Loading
Loading
+43 −28
Original line number Diff line number Diff line
@@ -201,7 +201,13 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
                )
                msgs, errors = _popen(cmd)
                if errors:
                    raise CommandError("errors happened while running xgettext on %s\n%s" % (file, errors))
                    os.unlink(os.path.join(dirpath, thefile))
                    if os.path.exists(potfile):
                        os.unlink(potfile)
                    raise CommandError(
                        "errors happened while running xgettext on %s\n%s" %
                        (file, errors))
                if msgs:
                    old = '#: ' + os.path.join(dirpath, thefile)[2:]
                    new = '#: ' + os.path.join(dirpath, file)[2:]
                    msgs = msgs.replace(old, new)
@@ -210,7 +216,6 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
                        msgs = '\n'.join(dropwhile(len, msgs.split('\n')))
                    else:
                        msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
                if msgs:
                    f = open(potfile, 'ab')
                    try:
                        f.write(msgs)
@@ -242,8 +247,14 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
                )
                msgs, errors = _popen(cmd)
                if errors:
                    raise CommandError("errors happened while running xgettext on %s\n%s" % (file, errors))

                    if thefile != file:
                        os.unlink(os.path.join(dirpath, thefile))
                    if os.path.exists(potfile):
                        os.unlink(potfile)
                    raise CommandError(
                        "errors happened while running xgettext on %s\n%s" %
                        (file, errors))
                if msgs:
                    if thefile != file:
                        old = '#: ' + os.path.join(dirpath, thefile)[2:]
                        new = '#: ' + orig_file[2:]
@@ -253,7 +264,6 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
                        msgs = '\n'.join(dropwhile(len, msgs.split('\n')))
                    else:
                        msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
                if msgs:
                    f = open(potfile, 'ab')
                    try:
                        f.write(msgs)
@@ -266,17 +276,21 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
            msgs, errors = _popen('msguniq %s --to-code=utf-8 "%s"' %
                                  (wrap, potfile))
            if errors:
                raise CommandError("errors happened while running msguniq\n%s" % errors)
                os.unlink(potfile)
                raise CommandError(
                    "errors happened while running msguniq\n%s" % errors)
            if os.path.exists(pofile):
                f = open(potfile, 'w')
                try:
                    f.write(msgs)
                finally:
                    f.close()
            if os.path.exists(pofile):
                msgs, errors = _popen('msgmerge %s -q "%s" "%s"' %
                                      (wrap, pofile, potfile))
                if errors:
                    raise CommandError("errors happened while running msgmerge\n%s" % errors)
                    os.unlink(potfile)
                    raise CommandError(
                        "errors happened while running msgmerge\n%s" % errors)
            elif not invoked_for_django:
                msgs = copy_plural_forms(msgs, locale, domain, verbosity)
            msgs = msgs.replace(
@@ -291,7 +305,8 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
                msgs, errors = _popen('msgattrib %s -o "%s" --no-obsolete "%s"' %
                                      (wrap, pofile, pofile))
                if errors:
                    raise CommandError("errors happened while running msgattrib\n%s" % errors)
                    raise CommandError(
                        "errors happened while running msgattrib\n%s" % errors)


class Command(NoArgsCommand):