示例#1
0
 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 __init__(self, text, parent=None, title=None):
        ga_GObject.GObject.__init__(self)
        self.rc = None

        # this seems to be wordwrapping text passed to
        # it, which is making for ugly error messages
        self.dialog = ga_Gtk.MessageDialog(parent, 0, self.STYLE, self.BUTTONS)

        if title:
            self.dialog.set_title(title)

        # escape product strings see rh bz#633438
        self.dialog.set_markup(text)

        self.dialog.set_default_response(0)

        self.dialog.set_position(ga_Gtk.WindowPosition.CENTER_ON_PARENT)
        self.dialog.show_all()
        self.dialog.set_icon_name('subscription-manager')

        self.dialog.set_modal(True)
        #this seems spurious, but without it, a ref to this obj gets "lost"
        ga_GObject.add_emission_hook(self, 'response', self.noop_hook)

        self.dialog.connect("response", self._on_response_event)
    def _clear_progress_bar(self):
        if not self.progress_bar:  # progress bar could be none iff self.test_connection is called directly
            return

        self.progress_bar.hide()
        ga_GObject.source_remove(self.timer)
        self.timer = 0
        self.progress_bar = None
示例#4
0
 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)
示例#5
0
    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 _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()
示例#7
0
    def search_button_clicked(self, widget=None):
        """
        Reload the subscriptions from the server when the Search button
        is clicked.
        """
        if not self.date_picker.date_entry_validate():
            return
        try:
            pb_title = _("Searching")
            pb_label = _("Searching for subscriptions. Please wait.")
            if self.pb:
                self.pb.set_title(pb_title)
                self.pb.set_label(pb_label)
            else:
                # show pulsating progress bar while we wait for results
                self.pb = progress.Progress(pb_title, pb_label)
                self.timer = ga_GObject.timeout_add(100, self.pb.pulse)
                self.pb.set_transient_for(self.parent_win)

            # fire off async refresh
            async_stash = async_utils.AsyncPool(self.pool_stash)
            async_stash.refresh(self.date_picker.date, self._update_display)
        except Exception as e:
            handle_gui_exception(e, _("Error fetching subscriptions from server:  %s"),
                    self.parent_win)
 def _display_progress_bar(self):
     if self.progress_bar:
         self.progress_bar.set_title(_("Testing Connection"))
         self.progress_bar.set_label(_("Please wait"))
     else:
         self.progress_bar = progress.Progress(_("Testing Connection"), _("Please wait"))
         self.timer = ga_GObject.timeout_add(100, self.progress_bar.pulse)
         self.progress_bar.set_parent_window(self.networkConfigDialog)
示例#9
0
def apply_highlight(text, highlight):
    """
    Apply pango markup to highlight a search term in a string
    """
    if not highlight:
        return ga_GObject.markup_escape_text(text)

    regex = re.compile("(" + re.escape(highlight) + ")", re.I)
    parts = regex.split(text)

    escaped = []
    # re.split makes every second result be our split term
    on_search_term = False
    for part in parts:
        if on_search_term:
            escaped += "<b>%s</b>" % ga_GObject.markup_escape_text(part)
        else:
            escaped += ga_GObject.markup_escape_text(part)
        on_search_term = not on_search_term

    return "".join(escaped)
示例#10
0
    def unsubscribe_button_clicked(self, widget):
        selection = widgets.SelectionWrapper(self.top_view.get_selection(), self.store)

        # nothing selected
        if not selection.is_valid():
            return

        # remove all markup, see rh bz#982286
        subscription_text = ga_GObject.markup_escape_text(selection['subscription'])

        prompt = messageWindow.YesNoDialog(_("Are you sure you want to remove %s?") % subscription_text,
                self.content.get_toplevel())
        prompt.connect('response', self._on_unsubscribe_prompt_response, selection)
示例#11
0
    def _on_unsubscribe_prompt_response(self, dialog, response, selection):
        if not response:
            return

        serial = long(selection["serial"])

        if self.identity.is_valid():
            self.pb = progress.Progress(_("Removing"), _("Removing subscription. Please wait."))
            self.timer = ga_GObject.timeout_add(100, self.pb.pulse)
            self.pb.set_transient_for(self.parent_win)
            self.async_bind.unbind(serial, selection, self._unsubscribe_callback, self._handle_unbind_exception)
        else:
            # unregistered, just delete the certs directly
            action = EntCertDeleteAction(self.entitlement_dir)
            action.perform([serial])
            self.update_subscriptions()
示例#12
0
    def _on_unsubscribe_prompt_response(self, dialog, response, selection):
        if not response:
            return

        serial = long(selection['serial'])

        if self.identity.is_valid():
            self.pb = progress.Progress(_("Removing"),
                    _("Removing subscription. Please wait."))
            self.timer = ga_GObject.timeout_add(100, self.pb.pulse)
            content_toplevel = self.content.get_toplevel()
            if content_toplevel.is_toplevel():
                self.pb.set_parent_window(content_toplevel)
            self.async_bind.unbind(serial, selection, self._unsubscribe_callback, self._handle_unbind_exception)
        else:
            # unregistered, just delete the certs directly
            self.backend.entcertlib.delete([serial])
            self.backend.cs.force_cert_check()
