def __init__(self, parent, db, callback, rows, path, opts, spare_server=None): QObject.__init__(self, parent) self.pd = ProgressDialog(_("Saving..."), parent=parent) self.spare_server = spare_server self.db = db self.opts = opts self.pd.setModal(True) self.pd.show() self.pd.set_min(0) self.pd.set_msg(_("Collecting data, please wait...")) self._parent = parent self.callback = callback self.callback_called = False self.rq = Queue() self.ids = [x for x in map(db.id, [r.row() for r in rows]) if x is not None] self.pd_max = len(self.ids) self.pd.set_max(0) self.pd.value = 0 self.failures = set([]) from calibre.ebooks.metadata.worker import SaveWorker self.worker = SaveWorker(self.rq, db, self.ids, path, self.opts, spare_server=self.spare_server) self.pd.canceled_signal.connect(self.canceled) self.continue_updating = True single_shot(self.update)
def __init__(self, parent, db, callback, rows, path, opts, spare_server=None): QObject.__init__(self, parent) self.pd = ProgressDialog(_('Saving...'), parent=parent) self.spare_server = spare_server self.db = db self.opts = opts self.pd.setModal(True) self.pd.show() self.pd.set_min(0) self.pd.set_msg(_('Collecting data, please wait...')) self._parent = parent self.callback = callback self.callback_called = False self.rq = Queue() self.ids = [ x for x in map(db.id, [r.row() for r in rows]) if x is not None ] self.pd_max = len(self.ids) self.pd.set_max(0) self.pd.value = 0 self.failures = set([]) from calibre.ebooks.metadata.worker import SaveWorker self.worker = SaveWorker(self.rq, db, self.ids, path, self.opts, spare_server=self.spare_server) self.pd.canceled_signal.connect(self.canceled) self.continue_updating = True single_shot(self.update)
class Saver(QObject): # {{{ def __init__(self, parent, db, callback, rows, path, opts, spare_server=None): QObject.__init__(self, parent) self.pd = ProgressDialog(_("Saving..."), parent=parent) self.spare_server = spare_server self.db = db self.opts = opts self.pd.setModal(True) self.pd.show() self.pd.set_min(0) self.pd.set_msg(_("Collecting data, please wait...")) self._parent = parent self.callback = callback self.callback_called = False self.rq = Queue() self.ids = [x for x in map(db.id, [r.row() for r in rows]) if x is not None] self.pd_max = len(self.ids) self.pd.set_max(0) self.pd.value = 0 self.failures = set([]) from calibre.ebooks.metadata.worker import SaveWorker self.worker = SaveWorker(self.rq, db, self.ids, path, self.opts, spare_server=self.spare_server) self.pd.canceled_signal.connect(self.canceled) self.continue_updating = True single_shot(self.update) def canceled(self): self.continue_updating = False if self.worker is not None: self.worker.canceled = True self.pd.hide() if not self.callback_called: self.callback(self.worker.path, self.failures, self.worker.error) self.callback_called = True def update(self): if not self.continue_updating: return if not self.worker.is_alive(): # Check that all ids were processed while self.ids: # Get all queued results since worker is dead before = len(self.ids) self.get_result() if before == len(self.ids): # No results available => worker died unexpectedly for i in list(self.ids): self.failures.add(("id:%d" % i, "Unknown error")) self.ids.remove(i) if not self.ids: self.continue_updating = False self.pd.hide() if not self.callback_called: try: # Give the worker time to clean up and set worker.error self.worker.join(2) except: pass # The worker was not yet started self.callback_called = True self.callback(self.worker.path, self.failures, self.worker.error) if self.continue_updating: self.get_result() single_shot(self.update) def get_result(self): try: id, title, ok, tb = self.rq.get_nowait() except Empty: return if self.pd.max != self.pd_max: self.pd.max = self.pd_max self.pd.value += 1 self.ids.remove(id) if not isinstance(title, unicode): title = str(title).decode(preferred_encoding, "replace") self.pd.set_msg(_("Saved") + " " + title) if not ok: self.failures.add((title, tb))
class Saver(QObject): # {{{ def __init__(self, parent, db, callback, rows, path, opts, spare_server=None): QObject.__init__(self, parent) self.pd = ProgressDialog(_('Saving...'), parent=parent) self.spare_server = spare_server self.db = db self.opts = opts self.pd.setModal(True) self.pd.show() self.pd.set_min(0) self.pd.set_msg(_('Collecting data, please wait...')) self._parent = parent self.callback = callback self.callback_called = False self.rq = Queue() self.ids = [ x for x in map(db.id, [r.row() for r in rows]) if x is not None ] self.pd_max = len(self.ids) self.pd.set_max(0) self.pd.value = 0 self.failures = set([]) from calibre.ebooks.metadata.worker import SaveWorker self.worker = SaveWorker(self.rq, db, self.ids, path, self.opts, spare_server=self.spare_server) self.pd.canceled_signal.connect(self.canceled) self.continue_updating = True single_shot(self.update) def canceled(self): self.continue_updating = False if self.worker is not None: self.worker.canceled = True self.pd.hide() if not self.callback_called: self.callback(self.worker.path, self.failures, self.worker.error) self.callback_called = True def update(self): if not self.continue_updating: return if not self.worker.is_alive(): # Check that all ids were processed while self.ids: # Get all queued results since worker is dead before = len(self.ids) self.get_result() if before == len(self.ids): # No results available => worker died unexpectedly for i in list(self.ids): self.failures.add(('id:%d' % i, 'Unknown error')) self.ids.remove(i) if not self.ids: self.continue_updating = False self.pd.hide() if not self.callback_called: try: # Give the worker time to clean up and set worker.error self.worker.join(2) except: pass # The worker was not yet started self.callback_called = True self.callback(self.worker.path, self.failures, self.worker.error) if self.continue_updating: self.get_result() single_shot(self.update) def get_result(self): try: id, title, ok, tb = self.rq.get_nowait() except Empty: return if self.pd.max != self.pd_max: self.pd.max = self.pd_max self.pd.value += 1 self.ids.remove(id) if not isinstance(title, unicode): title = str(title).decode(preferred_encoding, 'replace') self.pd.set_msg(_('Saved') + ' ' + title) if not ok: self.failures.add((title, tb))