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
1 changed files with 43 additions and 28 deletions

View File

@ -201,16 +201,21 @@ 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))
old = '#: '+os.path.join(dirpath, thefile)[2:] if os.path.exists(potfile):
new = '#: '+os.path.join(dirpath, file)[2:] os.unlink(potfile)
msgs = msgs.replace(old, new) raise CommandError(
if os.path.exists(potfile): "errors happened while running xgettext on %s\n%s" %
# Strip the header (file, errors))
msgs = '\n'.join(dropwhile(len, msgs.split('\n')))
else:
msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
if msgs: if msgs:
old = '#: ' + os.path.join(dirpath, thefile)[2:]
new = '#: ' + os.path.join(dirpath, file)[2:]
msgs = msgs.replace(old, new)
if os.path.exists(potfile):
# Strip the header
msgs = '\n'.join(dropwhile(len, msgs.split('\n')))
else:
msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
f = open(potfile, 'ab') f = open(potfile, 'ab')
try: try:
f.write(msgs) f.write(msgs)
@ -242,18 +247,23 @@ 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 thefile != file: if os.path.exists(potfile):
old = '#: '+os.path.join(dirpath, thefile)[2:] os.unlink(potfile)
new = '#: '+orig_file[2:] raise CommandError(
msgs = msgs.replace(old, new) "errors happened while running xgettext on %s\n%s" %
if os.path.exists(potfile): (file, errors))
# Strip the header
msgs = '\n'.join(dropwhile(len, msgs.split('\n')))
else:
msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
if msgs: if msgs:
if thefile != file:
old = '#: ' + os.path.join(dirpath, thefile)[2:]
new = '#: ' + orig_file[2:]
msgs = msgs.replace(old, new)
if os.path.exists(potfile):
# Strip the header
msgs = '\n'.join(dropwhile(len, msgs.split('\n')))
else:
msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
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)
f = open(potfile, 'w') raise CommandError(
try: "errors happened while running msguniq\n%s" % errors)
f.write(msgs)
finally:
f.close()
if os.path.exists(pofile): if os.path.exists(pofile):
f = open(potfile, 'w')
try:
f.write(msgs)
finally:
f.close()
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):