mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
2d406112a4
commit
04ccd041e9
@ -156,8 +156,7 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
self.cover_cache.stop()
|
self.cover_cache.stop()
|
||||||
self.cover_cache = CoverCache(db, FunctionDispatcher(self.db.cover))
|
self.cover_cache = CoverCache(db, FunctionDispatcher(self.db.cover))
|
||||||
self.cover_cache.start()
|
self.cover_cache.start()
|
||||||
self.metadata_backup = MetadataBackup(db,
|
self.metadata_backup = MetadataBackup(db)
|
||||||
self.db.dump_metadata)
|
|
||||||
self.metadata_backup.start()
|
self.metadata_backup.start()
|
||||||
def refresh_cover(event, ids):
|
def refresh_cover(event, ids):
|
||||||
if event == 'cover' and self.cover_cache is not None:
|
if event == 'cover' and self.cover_cache is not None:
|
||||||
|
@ -22,12 +22,17 @@ from calibre.ebooks.metadata import title_sort
|
|||||||
from calibre import fit_image, prints
|
from calibre import fit_image, prints
|
||||||
|
|
||||||
class MetadataBackup(Thread): # {{{
|
class MetadataBackup(Thread): # {{{
|
||||||
|
'''
|
||||||
|
Continuously backup changed metadata into OPF files
|
||||||
|
in the book directory. This class runs in its own
|
||||||
|
thread and makes sure that the actual file write happens in the
|
||||||
|
GUI thread to prevent Windows' file locking from causing problems.
|
||||||
|
'''
|
||||||
|
|
||||||
def __init__(self, db, dump_func):
|
def __init__(self, db):
|
||||||
Thread.__init__(self)
|
Thread.__init__(self)
|
||||||
self.daemon = True
|
self.daemon = True
|
||||||
self.db = db
|
self.db = db
|
||||||
self.dump_func = dump_func
|
|
||||||
self.keep_running = True
|
self.keep_running = True
|
||||||
from calibre.gui2 import FunctionDispatcher
|
from calibre.gui2 import FunctionDispatcher
|
||||||
self.do_write = FunctionDispatcher(self.write)
|
self.do_write = FunctionDispatcher(self.write)
|
||||||
@ -47,7 +52,7 @@ class MetadataBackup(Thread): # {{{
|
|||||||
|
|
||||||
dump = []
|
dump = []
|
||||||
try:
|
try:
|
||||||
self.dump_func([id_], dump_queue=dump)
|
self.db.dump_metadata([id_], dump_to=dump)
|
||||||
except:
|
except:
|
||||||
prints('Failed to get backup metadata for id:', id_, 'once')
|
prints('Failed to get backup metadata for id:', id_, 'once')
|
||||||
import traceback
|
import traceback
|
||||||
@ -55,7 +60,7 @@ class MetadataBackup(Thread): # {{{
|
|||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
dump = []
|
dump = []
|
||||||
try:
|
try:
|
||||||
self.dump_func([id_], dump_queue=dump)
|
self.db.dump_metadata([id_], dump_to=dump)
|
||||||
except:
|
except:
|
||||||
prints('Failed to get backup metadata for id:', id_, 'again, giving up')
|
prints('Failed to get backup metadata for id:', id_, 'again, giving up')
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
@ -567,7 +567,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
return self.field_metadata[key]
|
return self.field_metadata[key]
|
||||||
|
|
||||||
def dump_metadata(self, book_ids=None, remove_from_dirtied=True,
|
def dump_metadata(self, book_ids=None, remove_from_dirtied=True,
|
||||||
commit=True, dump_queue=None):
|
commit=True, dump_to=None):
|
||||||
'Write metadata for each record to an individual OPF file'
|
'Write metadata for each record to an individual OPF file'
|
||||||
if book_ids is None:
|
if book_ids is None:
|
||||||
book_ids = [x[0] for x in self.conn.get(
|
book_ids = [x[0] for x in self.conn.get(
|
||||||
@ -583,11 +583,11 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
raw = metadata_to_opf(mi)
|
raw = metadata_to_opf(mi)
|
||||||
path = os.path.join(self.abspath(book_id, index_is_id=True),
|
path = os.path.join(self.abspath(book_id, index_is_id=True),
|
||||||
'metadata.opf')
|
'metadata.opf')
|
||||||
if dump_queue is None:
|
if dump_to is None:
|
||||||
with open(path, 'wb') as f:
|
with open(path, 'wb') as f:
|
||||||
f.write(raw)
|
f.write(raw)
|
||||||
else:
|
else:
|
||||||
dump_queue.append((path, raw))
|
dump_to.append((path, raw))
|
||||||
if remove_from_dirtied:
|
if remove_from_dirtied:
|
||||||
self.conn.execute('DELETE FROM metadata_dirtied WHERE book=?',
|
self.conn.execute('DELETE FROM metadata_dirtied WHERE book=?',
|
||||||
(book_id,))
|
(book_id,))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user