Handle more file closing with "with"

This commit is contained in:
Ville Skyttä
2016-07-07 18:53:34 +03:00
parent 593708a39c
commit e8a8be5788
6 changed files with 17 additions and 33 deletions
+2 -8
View File
@@ -138,11 +138,8 @@ else:
domain + '.js'))
for js_file, (locale, po_file) in zip(js_files, po_files):
infile = open(po_file, 'r')
try:
with open(po_file, 'r') as infile:
catalog = read_po(infile, locale)
finally:
infile.close()
if catalog.fuzzy and not self.use_fuzzy:
continue
@@ -159,8 +156,7 @@ else:
msgid = msgid[0]
jscatalog[msgid] = message.string
outfile = open(js_file, 'wb')
try:
with open(js_file, 'wb') as outfile:
outfile.write('Documentation.addTranslations(')
dump(dict(
messages=jscatalog,
@@ -168,8 +164,6 @@ else:
locale=str(catalog.locale)
), outfile, sort_keys=True)
outfile.write(');')
finally:
outfile.close()
cmdclass['compile_catalog'] = compile_catalog_plusjs