示例#13
0
 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)
示例#14
0
    def _on_unsubscribe_prompt_response(self, dialog, response, selection):
        if not response:
            return

        serial = long(selection['serial'])

        if self.identity.is_valid():
            self.pb = progress.Progress(
                _("Removing"), _("Removing subscription. Please wait."))
            self.timer = ga_GObject.timeout_add(100, self.pb.pulse)
            self.pb.set_transient_for(self.parent_win)
            self.async_bind.unbind(serial, selection,
                                   self._unsubscribe_callback,
                                   self._handle_unbind_exception)
        else:
            # unregistered, just delete the certs directly
            action = EntCertDeleteAction(self.entitlement_dir)
            action.perform([serial])
        self.update_subscriptions()
示例#15
0
    def _contract_selected(self, pool, quantity=1):
        if not valid_quantity(quantity):
            show_error_window(_("Quantity must be a positive number."),
                              parent=self.parent_win)
            return

        self._contract_selection_cancelled()

        # Start the progress bar
        self.pb = progress.Progress(_("Attaching"),
                _("Attaching subscription. Please wait."))
        self.timer = ga_GObject.timeout_add(100, self.pb.pulse)
        self.pb.set_transient_for(self.parent_win)
        # Spin off a thread to handle binding the selected pool.
        # After it has completed the actual bind call, available
        # subs will be refreshed, but we won't re-run compliance
        # until we have serialized the certificates
        self.async_bind.bind(pool, quantity,
                bind_callback=self._async_bind_callback,
                cert_callback=self.backend.cs.force_cert_check,
                except_callback=self._async_bind_exception_callback)
示例#16
0
    def _contract_selected(self, pool, quantity=1):
        if not valid_quantity(quantity):
            show_error_window(_("Quantity must be a positive number."),
                              parent=self.parent_win)
            return

        self._contract_selection_cancelled()

        # Start the progress bar
        self.pb = progress.Progress(_("Attaching"),
                                    _("Attaching subscription. Please wait."))
        self.timer = ga_GObject.timeout_add(100, self.pb.pulse)
        self.pb.set_transient_for(self.parent_win)
        # Spin off a thread to handle binding the selected pool.
        # After it has completed the actual bind call, available
        # subs will be refreshed, but we won't re-run compliance
        # until we have serialized the certificates
        self.async_bind.bind(
            pool,
            quantity,
            bind_callback=self._async_bind_callback,
            cert_callback=self.backend.cs.force_cert_check,
            except_callback=self._async_bind_exception_callback)
示例#17
0
 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 as 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)
示例#18
0
 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 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)
示例#20
0
    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_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)
示例#22
0
 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)
示例#23
0
from subscription_manager import ga_loader

# initial-setup only works with gtk version 3
ga_loader.init_ga(gtk_version="3")

from subscription_manager.ga import GObject as ga_GObject
from subscription_manager.ga import Gtk as ga_Gtk
from subscription_manager.gui import managergui
from subscription_manager.i18n import configure_gettext
from subscription_manager.injectioninit import init_dep_injection
from subscription_manager.gui import registergui
from subscription_manager import utils
from subscription_manager.gui import utils as gui_utils

ga_GObject.threads_init()

__all__ = ["RHSMSpoke"]

configure_gettext()


class RHSMSpoke(FirstbootSpokeMixIn, NormalSpoke):
    """
    Spoke used for registration of system in Anaconda or Initial Setup
    """
    buildrObjects = ["RHSMSpokeWindow"]
    mainWidgetName = "RHSMSpokeWindow"
    uiFile = "rhsm_gui.ui"
    helpFile = "SubscriptionManagerSpoke.xml"
    # Display our spoke in second hub for testing purpose. There is also
示例#24
0

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)
示例#25
0
 def watchdog(self):
     if not self.keep_alive:
         ga_GObject.idle_add(check_if_ran_once, self, self.loop)
示例#26
0
 def _clear_progress_bar(self):
     if self.pb:
         self.pb.hide()
         ga_GObject.source_remove(self.timer)
         self.timer = 0
         self.pb = None
示例#27
0
 def _clear_progress_bar(self):
     if self.pb:
         self.pb.hide()
         ga_GObject.source_remove(self.timer)
         self.timer = 0
         self.pb = None
示例#28
0
 def _show_progress_bar(self, title, label, progress_parent=None):
     self.pb = progress.Progress(title, label, True)
     self.timer = ga_GObject.timeout_add(100, self.pb.pulse)
     self.pb.set_transient_for(progress_parent or self._get_dialog_widget())
示例#29
0
from subscription_manager import ga_loader

# initial-setup only works with gtk version 3
ga_loader.init_ga(gtk_version="3")

