mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Database restore now works with the new API
This commit is contained in:
parent
4b1a61d7ce
commit
176da67d82
@ -132,9 +132,8 @@ def get_db_loader():
|
|||||||
|
|
||||||
'''
|
'''
|
||||||
Various things that require other things before they can be migrated:
|
Various things that require other things before they can be migrated:
|
||||||
1. Port library/restore.py
|
1. Check that content server reloading on metadata,db change, metadata
|
||||||
2. Check that content server reloading on metadata,db change, metadata
|
|
||||||
backup, refresh gui on calibredb add and moving libraries all work (check
|
backup, refresh gui on calibredb add and moving libraries all work (check
|
||||||
them on windows as well for file locking issues)
|
them on windows as well for file locking issues)
|
||||||
3. Check for mem leaks when switching libraries
|
2. Check for mem leaks when switching libraries
|
||||||
'''
|
'''
|
||||||
|
@ -1525,6 +1525,10 @@ class DB(object):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def restore_book(self, book_id, path, formats):
|
||||||
|
self.conn.execute('UPDATE books SET path=? WHERE id=?', (path.replace(os.sep, '/'), book_id))
|
||||||
|
vals = [(book_id, fmt, size, name) for fmt, size, name in formats]
|
||||||
|
self.conn.executemany('INSERT INTO data (book,format,uncompressed_size,name) VALUES (?,?,?,?)', vals)
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
|
@ -423,6 +423,12 @@ class Cache(object):
|
|||||||
rmap = {icu_lower(v) if isinstance(v, unicode) else v:k for k, v in self.fields[field].table.id_map.iteritems()}
|
rmap = {icu_lower(v) if isinstance(v, unicode) else v:k for k, v in self.fields[field].table.id_map.iteritems()}
|
||||||
return rmap.get(icu_lower(item_name) if isinstance(item_name, unicode) else item_name, None)
|
return rmap.get(icu_lower(item_name) if isinstance(item_name, unicode) else item_name, None)
|
||||||
|
|
||||||
|
@read_api
|
||||||
|
def get_item_ids(self, field, item_names):
|
||||||
|
' Return the item id for item_name (case-insensitive) '
|
||||||
|
rmap = {icu_lower(v) if isinstance(v, unicode) else v:k for k, v in self.fields[field].table.id_map.iteritems()}
|
||||||
|
return {name:rmap.get(icu_lower(name) if isinstance(name, unicode) else name, None) for name in item_names}
|
||||||
|
|
||||||
@read_api
|
@read_api
|
||||||
def author_data(self, author_ids=None):
|
def author_data(self, author_ids=None):
|
||||||
'''
|
'''
|
||||||
@ -1568,6 +1574,21 @@ class Cache(object):
|
|||||||
def dump_and_restore(self, callback=None, sql=None):
|
def dump_and_restore(self, callback=None, sql=None):
|
||||||
return self.backend.dump_and_restore(callback=callback, sql=sql)
|
return self.backend.dump_and_restore(callback=callback, sql=sql)
|
||||||
|
|
||||||
|
@write_api
|
||||||
|
def close(self):
|
||||||
|
self.backend.close()
|
||||||
|
|
||||||
|
@write_api
|
||||||
|
def restore_book(self, book_id, mi, last_modified, path, formats):
|
||||||
|
''' Restore the book entry in the database for a book that already exists on the filesystem '''
|
||||||
|
cover = mi.cover
|
||||||
|
mi.cover = None
|
||||||
|
self._create_book_entry(mi, add_duplicates=True,
|
||||||
|
force_id=book_id, apply_import_tags=False, preserve_uuid=True)
|
||||||
|
self._update_last_modified((book_id,), last_modified)
|
||||||
|
if cover and os.path.exists(cover):
|
||||||
|
self._set_field('cover', {book_id:1})
|
||||||
|
self.backend.restore_book(book_id, path, formats)
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
class SortKey(object): # {{{
|
class SortKey(object): # {{{
|
||||||
|
@ -78,7 +78,7 @@ class LibraryDatabase(object):
|
|||||||
set_saved_searches(self, 'saved_searches')
|
set_saved_searches(self, 'saved_searches')
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.backend.close()
|
self.new_api.close()
|
||||||
|
|
||||||
def break_cycles(self):
|
def break_cycles(self):
|
||||||
delattr(self.backend, 'field_metadata')
|
delattr(self.backend, 'field_metadata')
|
||||||
|
@ -8,11 +8,11 @@ __docformat__ = 'restructuredtext en'
|
|||||||
from PyQt4.Qt import (QDialog, QLabel, QVBoxLayout, QDialogButtonBox,
|
from PyQt4.Qt import (QDialog, QLabel, QVBoxLayout, QDialogButtonBox,
|
||||||
QProgressBar, QSize, QTimer, pyqtSignal, Qt)
|
QProgressBar, QSize, QTimer, pyqtSignal, Qt)
|
||||||
|
|
||||||
from calibre.library.restore import Restore
|
|
||||||
from calibre.gui2 import (error_dialog, question_dialog, warning_dialog,
|
from calibre.gui2 import (error_dialog, question_dialog, warning_dialog,
|
||||||
info_dialog)
|
info_dialog)
|
||||||
from calibre import force_unicode
|
from calibre import force_unicode
|
||||||
from calibre.constants import filesystem_encoding
|
from calibre.constants import filesystem_encoding
|
||||||
|
from calibre.utils.config_base import tweaks
|
||||||
|
|
||||||
class DBRestore(QDialog):
|
class DBRestore(QDialog):
|
||||||
|
|
||||||
@ -42,13 +42,16 @@ class DBRestore(QDialog):
|
|||||||
self.library_path = library_path
|
self.library_path = library_path
|
||||||
self.update_signal.connect(self.do_update, type=Qt.QueuedConnection)
|
self.update_signal.connect(self.do_update, type=Qt.QueuedConnection)
|
||||||
|
|
||||||
|
if tweaks.get('use_new_db', False):
|
||||||
|
from calibre.db.restore import Restore
|
||||||
|
else:
|
||||||
|
from calibre.library.restore import Restore
|
||||||
self.restorer = Restore(library_path, self)
|
self.restorer = Restore(library_path, self)
|
||||||
self.restorer.daemon = True
|
self.restorer.daemon = True
|
||||||
|
|
||||||
# Give the metadata backup thread time to stop
|
# Give the metadata backup thread time to stop
|
||||||
QTimer.singleShot(2000, self.start)
|
QTimer.singleShot(2000, self.start)
|
||||||
|
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.restorer.start()
|
self.restorer.start()
|
||||||
QTimer.singleShot(10, self.update)
|
QTimer.singleShot(10, self.update)
|
||||||
@ -133,3 +136,4 @@ def repair_library_at(library_path, parent=None):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1214,7 +1214,6 @@ what is found in the OPF files.
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def command_restore_database(args, dbpath):
|
def command_restore_database(args, dbpath):
|
||||||
from calibre.library.restore import Restore
|
|
||||||
parser = restore_database_option_parser()
|
parser = restore_database_option_parser()
|
||||||
opts, args = parser.parse_args(args)
|
opts, args = parser.parse_args(args)
|
||||||
if len(args) != 0:
|
if len(args) != 0:
|
||||||
@ -1242,6 +1241,10 @@ def command_restore_database(args, dbpath):
|
|||||||
self.total = float(step)
|
self.total = float(step)
|
||||||
else:
|
else:
|
||||||
prints(msg, '...', '%d%%'%int(100*(step/self.total)))
|
prints(msg, '...', '%d%%'%int(100*(step/self.total)))
|
||||||
|
if tweaks.get('use_new_db', False):
|
||||||
|
from calibre.db.restore import Restore
|
||||||
|
else:
|
||||||
|
from calibre.library.restore import Restore
|
||||||
r = Restore(dbpath, progress_callback=Progress())
|
r = Restore(dbpath, progress_callback=Progress())
|
||||||
r.start()
|
r.start()
|
||||||
r.join()
|
r.join()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user