Skip to content

Commit 5f59901

Browse files
committed
Cleanups, catch KeyError explicitly if mapping_file is not defined
1 parent 3c4e65f commit 5f59901

File tree

1 file changed

+4
-5
lines changed
  • django_babel/management/commands

1 file changed

+4
-5
lines changed

django_babel/management/commands/babel.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,16 @@ def handle_makemessages(self, **options):
4545
if mapping_file is None and 'extract_messages' in distribution.command_options:
4646
opts = distribution.command_options['extract_messages']
4747
try:
48-
mapping_file = opts.get('mapping_file', ())[1]
49-
except IndexError:
48+
mapping_file = opts['mapping_file'][1]
49+
except (IndexError, KeyError):
5050
mapping_file = None
5151

5252
for path in locale_paths:
5353
potfile = os.path.join(path, '%s.pot' % domain)
5454
if not os.path.exists(potfile):
5555
continue
5656

57-
cmd = ['pybabel', 'extract', '-o',
58-
os.path.join(path, '%s.pot' % domain)]
57+
cmd = ['pybabel', 'extract', '-o', potfile]
5958

6059
if mapping_file is not None:
6160
cmd.extend(['-F', mapping_file])
@@ -66,7 +65,7 @@ def handle_makemessages(self, **options):
6665

6766
for locale in locales:
6867
cmd = ['pybabel', 'update', '-D', domain,
69-
'-i', os.path.join(path, '%s.pot' % domain),
68+
'-i', potfile,
7069
'-d', path,
7170
'-l', locale]
7271
call(cmd)

0 commit comments

Comments
 (0)