Fix regression that broke catalog generation in the GUI

This commit is contained in:
Kovid Goyal 2010-02-19 19:08:41 -07:00
parent 63c4f94f95
commit 839c03372f

View File

@ -1458,13 +1458,12 @@ class LibraryDatabase2(LibraryDatabase):
def add_catalog(self, path, title): def add_catalog(self, path, title):
format = os.path.splitext(path)[1][1:].lower() format = os.path.splitext(path)[1][1:].lower()
stream = path if hasattr(path, 'read') else open(path, 'rb') with open(path, 'rb') as stream:
stream.seek(0) matches = self.data.get_matches('title', '='+title)
matches = self.data.get_matches('title', title)
if matches: if matches:
tag_matches = self.data.get_matches('tags', _('Catalog')) tag_matches = self.data.get_matches('tags', '='+_('Catalog'))
matches = matches.intersection(tag_matches) matches = matches.intersection(tag_matches)
db_id, existing = None, False db_id = None
if matches: if matches:
db_id = list(matches)[0] db_id = list(matches)[0]
if db_id is None: if db_id is None:
@ -1475,19 +1474,18 @@ class LibraryDatabase2(LibraryDatabase):
self.set_path(db_id, index_is_id=True) self.set_path(db_id, index_is_id=True)
self.conn.commit() self.conn.commit()
try: try:
mi = get_metadata(stream, mi = get_metadata(stream, format)
os.path.splitext(path)[1][1:].lower())
except: except:
import traceback
traceback.print_exc()
mi = MetaInformation(title, ['calibre']) mi = MetaInformation(title, ['calibre'])
stream.seek(0)
mi.title, mi.authors = title, ['calibre'] mi.title, mi.authors = title, ['calibre']
mi.tags = [_('Catalog')] mi.tags = [_('Catalog')]
mi.pubdate = mi.timestamp = utcnow() mi.pubdate = mi.timestamp = utcnow()
self.set_metadata(db_id, mi) self.set_metadata(db_id, mi)
self.add_format(db_id, format, stream, index_is_id=True) self.add_format(db_id, format, stream, index_is_id=True)
if not hasattr(path, 'read'):
stream.close()
self.conn.commit() self.conn.commit()
self.data.refresh_ids(self, [db_id]) # Needed to update format list and size self.data.refresh_ids(self, [db_id]) # Needed to update format list and size
return db_id return db_id