mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
where possible, open files using context managers
This commit is contained in:
parent
cb29d11996
commit
9320e2fe22
@ -2961,7 +2961,8 @@ class CatalogBuilder(object):
|
|||||||
left = max(int((MI_WIDTH - width) / 2.), 0)
|
left = max(int((MI_WIDTH - width) / 2.), 0)
|
||||||
top = max(int((MI_HEIGHT - height) / 2.), 0)
|
top = max(int((MI_HEIGHT - height) / 2.), 0)
|
||||||
draw.text((left, top), text, fill=(0, 0, 0), font=font)
|
draw.text((left, top), text, fill=(0, 0, 0), font=font)
|
||||||
img.save(open(out_path, 'wb'), 'GIF')
|
with open(out_path, 'wb') as f:
|
||||||
|
img.save(f, 'GIF')
|
||||||
|
|
||||||
def generate_ncx_header(self):
|
def generate_ncx_header(self):
|
||||||
""" Generate the basic NCX file.
|
""" Generate the basic NCX file.
|
||||||
|
@ -3517,10 +3517,9 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
self.set_metadata(id, mi, commit=True, ignore_errors=True)
|
self.set_metadata(id, mi, commit=True, ignore_errors=True)
|
||||||
npath = self.run_import_plugins(path, format)
|
npath = self.run_import_plugins(path, format)
|
||||||
format = os.path.splitext(npath)[-1].lower().replace('.', '').upper()
|
format = os.path.splitext(npath)[-1].lower().replace('.', '').upper()
|
||||||
stream = lopen(npath, 'rb')
|
with lopen(npath, 'rb') as stream:
|
||||||
format = check_ebook_format(stream, format)
|
format = check_ebook_format(stream, format)
|
||||||
self.add_format(id, format, stream, index_is_id=True)
|
self.add_format(id, format, stream, index_is_id=True)
|
||||||
stream.close()
|
|
||||||
postimport.append((id, format))
|
postimport.append((id, format))
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
self.data.refresh_ids(self, ids) # Needed to update format list and size
|
self.data.refresh_ids(self, ids) # Needed to update format list and size
|
||||||
|
Loading…
x
Reference in New Issue
Block a user