From d9b75ef819d7f9658f2dd4007462d3f918606279 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 12 Feb 2013 10:35:35 +0530 Subject: [PATCH] ... --- src/calibre/ebooks/oeb/polish/container.py | 6 +++++- src/calibre/ebooks/oeb/polish/cover.py | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/oeb/polish/container.py b/src/calibre/ebooks/oeb/polish/container.py index f2ada441fc..08fd53158f 100644 --- a/src/calibre/ebooks/oeb/polish/container.py +++ b/src/calibre/ebooks/oeb/polish/container.py @@ -373,7 +373,11 @@ class Container(object): def open(self, name, mode='rb'): if name in self.dirtied: self.commit_item(name) - return open(self.name_to_abspath(name), mode) + path = self.name_to_abspath(name) + base = os.path.dirname(path) + if not os.path.exists(base): + os.makedirs(base) + return open(path, mode) def commit(self, outpath=None): for name in tuple(self.dirtied): diff --git a/src/calibre/ebooks/oeb/polish/cover.py b/src/calibre/ebooks/oeb/polish/cover.py index 78a67d4df8..7dd4ba39fe 100644 --- a/src/calibre/ebooks/oeb/polish/cover.py +++ b/src/calibre/ebooks/oeb/polish/cover.py @@ -27,7 +27,8 @@ def set_azw3_cover(container, cover_path, report): guide = container.opf_xpath('//opf:guide')[0] container.insert_into_xml(guide, guide.makeelement( OPF('reference'), href=href, type='cover')) - shutil.copyfile(cover_path, container.name_to_abspath(name)) + with open(cover_path, 'rb') as src, container.open(name, 'wb') as dest: + shutil.copyfileobj(src, dest) container.dirty(container.opf_name) report('Cover updated' if found else 'Cover inserted')