From fdf4c4342fd276a0dcd482f915ffddecc2d5a565 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 12 Sep 2008 10:18:16 -0700 Subject: [PATCH] b13 --- src/calibre/constants.py | 2 +- src/calibre/library/database2.py | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/calibre/constants.py b/src/calibre/constants.py index f1a2d72ca0..ef307b3306 100644 --- a/src/calibre/constants.py +++ b/src/calibre/constants.py @@ -2,7 +2,7 @@ __license__ = 'GPL v3' __copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net' __docformat__ = 'restructuredtext en' __appname__ = 'calibre' -__version__ = '0.4.84b12' +__version__ = '0.4.84b13' __author__ = "Kovid Goyal " ''' Various run time constants. diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index fae2f73a5c..d0132529d9 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -514,12 +514,15 @@ class LibraryDatabase2(LibraryDatabase): p.save(path) def formats(self, index, index_is_id=False): - ''' Return available formats as a comma separated list ''' + ''' Return available formats as a comma separated list or None if htere are no available formats ''' id = index if index_is_id else self.id(index) path = os.path.join(self.library_path, self.path(id, index_is_id=True)) - formats = self.conn.execute('SELECT format FROM data WHERE book=?', (id,)).fetchall() - name = self.conn.execute('SELECT name FROM data WHERE book=?', (id,)).fetchone()[0] - formats = map(lambda x:x[0], formats) + try: + formats = self.conn.execute('SELECT format FROM data WHERE book=?', (id,)).fetchall() + name = self.conn.execute('SELECT name FROM data WHERE book=?', (id,)).fetchone()[0] + formats = map(lambda x:x[0], formats) + except: + return None ans = [] for format in formats: _format = ('.' + format.lower()) if format else '' @@ -573,7 +576,7 @@ class LibraryDatabase2(LibraryDatabase): if os.path.exists(path): shutil.rmtree(path) parent = os.path.dirname(path) - if not os.listdir(parent): + if len(os.listdir(parent)) == 0: shutil.rmtree(parent) self.conn.execute('DELETE FROM books WHERE id=?', (id,)) self.conn.commit()