from subscription_manager.ga import GObject as ga_GObject
from subscription_manager.ga import Gtk as ga_Gtk
from subscription_manager.gui import managergui
from subscription_manager.i18n import configure_gettext
from subscription_manager.injectioninit import init_dep_injection
from subscription_manager.gui import registergui
from subscription_manager import utils
from subscription_manager.gui import utils as gui_utils

ga_GObject.threads_init()

__all__ = ["RHSMSpoke"]

configure_gettext()


class RHSMSpoke(NormalSpoke):
    """
    Spoke used for registration of system in Anaconda or Initial Setup
    """
    buildrObjects = ["RHSMSpokeWindow"]
    mainWidgetName = "RHSMSpokeWindow"
    uiFile = "rhsm_gui.ui"
    helpFile = "SubscriptionManagerSpoke.xml"
    # Display our spoke in second hub for testing purpose. There is also
示例#30
0
    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)
示例#31
0
 def format_restlib_exception(self, restlib_exception, message_template):
     return ga_GObject.markup_escape_text(restlib_exception.msg)
示例#32
0
 def _process_callback(self, callback, *args):
     ga_GObject.idle_add(callback, *args)
示例#33
0
        """
        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",
示例#34
0
 def _show_progress_bar(self, title, label, progress_parent=None):
     self.pb = progress.Progress(title, label, True)
     self.timer = ga_GObject.timeout_add(100, self.pb.pulse)
     self.pb.set_transient_for(progress_parent or self._get_dialog_widget())
示例#35
0
 def _process_callback(self, callback, *args):
     ga_GObject.idle_add(callback, *args)
示例#36
0
 def watchdog(self):
     if not self.keep_alive:
         ga_GObject.idle_add(check_if_ran_once, self, self.loop)
示例#37
0
 def format_restlib_exception(self, restlib_exception, message_template):
     return ga_GObject.markup_escape_text(restlib_exception.msg)
示例#38
0
def main():

    log.info("rhsmd started")
    parser = OptionParser(usage=USAGE,
                          formatter=WrappedIndentedHelpFormatter())
    parser.add_option("-d",
                      "--debug",
                      dest="debug",
                      help="Display debug messages",
                      action="store_true",
                      default=False)
    parser.add_option(
        "-k",
        "--keep-alive",
        dest="keep_alive",
        help="Stay running (don't shut down after the first dbus call)",
        action="store_true",
        default=False)
    parser.add_option("-s",
                      "--syslog",
                      dest="syslog",
                      help="Run standalone and log result to syslog",
                      action="store_true",
                      default=False)
    parser.add_option(
        "-f",
        "--force-signal",
        dest="force_signal",
        help="Force firing of a signal " +
        "(valid, expired, warning, partial, classic or registration_required)")
    parser.add_option(
        "-i",
        "--immediate",
        dest="immediate",
        action="store_true",
        default=False,
        help="Fire forced signal immediately (requires --force-signal)")

    options, args = parser.parse_args()

    force_signal = parse_force_signal(options.force_signal)

    if options.immediate and force_signal is None:
        print_error("--immediate must be used with --force-signal")
        sys.exit(-2)

    global enable_debug
    enable_debug = options.debug

    # short-circuit dbus initialization
    if options.syslog:
        log.info("logging subscription status to syslog")
        status = check_status(force_signal)
        if status == RHSM_EXPIRED:
            log_syslog(
                syslog.LOG_NOTICE,
                "This system is missing one or more subscriptions. " +
                "Please run subscription-manager for more information.")
        elif status == RHSM_PARTIALLY_VALID:
            log_syslog(
                syslog.LOG_NOTICE,
                "This system is missing one or more subscriptions " +
                "to fully cover its products. " +
                "Please run subscription-manager for more information.")
        elif status == RHSM_WARNING:
            log_syslog(
                syslog.LOG_NOTICE,
                "This system's subscriptions are about to expire. " +
                "Please run subscription-manager for more information.")
        elif status == RHN_CLASSIC:
            log_syslog(syslog.LOG_INFO,
                       get_branding().RHSMD_REGISTERED_TO_OTHER)
        elif status == RHSM_REGISTRATION_REQUIRED:
            log_syslog(
                syslog.LOG_NOTICE,
                "In order for Subscription Manager to provide your " +
                "system with updates, your system must be registered " +
                "with the Customer Portal. Please enter your Red Hat " +
                "login to ensure your system is up-to-date.")

        # Return an exit code for the program. having valid entitlements is
        # good, so it gets an exit status of 0.
        return status

    # we are not running from cron here, so unset the excepthook
    # though, we may be running from cli, or as a dbus activation. For
    # cli, we should traceback. For dbus, we should try to log it and
    # raise dbus exception?
    sys.excepthook = sys.__excepthook__

    system_bus = dbus.SystemBus()
    loop = ga_GObject.MainLoop()
    checker = StatusChecker(system_bus, options.keep_alive, force_signal, loop)

    if options.immediate:
        checker.entitlement_status_changed(force_signal)

    loop.run()
示例#39
0
    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()