calibredb now does a backup of changed metadata

This commit is contained in:
Kovid Goyal 2010-09-24 09:00:46 -06:00
parent 60e7729906
commit 41ebe2bd14
3 changed files with 17 additions and 6 deletions

View File

@ -36,14 +36,14 @@ class MetadataBackup(Thread): # {{{
def run(self): def run(self):
while self.keep_running: while self.keep_running:
try: try:
id_ = self.db.dirtied_queue.get(True, 5) id_ = self.db.dirtied_queue.get()
except Empty: except Empty:
continue continue
except: except:
# Happens during interpreter shutdown # Happens during interpreter shutdown
break break
if self.dump_func([id_]) is None: if self.dump_func([id_]) is None:
# An exception occured in dump_func, retry once # An exception occurred in dump_func, retry once
prints('Failed to backup metadata for id:', id_, 'once') prints('Failed to backup metadata for id:', id_, 'once')
time.sleep(2) time.sleep(2)
if not self.dump_func([id_]): if not self.dump_func([id_]):
@ -84,9 +84,12 @@ class CoverCache(Thread): # {{{
def run(self): def run(self):
while self.keep_running: while self.keep_running:
try: try:
id_ = self.load_queue.get(True, 1) id_ = self.load_queue.get()
except Empty: except Empty:
continue continue
except:
#Happens during interpreter shutdown
break
try: try:
img = self._image_for_id(id_) img = self._image_for_id(id_)
except: except:

View File

@ -32,8 +32,9 @@ def send_message(msg=''):
t.conn.send('refreshdb:'+msg) t.conn.send('refreshdb:'+msg)
t.conn.close() t.conn.close()
def write_dirtied(db):
prints('Backing up metadata')
db.dump_metadata()
def get_parser(usage): def get_parser(usage):
parser = OptionParser(usage) parser = OptionParser(usage)
@ -259,6 +260,7 @@ def do_add(db, paths, one_book_per_directory, recurse, add_duplicates):
print >>sys.stderr, '\t', title+':' print >>sys.stderr, '\t', title+':'
print >>sys.stderr, '\t\t ', path print >>sys.stderr, '\t\t ', path
write_dirtied(db)
send_message() send_message()
finally: finally:
sys.stdout = orig sys.stdout = orig
@ -299,6 +301,7 @@ def do_add_empty(db, title, authors, isbn):
if isbn: if isbn:
mi.isbn = isbn mi.isbn = isbn
db.import_book(mi, []) db.import_book(mi, [])
write_dirtied()
send_message() send_message()
def command_add(args, dbpath): def command_add(args, dbpath):
@ -452,6 +455,7 @@ def do_set_metadata(db, id, stream):
db.set_metadata(id, mi) db.set_metadata(id, mi)
db.clean() db.clean()
do_show_metadata(db, id, False) do_show_metadata(db, id, False)
write_dirtied()
send_message() send_message()
def set_metadata_option_parser(): def set_metadata_option_parser():

View File

@ -557,7 +557,11 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
def metadata_for_field(self, key): def metadata_for_field(self, key):
return self.field_metadata[key] return self.field_metadata[key]
def dump_metadata(self, book_ids, remove_from_dirtied=True, commit=True): def dump_metadata(self, book_ids=None, remove_from_dirtied=True, commit=True):
'Write metadata for each record to an individual OPF file'
if book_ids is None:
book_ids = [x[0] for x in self.conn.get(
'SELECT book FROM metadata_dirtied', all=True)]
for book_id in book_ids: for book_id in book_ids:
if not self.data.has_id(book_id): if not self.data.has_id(book_id):
continue continue