mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
Fix #1236 (calibredb add error) and a nasty regression from 0.4.102 that caused book folders to not be renamed when metadata is edited
This commit is contained in:
parent
be3931f78f
commit
09a4a48bbd
@ -99,7 +99,7 @@ def get_db(dbpath, options):
|
|||||||
if options.library_path is not None:
|
if options.library_path is not None:
|
||||||
dbpath = options.library_path
|
dbpath = options.library_path
|
||||||
dbpath = os.path.abspath(dbpath)
|
dbpath = os.path.abspath(dbpath)
|
||||||
return LibraryDatabase2(dbpath, row_factory=True)
|
return LibraryDatabase2(dbpath)
|
||||||
|
|
||||||
def do_list(db, fields, sort_by, ascending, search_text, line_width, separator,
|
def do_list(db, fields, sort_by, ascending, search_text, line_width, separator,
|
||||||
prefix, output_format, subtitle='Books in the calibre database'):
|
prefix, output_format, subtitle='Books in the calibre database'):
|
||||||
@ -241,7 +241,7 @@ def do_add(db, paths, one_book_per_directory, recurse, add_duplicates):
|
|||||||
if not mi.title:
|
if not mi.title:
|
||||||
mi.title = os.path.splitext(os.path.basename(book))[0]
|
mi.title = os.path.splitext(os.path.basename(book))[0]
|
||||||
if not mi.authors:
|
if not mi.authors:
|
||||||
mi.authors = ['Unknown']
|
mi.authors = [_('Unknown')]
|
||||||
|
|
||||||
formats.append(format)
|
formats.append(format)
|
||||||
metadata.append(mi)
|
metadata.append(mi)
|
||||||
|
@ -829,9 +829,9 @@ class LibraryDatabase2(LibraryDatabase):
|
|||||||
except IntegrityError: # Sometimes books specify the same author twice in their metadata
|
except IntegrityError: # Sometimes books specify the same author twice in their metadata
|
||||||
pass
|
pass
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
self.set_path(id, True)
|
|
||||||
self.data.set(id, FIELD_MAP['authors'], ','.join([a.replace(',', '|') for a in authors]), row_is_id=True)
|
self.data.set(id, FIELD_MAP['authors'], ','.join([a.replace(',', '|') for a in authors]), row_is_id=True)
|
||||||
self.data.set(id, FIELD_MAP['author_sort'], self.data[self.data.row(id)][FIELD_MAP['authors']], row_is_id=True)
|
self.data.set(id, FIELD_MAP['author_sort'], self.data[self.data.row(id)][FIELD_MAP['authors']], row_is_id=True)
|
||||||
|
self.set_path(id, True)
|
||||||
if notify:
|
if notify:
|
||||||
self.notify('metadata', [id])
|
self.notify('metadata', [id])
|
||||||
|
|
||||||
@ -841,9 +841,9 @@ class LibraryDatabase2(LibraryDatabase):
|
|||||||
if not isinstance(title, unicode):
|
if not isinstance(title, unicode):
|
||||||
title = title.decode(preferred_encoding, 'replace')
|
title = title.decode(preferred_encoding, 'replace')
|
||||||
self.conn.execute('UPDATE books SET title=? WHERE id=?', (title, id))
|
self.conn.execute('UPDATE books SET title=? WHERE id=?', (title, id))
|
||||||
self.set_path(id, True)
|
|
||||||
self.data.set(id, FIELD_MAP['title'], title, row_is_id=True)
|
self.data.set(id, FIELD_MAP['title'], title, row_is_id=True)
|
||||||
self.data.set(id, FIELD_MAP['sort'], title_sort(title), row_is_id=True)
|
self.data.set(id, FIELD_MAP['sort'], title_sort(title), row_is_id=True)
|
||||||
|
self.set_path(id, True)
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
if notify:
|
if notify:
|
||||||
self.notify('metadata', [id])
|
self.notify('metadata', [id])
|
||||||
@ -1111,20 +1111,20 @@ class LibraryDatabase2(LibraryDatabase):
|
|||||||
if record is None: continue
|
if record is None: continue
|
||||||
x = {}
|
x = {}
|
||||||
for field in FIELDS:
|
for field in FIELDS:
|
||||||
x[field] = record[field]
|
x[field] = record[FIELD_MAP[field]]
|
||||||
data.append(x)
|
data.append(x)
|
||||||
x['id'] = record[0]
|
x['id'] = record[FIELD_MAP['id']]
|
||||||
x['formats'] = []
|
x['formats'] = []
|
||||||
x['authors'] = [i.replace('|', ',') for i in x['authors'].split(',')]
|
x['authors'] = [i.replace('|', ',') for i in x['authors'].split(',')]
|
||||||
if authors_as_string:
|
if authors_as_string:
|
||||||
x['authors'] = authors_to_string(x['authors'])
|
x['authors'] = authors_to_string(x['authors'])
|
||||||
x['tags'] = [i.replace('|', ',').strip() for i in x['tags'].split(',')] if x['tags'] else []
|
x['tags'] = [i.replace('|', ',').strip() for i in x['tags'].split(',')] if x['tags'] else []
|
||||||
path = os.path.join(prefix, self.path(record['id'], index_is_id=True))
|
path = os.path.join(prefix, self.path(record[FIELD_MAP['id']], index_is_id=True))
|
||||||
x['cover'] = os.path.join(path, 'cover.jpg')
|
x['cover'] = os.path.join(path, 'cover.jpg')
|
||||||
if not self.has_cover(x['id'], index_is_id=True):
|
if not self.has_cover(x['id'], index_is_id=True):
|
||||||
x['cover'] = None
|
x['cover'] = None
|
||||||
path += os.sep + self.construct_file_name(record['id']) + '.%s'
|
path += os.sep + self.construct_file_name(record[FIELD_MAP['id']]) + '.%s'
|
||||||
formats = self.formats(record['id'], index_is_id=True)
|
formats = self.formats(record[FIELD_MAP['id']], index_is_id=True)
|
||||||
if formats:
|
if formats:
|
||||||
for fmt in formats.split(','):
|
for fmt in formats.split(','):
|
||||||
x['formats'].append(path%fmt.lower())
|
x['formats'].append(path%fmt.lower())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user