def refresh(self, active_on, callback, data=None): """ Run pool stash refresh asynchronously. """ ga_GObject.idle_add(self._watch_thread) threading.Thread(target=self._run_refresh, args=(active_on, callback, data)).start()
def refresh(self, active_on, callback, data=None): """ Run pool stash refresh asynchronously. """ ga_GObject.idle_add(self._watch_thread) threading.Thread(target=self._run_refresh, name="AsyncPoolRefreshThread", args=(active_on, callback, data)).start()
def watchdog(self): """ This is so we can guarantee exit after the D-Bus stuff is done, since certain parts of that are async :return: None """ if not self.keep_alive: ga_GObject.idle_add(check_if_ran_once, self, self.loop)
def worker(self, widget_update, backend_method, args=None, kwargs=None, exception_msg=None, callback=None): args = args or [] kwargs = kwargs or {} try: result = backend_method(*args, **kwargs) if callback: ga_GObject.idle_add(callback, result) except Exception, e: message = exception_msg or str(e) ga_GObject.idle_add(handle_gui_exception, e, message, self.parent_window)
def _run_unbind(self, serial, selection, callback, except_callback): """ Selection is only passed to maintain the gui error message. This can be removed, because it doesn't really give us any more information """ try: self.cp_provider.get_consumer_auth_cp().unbindBySerial(self.identity.uuid, serial) try: self.certlib.update() except Disconnected, e: pass if callback: ga_GObject.idle_add(callback)
def _run_unbind(self, serial, selection, callback, except_callback): """ Selection is only passed to maintain the gui error message. This can be removed, because it doesn't really give us any more information """ try: self.cp_provider.get_consumer_auth_cp().unbindBySerial( self.identity.uuid, serial) try: self.certlib.update() except Disconnected, e: pass if callback: ga_GObject.idle_add(callback)
def _run_unbind(self, serial, selection, callback, except_callback): """ Selection is only passed to maintain the gui error message. This can be removed, because it doesn't really give us any more information """ try: ent_service = entitlement.EntitlementService(self.cp_provider.get_consumer_auth_cp()) ent_service.remove_entitlements_by_serials([serial]) try: self.certlib.update() except Disconnected: pass if callback: ga_GObject.idle_add(callback) except Exception: ga_GObject.idle_add(except_callback, sys.exc_info(), selection)
def test_registration_error_returns_to_page(self): self.rs.initialize() self.correct_page = None self.rs.register_notebook.connect('notify::page', self.page_notify_handler) self.rs.connect('register-error', self.error_handler) ga_GObject.timeout_add(3000, self.gtk_quit_on_fail) ga_GObject.idle_add(self.emit_proceed) ga_GObject.idle_add(self.emit_error) # run till quit or timeout # if we get to the state we want we can call quit ga_Gtk.main() # If we saw any exceptions, raise them now so we fail nosetests for exc_info in self.exc_infos: raise exc_info[1], None, exc_info[2] self.assertTrue(self.correct_page)
def test_registration_error_returns_to_page(self): self.rs.initialize() self.correct_page = None self.rs.register_notebook.connect('notify::page', self.page_notify_handler) self.rs.connect('register-error', self.error_handler) ga_GObject.timeout_add(3000, self.gtk_quit_on_fail) ga_GObject.idle_add(self.emit_proceed) ga_GObject.idle_add(self.emit_error) # run till quit or timeout # if we get to the state we want we can call quit ga_Gtk.main() # If we saw any exceptions, raise them now so we fail nosetests for exc_info in self.exc_infos: six.reraise(*exc_info) self.assertTrue(self.correct_page)
def _create_async_pool(self): provide(inj.CP_PROVIDER, stubs.StubCPProvider()) inj.provide(inj.PROD_DIR, stubs.StubProductDirectory()) inj.provide(inj.ENT_DIR, stubs.StubEntitlementDirectory()) inj.provide(inj.CERT_SORTER, stubs.StubCertSorter()) self.pool_stash = \ managerlib.PoolStash() self.ap = async_utils.AsyncPool(self.pool_stash) # add a timeout and a idle handler self.idle = ga_GObject.idle_add(self.ap.refresh, datetime.date.today(), self.idle_callback) self.timer = ga_GObject.timeout_add(50, self.idle_callback) self.mainloop = ga_GObject.MainLoop()
def _create_async_pool(self): provide(inj.CP_PROVIDER, stubs.StubCPProvider()) inj.provide(inj.PROD_DIR, stubs.StubProductDirectory()) inj.provide(inj.ENT_DIR, stubs.StubEntitlementDirectory()) inj.provide(inj.CERT_SORTER, stubs.StubCertSorter()) self.pool_stash = \ managerlib.PoolStash(facts=self.stub_facts) self.ap = async.AsyncPool(self.pool_stash) # add a timeout and a idle handler self.idle = ga_GObject.idle_add(self.ap.refresh, datetime.date.today(), self.idle_callback) self.timer = ga_GObject.timeout_add(50, self.idle_callback) self.mainloop = ga_GObject.MainLoop()
def _run_bind(self, pool, quantity, bind_callback, cert_callback, except_callback): try: attach.AttachService(self.cp_provider.get_consumer_auth_cp()).attach_pool(pool['id'], quantity) if bind_callback: ga_GObject.idle_add(bind_callback) fetch_certificates(self.certlib) if cert_callback: ga_GObject.idle_add(cert_callback) except Exception: ga_GObject.idle_add(except_callback, sys.exc_info())
def _run_bind(self, pool, quantity, bind_callback, cert_callback, except_callback): try: self.plugin_manager.run("pre_subscribe", consumer_uuid=self.identity.uuid, pool_id=pool['id'], quantity=quantity) ents = self.cp_provider.get_consumer_auth_cp().bindByEntitlementPool(self.identity.uuid, pool['id'], quantity) self.plugin_manager.run("post_subscribe", consumer_uuid=self.identity.uuid, entitlement_data=ents) if bind_callback: ga_GObject.idle_add(bind_callback) fetch_certificates(self.certlib) if cert_callback: ga_GObject.idle_add(cert_callback) except Exception: ga_GObject.idle_add(except_callback, sys.exc_info())
def _run_bind(self, pool, quantity, bind_callback, cert_callback, except_callback): try: self.plugin_manager.run("pre_subscribe", consumer_uuid=self.identity.uuid, pool_id=pool['id'], quantity=quantity) ents = self.cp_provider.get_consumer_auth_cp().bindByEntitlementPool(self.identity.uuid, pool['id'], quantity) self.plugin_manager.run("post_subscribe", consumer_uuid=self.identity.uuid, entitlement_data=ents) if bind_callback: ga_GObject.idle_add(bind_callback) fetch_certificates(self.certlib) if cert_callback: ga_GObject.idle_add(cert_callback) except Exception, e: ga_GObject.idle_add(except_callback, e)
def watchdog(self): if not self.keep_alive: ga_GObject.idle_add(check_if_ran_once, self, self.loop)
def test_connection_wrapper(self, proxy_host, proxy_port, proxy_user, proxy_password): connection_status = self.test_connection(proxy_host, proxy_port, proxy_user, proxy_password) ga_GObject.idle_add(self.on_test_connection_finish, connection_status)
def _run_unbind(self, serial, selection, callback, except_callback): """ Selection is only passed to maintain the gui error message. This can be removed, because it doesn't really give us any more information """ try: self.cp_provider.get_consumer_auth_cp().unbindBySerial(self.identity.uuid, serial) try: self.certlib.update() except Disconnected, e: pass if callback: ga_GObject.idle_add(callback) except Exception, e: ga_GObject.idle_add(except_callback, e, selection) def bind(self, pool, quantity, except_callback, bind_callback=None, cert_callback=None): threading.Thread(target=self._run_bind, args=(pool, quantity, bind_callback, cert_callback, except_callback)).start() def unbind(self, serial, selection, callback, except_callback): threading.Thread(target=self._run_unbind, args=(serial, selection, callback, except_callback)).start() class AsyncRepoOverridesUpdate(object): def __init__(self, overrides_api): self.overrides_api = overrides_api self.identity = require(IDENTITY)
def _process_callback(self, callback, *args): ga_GObject.idle_add(callback, *args)
def set_sensitive(self, is_sensitive): for widget in self.widgets_to_disable: widget.set_sensitive(is_sensitive) def finished(self): self.set_sensitive(True) class AsyncWidgetUpdater(object): def __init__(self, parent): self.parent_window = parent def worker(self, widget_update, backend_method, args=None, kwargs=None, exception_msg=None, callback=None): args = args or [] kwargs = kwargs or {} try: result = backend_method(*args, **kwargs) if callback: ga_GObject.idle_add(callback, result) except Exception, e: message = exception_msg or str(e) ga_GObject.idle_add(handle_gui_exception, e, message, self.parent_window) finally: ga_GObject.idle_add(widget_update.finished) def update(self, widget_update, backend_method, args=None, kwargs=None, exception_msg=None, callback=None): threading.Thread(target=self.worker, name="AsyncWidgetUpdaterThread", args=(widget_update, backend_method, args, kwargs, exception_msg, callback)).start()
class AsyncWidgetUpdater(object): def __init__(self, parent): self.parent_window = parent def worker(self, widget_update, backend_method, args=None, kwargs=None, exception_msg=None, callback=None): args = args or [] kwargs = kwargs or {} try: result = backend_method(*args, **kwargs) if callback: ga_GObject.idle_add(callback, result) except Exception, e: message = exception_msg or str(e) ga_GObject.idle_add(handle_gui_exception, e, message, self.parent_window) finally: ga_GObject.idle_add(widget_update.finished) def update(self, widget_update, backend_method, args=None, kwargs=None, exception_msg=None, callback=None): threading.Thread(target=self.worker, name="AsyncWidgetUpdaterThread", args=(widget_update, backend_method, args, kwargs, exception_msg, callback)).start() class GuiExceptionMapper(ExceptionMapper): def format_restlib_exception(self, restlib_exception, message_template): return ga_GObject.markup_escape_text(restlib_exception.msg)
""" Selection is only passed to maintain the gui error message. This can be removed, because it doesn't really give us any more information """ try: self.cp_provider.get_consumer_auth_cp().unbindBySerial( self.identity.uuid, serial) try: self.certlib.update() except Disconnected, e: pass if callback: ga_GObject.idle_add(callback) except Exception, e: ga_GObject.idle_add(except_callback, e, selection) def bind(self, pool, quantity, except_callback, bind_callback=None, cert_callback=None): threading.Thread(target=self._run_bind, name="AsyncBindBindThread", args=(pool, quantity, bind_callback, cert_callback, except_callback)).start() def unbind(self, serial, selection, callback, except_callback): threading.Thread(target=self._run_unbind, name="AsyncBindUnbindThread",