This commit is contained in:
Kovid Goyal 2013-02-12 10:35:35 +05:30
parent c91c1aeba2
commit d9b75ef819
2 changed files with 7 additions and 2 deletions

View File

@ -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):

View File

@ -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')