IGN:Handle missing formats more robustly

This commit is contained in:
Kovid Goyal 2008-09-01 22:29:58 -07:00
parent a24e9c0c7c
commit 653bd0e3ed
3 changed files with 7 additions and 2 deletions

View File

@ -2,7 +2,7 @@ __license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
__docformat__ = 'restructuredtext en'
__appname__ = 'calibre'
__version__ = '0.4.84b4'
__version__ = '0.4.84b5'
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
'''
Various run time constants.

View File

@ -1418,6 +1418,8 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
fmts = ''
for fmt in fmts.split(','):
data = self.format(idx, fmt, index_is_id=index_is_id)
if not data:
continue
fname = name +'.'+fmt.lower()
fname = sanitize_file_name(fname)
f = open(os.path.join(base, fname), 'w+b')

View File

@ -281,6 +281,8 @@ class LibraryDatabase2(LibraryDatabase):
for format in formats:
# Get data as string (cant use file as source and target files may be the same)
f = self.format(id, format, index_is_id=True, as_file=False)
if not f:
continue
stream = cStringIO.StringIO(f)
self.add_format(id, format, stream, index_is_id=True, path=tpath)
self.conn.execute('UPDATE books SET path=? WHERE id=?', (path, id))
@ -344,6 +346,7 @@ class LibraryDatabase2(LibraryDatabase):
if os.access(path, os.R_OK|os.W_OK):
f = open(path, mode)
return f if as_file else f.read()
self.remove_format(id, format, index_is_id=True)
def add_format(self, index, format, stream, index_is_id=False, path=None):
id = index if index_is_id else self.id(index)
@ -384,7 +387,7 @@ class LibraryDatabase2(LibraryDatabase):
ext = ('.' + format.lower()) if format else ''
path = os.path.join(path, name+ext)
if os.access(path, os.W_OK):
os.unlink(path)
os.remove(path)
self.conn.execute('DELETE FROM data WHERE book=? AND format=?', (id, format.upper()))
self.conn.commit()