1
0
mirror of https://github.com/django/django.git synced 2025-03-03 05:24:24 +00:00

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
This commit is contained in:
Jannis Leidel 2011-02-12 19:12:21 +00:00
parent 632d9f994f
commit 204e83e331

View File

@ -201,7 +201,13 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
) )
msgs, errors = _popen(cmd) msgs, errors = _popen(cmd)
if errors: 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:] old = '#: ' + os.path.join(dirpath, thefile)[2:]
new = '#: ' + os.path.join(dirpath, file)[2:] new = '#: ' + os.path.join(dirpath, file)[2:]
msgs = msgs.replace(old, new) 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'))) msgs = '\n'.join(dropwhile(len, msgs.split('\n')))
else: else:
msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8') msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
if msgs:
f = open(potfile, 'ab') f = open(potfile, 'ab')
try: try:
f.write(msgs) f.write(msgs)
@ -242,8 +247,14 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
) )
msgs, errors = _popen(cmd) msgs, errors = _popen(cmd)
if errors: 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: if thefile != file:
old = '#: ' + os.path.join(dirpath, thefile)[2:] old = '#: ' + os.path.join(dirpath, thefile)[2:]
new = '#: ' + orig_file[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'))) msgs = '\n'.join(dropwhile(len, msgs.split('\n')))
else: else:
msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8') msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
if msgs:
f = open(potfile, 'ab') f = open(potfile, 'ab')
try: try:
f.write(msgs) 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"' % msgs, errors = _popen('msguniq %s --to-code=utf-8 "%s"' %
(wrap, potfile)) (wrap, potfile))
if errors: 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') f = open(potfile, 'w')
try: try:
f.write(msgs) f.write(msgs)
finally: finally:
f.close() f.close()
if os.path.exists(pofile):
msgs, errors = _popen('msgmerge %s -q "%s" "%s"' % msgs, errors = _popen('msgmerge %s -q "%s" "%s"' %
(wrap, pofile, potfile)) (wrap, pofile, potfile))
if errors: 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: elif not invoked_for_django:
msgs = copy_plural_forms(msgs, locale, domain, verbosity) msgs = copy_plural_forms(msgs, locale, domain, verbosity)
msgs = msgs.replace( 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"' % msgs, errors = _popen('msgattrib %s -o "%s" --no-obsolete "%s"' %
(wrap, pofile, pofile)) (wrap, pofile, pofile))
if errors: 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): class Command(NoArgsCommand):