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,36 +1458,34 @@ 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 = None
db_id, existing = None, False if matches:
if matches: db_id = list(matches)[0]
db_id = list(matches)[0] if db_id is None:
if db_id is None: obj = self.conn.execute('INSERT INTO books(title, author_sort) VALUES (?, ?)',
obj = self.conn.execute('INSERT INTO books(title, author_sort) VALUES (?, ?)', (title, 'calibre'))
(title, 'calibre')) db_id = obj.lastrowid
db_id = obj.lastrowid self.data.books_added([db_id], self)
self.data.books_added([db_id], self) 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, format)
mi = get_metadata(stream, except:
os.path.splitext(path)[1][1:].lower()) import traceback
except: traceback.print_exc()
mi = MetaInformation(title, ['calibre']) mi = MetaInformation(title, ['calibre'])
stream.seek(0)
mi.title, mi.authors = title, ['calibre']
mi.tags = [_('Catalog')]
mi.pubdate = mi.timestamp = utcnow()
self.set_metadata(db_id, mi)
self.add_format(db_id, format, stream, index_is_id=True)
mi.title, mi.authors = title, ['calibre']
mi.tags = [_('Catalog')]
mi.pubdate = mi.timestamp = utcnow()
self.set_metadata(db_id, mi)
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