From 314b212b59b4e3e16a613fb02088b24c2d1bf92f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 29 Sep 2010 13:03:47 -0600 Subject: [PATCH] Tweak epub: Warning to close open files. --- src/calibre/gui2/dialogs/tweak_epub.ui | 8 ++--- src/calibre/utils/zipfile.py | 43 +++++++++++++------------- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/calibre/gui2/dialogs/tweak_epub.ui b/src/calibre/gui2/dialogs/tweak_epub.ui index ccd33f44ab..063460aaae 100644 --- a/src/calibre/gui2/dialogs/tweak_epub.ui +++ b/src/calibre/gui2/dialogs/tweak_epub.ui @@ -32,7 +32,7 @@ &Explode ePub - + :/images/wizard.png:/images/wizard.png @@ -49,7 +49,7 @@ &Rebuild ePub - + :/images/exec.png:/images/exec.png @@ -63,7 +63,7 @@ &Cancel - + :/images/window-close.png:/images/window-close.png @@ -71,7 +71,7 @@ - Explode the ePub to display contents in a file browser window. To tweak individual files, right-click, then 'Open with...' your editor of choice. When tweaks are complete, close the file browser window. Rebuild the ePub, updating your calibre library. + <p>Explode the ePub to display contents in a file browser window. To tweak individual files, right-click, then 'Open with...' your editor of choice. When tweaks are complete, close the file browser window <b>and the editor windows you used to edit files in the epub</b>.</p><p>Rebuild the ePub, updating your calibre library.</p> true diff --git a/src/calibre/utils/zipfile.py b/src/calibre/utils/zipfile.py index 8f22b5f9e2..dbcc125274 100644 --- a/src/calibre/utils/zipfile.py +++ b/src/calibre/utils/zipfile.py @@ -1147,28 +1147,27 @@ class ZipFile: self._writecheck(zinfo) self._didModify = True - fp = open(filename, "rb") - # Must overwrite CRC and sizes with correct data later - zinfo.CRC = CRC = 0 - zinfo.compress_size = compress_size = 0 - zinfo.file_size = file_size = 0 - self.fp.write(zinfo.FileHeader()) - if zinfo.compress_type == ZIP_DEFLATED: - cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, - zlib.DEFLATED, -15) - else: - cmpr = None - while 1: - buf = fp.read(1024 * 8) - if not buf: - break - file_size = file_size + len(buf) - CRC = crc32(buf, CRC) & 0xffffffff - if cmpr: - buf = cmpr.compress(buf) - compress_size = compress_size + len(buf) - self.fp.write(buf) - fp.close() + with open(filename, "rb") as fp: + # Must overwrite CRC and sizes with correct data later + zinfo.CRC = CRC = 0 + zinfo.compress_size = compress_size = 0 + zinfo.file_size = file_size = 0 + self.fp.write(zinfo.FileHeader()) + if zinfo.compress_type == ZIP_DEFLATED: + cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, + zlib.DEFLATED, -15) + else: + cmpr = None + while 1: + buf = fp.read(1024 * 8) + if not buf: + break + file_size = file_size + len(buf) + CRC = crc32(buf, CRC) & 0xffffffff + if cmpr: + buf = cmpr.compress(buf) + compress_size = compress_size + len(buf) + self.fp.write(buf) if cmpr: buf = cmpr.flush() compress_size = compress_size + len(buf)