class DBRestore(QDialog): update_signal = pyqtSignal(object, object) def __init__(self, parent, library_path, wait_time=2): QDialog.__init__(self, parent) self.l = QVBoxLayout() self.setLayout(self.l) self.l1 = QLabel('<b>'+_('Restoring database from backups, do not' ' interrupt, this will happen in three stages')+'...') self.setWindowTitle(_('Restoring database')) self.l.addWidget(self.l1) self.pb = QProgressBar(self) self.l.addWidget(self.pb) self.pb.setMaximum(0) self.pb.setMinimum(0) self.msg = QLabel('') self.l.addWidget(self.msg) self.msg.setWordWrap(True) self.bb = QDialogButtonBox(QDialogButtonBox.Cancel) self.l.addWidget(self.bb) self.bb.rejected.connect(self.reject) self.resize(self.sizeHint() + QSize(100, 50)) self.error = None self.rejected = False self.library_path = library_path self.update_signal.connect(self.do_update, type=Qt.QueuedConnection) from calibre.db.restore import Restore self.restorer = Restore(library_path, self) self.restorer.daemon = True # Give the metadata backup thread time to stop QTimer.singleShot(wait_time * 1000, self.start) def start(self): self.restorer.start() QTimer.singleShot(10, self.update) def reject(self): self.rejected = True self.restorer.progress_callback = lambda x, y: x QDialog.reject(self) def update(self): if self.restorer.is_alive(): QTimer.singleShot(10, self.update) else: self.restorer.progress_callback = lambda x, y: x self.accept() def __call__(self, msg, step): self.update_signal.emit(msg, step) def do_update(self, msg, step): if msg is None: self.pb.setMaximum(step) else: self.msg.setText(msg) self.pb.setValue(step)
def main(opts, args, dbctx): if not opts.really_do_it: raise SystemExit( _('You must provide the %s option to do a' ' recovery') % '--really-do-it') r = Restore(dbctx.library_path, progress_callback=Progress()) r.start() r.join() if r.tb is not None: prints('Restoring database failed with error:') prints(r.tb) else: prints('Restoring database succeeded') prints('old database saved as', r.olddb) if r.errors_occurred: name = 'calibre_db_restore_report.txt' lopen('calibre_db_restore_report.txt', 'wb').write(r.report.encode('utf-8')) prints('Some errors occurred. A detailed report was ' 'saved to', name) return 0
def main(opts, args, dbctx): if not opts.really_do_it: raise SystemExit( _('You must provide the %s option to do a' ' recovery') % '--really-do-it' ) r = Restore(dbctx.library_path, progress_callback=Progress()) r.start() r.join() if r.tb is not None: prints('Restoring database failed with error:') prints(r.tb) else: prints('Restoring database succeeded') prints('old database saved as', r.olddb) if r.errors_occurred: name = 'calibre_db_restore_report.txt' lopen('calibre_db_restore_report.txt', 'wb').write(r.report.encode('utf-8')) prints('Some errors occurred. A detailed report was ' 'saved to', name) return 0