def __init__(self, backend=None, facts=None, ent_dir=None, prod_dir=None, auto_launch_registration=False): super(MainWindow, self).__init__() self.backend = backend or Backend() self.identity = require(IDENTITY) self.facts = facts or Facts(self.backend.entitlement_dir, self.backend.product_dir) # We need to make sure facts are loaded immediately, some GUI operations # are done in separate threads, and if facts try to load in another # thread the virt guest detection code breaks due to hwprobe's use of # signals. self.facts.get_facts() log.debug("Client Versions: %s " % get_client_versions()) # Log the server version asynchronously ga_GLib.idle_add(self.log_server_version, self.backend.cp_provider.get_consumer_auth_cp()) settings = self.main_window.get_settings() # prevent gtk from trying to save a list of recently used files, which # as root, causes gtk warning: # "Attempting to set the permissions of `/root/.local/share/recently-used.xbel' # The __name__ use is just for the 'origin' value gtk uses to store # where a Gtk.Settings value was set. settings.set_long_property('gtk-recent-files-max-age', 0, "%s:%s" % (__name__, type(self).__name__)) self.product_dir = prod_dir or self.backend.product_dir self.entitlement_dir = ent_dir or self.backend.entitlement_dir self.system_facts_dialog = factsgui.SystemFactsDialog(self.facts) self.preferences_dialog = PreferencesDialog(self.backend, self._get_window()) self.repos_dialog = RepositoriesDialog(self.backend, self._get_window()) self.import_sub_dialog = ImportSubDialog() self.network_config_dialog = networkConfig.NetworkConfigDialog() self.network_config_dialog.saveButton.connect("clicked", self._config_changed) self.redeem_dialog = redeem.RedeemDialog(self.backend) self.installed_tab_icon = ga_Gtk.Image() self.installed_tab_icon.set_from_stock(ga_Gtk.STOCK_YES, ga_Gtk.IconSize.MENU) self.installed_tab = InstalledProductsTab(self.backend, self.facts, self.installed_tab_icon, self, ent_dir=self.entitlement_dir, prod_dir=self.product_dir) self.my_subs_tab = MySubscriptionsTab(self.backend, self.main_window, ent_dir=self.entitlement_dir, prod_dir=self.product_dir) self.all_subs_tab = AllSubscriptionsTab(self.backend, self.facts, self.main_window) hbox = ga_Gtk.HBox(spacing=6) hbox.pack_start(self.installed_tab_icon, False, False, 0) hbox.pack_start(ga_Gtk.Label(self.installed_tab.get_label()), False, False, 0) self.notebook.append_page(self.installed_tab.get_content(), hbox) hbox.show_all() self.notebook.append_page(self.my_subs_tab.get_content(), ga_Gtk.Label(self.my_subs_tab.get_label())) self.connect_signals({ "on_register_menu_item_activate": self._register_item_clicked, "on_unregister_menu_item_activate": self._unregister_item_clicked, "on_import_cert_menu_item_activate": self._import_cert_item_clicked, "on_view_facts_menu_item_activate": self._facts_item_clicked, "on_proxy_config_menu_item_activate": self._proxy_config_item_clicked, "on_redeem_menu_item_activate": self._redeem_item_clicked, "on_preferences_menu_item_activate": self._preferences_item_clicked, "on_repos_menu_item_activate": self._repos_item_clicked, "on_about_menu_item_activate": self._about_item_clicked, "on_getting_started_menu_item_activate": self._getting_started_item_clicked, "on_online_docs_menu_item_activate": self._online_docs_item_clicked, "on_quit_menu_item_activate": ga_Gtk.main_quit, }) # TODO: why is this defined in the init scope? # When something causes cert_sorter to upate it's state, refresh the gui # The cert directories being updated will cause this (either noticed # from a timer, or via cert_sort.force_cert_check). def on_cert_sorter_cert_change(): # Update installed products self.installed_tab.update_products() self.installed_tab._set_validity_status() # Update attached subs self.my_subs_tab.update_subscriptions() # Update main window self.refresh() # Reset repos dialog, see bz 1132919 self.repos_dialog = RepositoriesDialog(self.backend, self._get_window()) self.backend.cs.add_callback(on_cert_sorter_cert_change) self.main_window.show_all() # Check to see if already registered to old RHN/Spacewalk # and show dialog if so self._check_rhn_classic() # Update everything with compliance data self.backend.cs.notify() # managergui needs cert_sort.cert_monitor.run_check() to run # on a timer to detect cert changes from outside the gui # (via rhsmdd for example, or manually provisioned). ga_GLib.timeout_add(2000, self._on_cert_check_timer) if auto_launch_registration and not self.registered(): self._register_item_clicked(None)
class MainWindow(widgets.SubmanBaseWidget): """ The new RHSM main window. """ widget_names = ['main_window', 'notebook', 'system_name_label', 'register_menu_item', 'unregister_menu_item', 'redeem_menu_item', 'settings_menu_item', 'repos_menu_item', 'import_cert_menu_item'] gui_file = "mainwindow" def log_server_version(self, uep): server_versions = get_server_versions(uep) log.debug("Server Versions: %s" % server_versions) # Remove this from the GTK main loop return False def _on_proxy_error_dialog_response(self, window, response): if response: self.network_config_dialog.show() else: system_exit(os.EX_UNAVAILABLE) def _exit(self, *args): system_exit(0) def __init__(self, backend=None, ent_dir=None, prod_dir=None, auto_launch_registration=False): super(MainWindow, self).__init__() rhsm_cfg = config.initConfig() proxy_server = rhsm_cfg.get("server", "proxy_hostname") proxy_port = int(rhsm_cfg.get("server", "proxy_port") or config.DEFAULT_PROXY_PORT) def show_proxy_error_dialog(proxy_auth_required=False): """ When proxy server is set in configuration and it is not possible to connect to proxy server, then open dialog for setting proxy server. """ if proxy_auth_required: proxy_user = rhsm_cfg.get("server", "proxy_user") proxy_password = rhsm_cfg.get("server", "proxy_password") if proxy_user or proxy_password: err_msg = _("Wrong proxy username or password, please check your settings.") else: err_msg = _("Proxy authentication required, please check your settings.") else: err_msg = _("Proxy connection failed, please check your settings.") print_error(err_msg) error_dialog = messageWindow.ContinueDialog(err_msg, self._get_window()) error_dialog.connect("response", self._on_proxy_error_dialog_response) self.network_config_dialog = networkConfig.NetworkConfigDialog() # Sub-man gui will be terminated after saving settings and it is # necessary to start it once again. self.network_config_dialog.saveButton.connect("clicked", self._exit) self.network_config_dialog.cancelButton.connect("clicked", self._exit) self.backend = backend or Backend() cp = self.backend.cp_provider.get_consumer_auth_cp() if proxy_server: if not utils.test_proxy_reachability(proxy_server, proxy_port): show_proxy_error_dialog() return try: # Try to send to the simplest Rest API call to Candlepin server. # This result will be used for getting version of Candlepin server. # See self.log_server_version. cp.supports_resource("status") except socket.error as err: # See https://tools.ietf.org/html/rfc7235#section-4.3 if "407 Proxy Authentication Required" in err.message: show_proxy_error_dialog(proxy_auth_required=True) return self.identity = require(IDENTITY) log.debug("Client Versions: %s " % get_client_versions()) ga_GLib.idle_add(self.log_server_version, cp) settings = self.main_window.get_settings() # prevent gtk from trying to save a list of recently used files, which # as root, causes gtk warning: # "Attempting to set the permissions of `/root/.local/share/recently-used.xbel' # The __name__ use is just for the 'origin' value gtk uses to store # where a Gtk.Settings value was set. settings.set_long_property('gtk-recent-files-max-age', 0, "%s:%s" % (__name__, type(self).__name__)) ga_Gtk.Window.set_default_icon_name("subscription-manager") self.product_dir = prod_dir or self.backend.product_dir self.entitlement_dir = ent_dir or self.backend.entitlement_dir self.system_facts_dialog = factsgui.SystemFactsDialog(update_callback=self._handle_facts_updated) self.preferences_dialog = PreferencesDialog(self.backend, self._get_window()) self.repos_dialog = RepositoriesDialog(self.backend, self._get_window()) self.import_sub_dialog = ImportSubDialog() self.network_config_dialog = networkConfig.NetworkConfigDialog() self.network_config_dialog.saveButton.connect("clicked", self._config_changed) self.redeem_dialog = redeem.RedeemDialog(self.backend) self.installed_tab_icon = ga_Gtk.Image() self.installed_tab_icon.set_from_stock(ga_Gtk.STOCK_YES, ga_Gtk.IconSize.MENU) self.installed_tab = InstalledProductsTab(self.backend, self.installed_tab_icon, self, ent_dir=self.entitlement_dir, prod_dir=self.product_dir) self.my_subs_tab = MySubscriptionsTab(self.backend, self.main_window, ent_dir=self.entitlement_dir, prod_dir=self.product_dir) self.all_subs_tab = AllSubscriptionsTab(self.backend, self.main_window) hbox = ga_Gtk.HBox(spacing=6) hbox.pack_start(self.installed_tab_icon, False, False, 0) hbox.pack_start(ga_Gtk.Label(self.installed_tab.get_label()), False, False, 0) self.notebook.append_page(self.installed_tab.get_content(), hbox) hbox.show_all() self.notebook.append_page(self.my_subs_tab.get_content(), ga_Gtk.Label(self.my_subs_tab.get_label())) self.connect_signals({ "on_register_menu_item_activate": self._register_item_clicked, "on_unregister_menu_item_activate": self._unregister_item_clicked, "on_import_cert_menu_item_activate": self._import_cert_item_clicked, "on_view_facts_menu_item_activate": self._facts_item_clicked, "on_proxy_config_menu_item_activate": self._proxy_config_item_clicked, "on_redeem_menu_item_activate": self._redeem_item_clicked, "on_preferences_menu_item_activate": self._preferences_item_clicked, "on_repos_menu_item_activate": self._repos_item_clicked, "on_about_menu_item_activate": self._about_item_clicked, "on_getting_started_menu_item_activate": self._getting_started_item_clicked, "on_online_docs_menu_item_activate": self._online_docs_item_clicked, "on_quit_menu_item_activate": ga_Gtk.main_quit, }) # various state tracking for async operations self._show_overrides = False self._can_redeem = False self.backend.cs.add_callback(self.on_cert_sorter_cert_change) self.main_window.show_all() # Check to see if already registered to old RHN/Spacewalk # and show dialog if so self._check_rhn_classic() # Update everything with compliance data self.backend.cs.notify() # managergui needs cert_sort.cert_monitor.run_check() to run # on a timer to detect cert changes from outside the gui # (via rhsmdd for example, or manually provisioned). cert_monitor_thread = threading.Thread(target=self._cert_check_timer, name="CertMonitorThread") cert_monitor_thread.daemon = True cert_monitor_thread.start() if auto_launch_registration and not self.registered(): self._register_item_clicked(None) enabled_yum_plugins = YumPluginManager.enable_pkg_plugins() if len(enabled_yum_plugins) > 0: messageWindow.InfoDialog( YumPluginManager.warning_message(enabled_yum_plugins), self._get_window(), _("Warning - subscription-manager plugins were automatically enabled") ) def registered(self): return self.identity.is_valid() def _cert_check_timer(self): while True: self.backend.on_cert_check_timer() time.sleep(2.0) def _cert_change_update(self): # Update installed products self.installed_tab.refresh() # Update attached subs self.my_subs_tab.refresh() # Update main window self.refresh() # Reset repos dialog, see bz 1132919 self.repos_dialog = RepositoriesDialog(self.backend, self._get_window()) # When something causes cert_sorter to update it's state, refresh the gui # The cert directories being updated will cause this (either noticed # from a timer, or via cert_sort.force_cert_check). def on_cert_sorter_cert_change(self): # gather data used in GUI refresh self._show_overrides = self._should_show_overrides() self._can_redeem = self._should_show_redeem() self.installed_tab.update() self.my_subs_tab.update_subscriptions(update_gui=False) # don't update GUI since we're in a different thread # queue up in the main thread since the cert check may be done by another thread. ga_GLib.idle_add(self._cert_change_update) def _on_sla_back_button_press(self): self._perform_unregister() self._register_item_clicked(None) def _on_sla_cancel_button_press(self): self._perform_unregister() def on_registration_changed(self): # Show the All Subscriptions tab if registered, hide it otherwise: if self.registered() and self.notebook.get_n_pages() == 2: self.notebook.append_page(self.all_subs_tab.get_content(), ga_Gtk.Label(self.all_subs_tab.get_label())) elif not self.registered() and self.notebook.get_n_pages() == 3: self.notebook.set_current_page(0) self.notebook.remove_page(2) # we've unregistered, clear pools from all subscriptions tab # so it's correct if we reshow it self.all_subs_tab.sub_details.clear() self.all_subs_tab.clear_pools() self.installed_tab.set_registered(self.registered()) self._show_buttons() self._show_redemption_buttons() def refresh(self): """ Refresh the UI. """ # Always run on startup, when there is no last_uuid if not hasattr(self, 'last_uuid') or self.identity.uuid != self.last_uuid: self.last_uuid = self.identity.uuid self.on_registration_changed() self.all_subs_tab.refresh() self.installed_tab.refresh() self.my_subs_tab.refresh() def _get_window(self): """ Return the window containing this widget (might be different for firstboot). """ return self.main_window def _show_buttons(self): """ Renders the Tools buttons dynamically. """ is_registered = self.registered() if is_registered: #self.register_menu_item.hide() self.register_menu_item.set_sensitive(False) self.unregister_menu_item.set_sensitive(True) self.settings_menu_item.set_sensitive(True) # preferences self.import_cert_menu_item.set_sensitive(False) else: self.register_menu_item.set_sensitive(True) self.unregister_menu_item.set_sensitive(False) self.settings_menu_item.set_sensitive(False) self.import_cert_menu_item.set_sensitive(True) if self._show_overrides: self.repos_menu_item.set_sensitive(True) else: self.repos_menu_item.set_sensitive(False) def _should_show_overrides(self): is_registered = self.registered() show_overrides = False try: cp = self.backend.cp_provider.get_consumer_auth_cp() # This can throw an exception if we cannot connect to the server, bz 1058374 show_overrides = is_registered and cp.supports_resource('content_overrides') except Exception as e: log.debug("Failed to check if the server supports resource content_overrides") log.debug(e) return show_overrides def _show_redemption_buttons(self): if self._can_redeem: self.redeem_menu_item.set_sensitive(True) else: self.redeem_menu_item.set_sensitive(False) def _should_show_redeem(self): # Check if consumer can redeem a subscription - if an identity cert exists can_redeem = False if self.identity.uuid: try: consumer = self.backend.cp_provider.get_consumer_auth_cp().getConsumer(self.identity.uuid, None, None) can_redeem = consumer['canActivate'] except Exception: can_redeem = False return can_redeem def _register_item_clicked(self, widget): registration_dialog = registergui.RegisterDialog(self.backend) registration_dialog.register_dialog.connect('destroy', self._on_dialog_destroy, widget) registration_dialog.window.set_transient_for(self._get_window()) if registration_dialog and widget: widget.set_sensitive(False) registration_dialog.initialize() registration_dialog.show() def _on_dialog_destroy(self, obj, widget): # bz#1382897 make sure register menu item is left in appropriate state if (widget is not self.register_menu_item or not self.registered()) and widget: widget.set_sensitive(True) return False def _preferences_item_clicked(self, widget): try: self.preferences_dialog.show() except Exception as e: handle_gui_exception(e, _("Error in preferences dialog." "Please see /var/log/rhsm/rhsm.log for more information."), self._get_window()) def _repos_item_clicked(self, widget): try: self.repos_dialog.show() except Exception as e: handle_gui_exception(e, _("Error in repos dialog. " "Please see /var/log/rhsm/rhsm.log for more information."), self._get_window()) def _on_unregister_prompt_response(self, dialog, response): if not response: log.debug("unregister prompt not confirmed. cancelling") return log.debug("Proceeding with un-registration: %s", self.identity.uuid) self._perform_unregister() def _perform_unregister(self): try: reset_resolver() unregister.UnregisterService(self.backend.cp_provider.get_consumer_auth_cp()).unregister() except Exception as e: log.error("Error unregistering system with entitlement platform.") handle_gui_exception(e, _("<b>Errors were encountered during unregister.</b>") + "\n%s\n" + _("Please see /var/log/rhsm/rhsm.log for more information."), self.main_window, log_msg="Consumer may need to be manually cleaned up: %s" % self.identity.uuid) # managerlib.unregister removes product and entitlement directories self.backend.product_dir.__init__() self.backend.entitlement_dir.__init__() # We have new credentials, restart virt-who restart_virt_who() self.backend.cs.force_cert_check() def _unregister_item_clicked(self, widget): log.debug("Unregister button pressed, asking for confirmation.") prompt = messageWindow.YesNoDialog( _("<b>Are you sure you want to unregister?</b>"), self._get_window()) prompt.connect('response', self._on_unregister_prompt_response) def _proxy_config_item_clicked(self, widget): self.network_config_dialog.set_parent_window(self._get_window()) self.network_config_dialog.show() def _facts_item_clicked(self, widget): self.system_facts_dialog.set_parent_window(self._get_window()) self.system_facts_dialog.show() def _import_cert_item_clicked(self, widget): self.import_sub_dialog.set_parent_window(self._get_window()) self.import_sub_dialog.show() def _update_certificates_button_clicked(self, widget): autobind_wizard = registergui.AutobindWizardDialog(self.backend) autobind_wizard.register_dialog.connect('destroy', self._on_dialog_destroy, widget) autobind_wizard.window.set_transient_for(self._get_window()) if autobind_wizard and widget: widget.set_sensitive(False) autobind_wizard.initialize() autobind_wizard.show() def _redeem_item_clicked(self, widget): self.redeem_dialog.set_parent_window(self._get_window()) self.redeem_dialog.show() def _getting_started_item_clicked(self, widget): try: # try to open documentation in yelp ga_Gtk.show_uri(None, 'ghelp:subscription-manager', time.time()) except Exception as e: # if we can't open it, it's probably because the user didn't # install the docs, or yelp. no need to bother them. log.warn("Unable to open help documentation: %s", e) def _about_item_clicked(self, widget): about = AboutDialog(self._get_window(), self.backend) about.show() def _online_docs_item_clicked(self, widget): browser = None for possible_browser in PREFERRED_BROWSERS: try: browser = webbrowser.get(possible_browser) break except webbrowser.Error: pass if browser is None: utils.show_error_window(NO_BROWSER_MESSAGE % (self._get_online_doc_url())) else: webbrowser.open_new(self._get_online_doc_url()) def _quit_item_clicked(self): self.hide() def _config_changed(self, widget): # update the backend's UEP in case we changed proxy # config. We specify all these settings since they # are new and the default UEP init won't get them # (it's default args are set at class init time) self.backend.update() def _check_rhn_classic(self): if ClassicCheck().is_registered_with_classic(): prompt = messageWindow.ContinueDialog( linkify(get_branding().REGISTERED_TO_OTHER_WARNING), self.main_window, _("System Already Registered")) prompt.connect('response', self._on_rhn_classic_response) def _on_rhn_classic_response(self, dialog, response): if not response: self.main_window.hide() def _get_online_doc_url(self): lang, encoding = locale.getdefaultlocale() if lang is not None: url = ONLINE_DOC_URL_TEMPLATE % (lang.replace("_", "-").lower()) else: url = ONLINE_DOC_FALLBACK_URL try: urllib.request.urlopen(url) except urllib.error.URLError: # Use the default if there is no translation. url = ONLINE_DOC_FALLBACK_URL return url def _handle_facts_updated(self): # see bz 1323271 - update compliance on update of facts self.backend.cs.load() self.backend.cs.notify()
def __init__(self, backend=None, ent_dir=None, prod_dir=None, auto_launch_registration=False): super(MainWindow, self).__init__() rhsm_cfg = config.initConfig() proxy_server = rhsm_cfg.get("server", "proxy_hostname") proxy_port = int(rhsm_cfg.get("server", "proxy_port") or config.DEFAULT_PROXY_PORT) def show_proxy_error_dialog(proxy_auth_required=False): """ When proxy server is set in configuration and it is not possible to connect to proxy server, then open dialog for setting proxy server. """ if proxy_auth_required: proxy_user = rhsm_cfg.get("server", "proxy_user") proxy_password = rhsm_cfg.get("server", "proxy_password") if proxy_user or proxy_password: err_msg = _("Wrong proxy username or password, please check your settings.") else: err_msg = _("Proxy authentication required, please check your settings.") else: err_msg = _("Proxy connection failed, please check your settings.") print_error(err_msg) error_dialog = messageWindow.ContinueDialog(err_msg, self._get_window()) error_dialog.connect("response", self._on_proxy_error_dialog_response) self.network_config_dialog = networkConfig.NetworkConfigDialog() # Sub-man gui will be terminated after saving settings and it is # necessary to start it once again. self.network_config_dialog.saveButton.connect("clicked", self._exit) self.network_config_dialog.cancelButton.connect("clicked", self._exit) self.backend = backend or Backend() cp = self.backend.cp_provider.get_consumer_auth_cp() if proxy_server: if not utils.test_proxy_reachability(proxy_server, proxy_port): show_proxy_error_dialog() return try: # Try to send to the simplest Rest API call to Candlepin server. # This result will be used for getting version of Candlepin server. # See self.log_server_version. cp.supports_resource("status") except socket.error as err: # See https://tools.ietf.org/html/rfc7235#section-4.3 if "407 Proxy Authentication Required" in err.message: show_proxy_error_dialog(proxy_auth_required=True) return self.identity = require(IDENTITY) log.debug("Client Versions: %s " % get_client_versions()) ga_GLib.idle_add(self.log_server_version, cp) settings = self.main_window.get_settings() # prevent gtk from trying to save a list of recently used files, which # as root, causes gtk warning: # "Attempting to set the permissions of `/root/.local/share/recently-used.xbel' # The __name__ use is just for the 'origin' value gtk uses to store # where a Gtk.Settings value was set. settings.set_long_property('gtk-recent-files-max-age', 0, "%s:%s" % (__name__, type(self).__name__)) ga_Gtk.Window.set_default_icon_name("subscription-manager") self.product_dir = prod_dir or self.backend.product_dir self.entitlement_dir = ent_dir or self.backend.entitlement_dir self.system_facts_dialog = factsgui.SystemFactsDialog(update_callback=self._handle_facts_updated) self.preferences_dialog = PreferencesDialog(self.backend, self._get_window()) self.repos_dialog = RepositoriesDialog(self.backend, self._get_window()) self.import_sub_dialog = ImportSubDialog() self.network_config_dialog = networkConfig.NetworkConfigDialog() self.network_config_dialog.saveButton.connect("clicked", self._config_changed) self.redeem_dialog = redeem.RedeemDialog(self.backend) self.installed_tab_icon = ga_Gtk.Image() self.installed_tab_icon.set_from_stock(ga_Gtk.STOCK_YES, ga_Gtk.IconSize.MENU) self.installed_tab = InstalledProductsTab(self.backend, self.installed_tab_icon, self, ent_dir=self.entitlement_dir, prod_dir=self.product_dir) self.my_subs_tab = MySubscriptionsTab(self.backend, self.main_window, ent_dir=self.entitlement_dir, prod_dir=self.product_dir) self.all_subs_tab = AllSubscriptionsTab(self.backend, self.main_window) hbox = ga_Gtk.HBox(spacing=6) hbox.pack_start(self.installed_tab_icon, False, False, 0) hbox.pack_start(ga_Gtk.Label(self.installed_tab.get_label()), False, False, 0) self.notebook.append_page(self.installed_tab.get_content(), hbox) hbox.show_all() self.notebook.append_page(self.my_subs_tab.get_content(), ga_Gtk.Label(self.my_subs_tab.get_label())) self.connect_signals({ "on_register_menu_item_activate": self._register_item_clicked, "on_unregister_menu_item_activate": self._unregister_item_clicked, "on_import_cert_menu_item_activate": self._import_cert_item_clicked, "on_view_facts_menu_item_activate": self._facts_item_clicked, "on_proxy_config_menu_item_activate": self._proxy_config_item_clicked, "on_redeem_menu_item_activate": self._redeem_item_clicked, "on_preferences_menu_item_activate": self._preferences_item_clicked, "on_repos_menu_item_activate": self._repos_item_clicked, "on_about_menu_item_activate": self._about_item_clicked, "on_getting_started_menu_item_activate": self._getting_started_item_clicked, "on_online_docs_menu_item_activate": self._online_docs_item_clicked, "on_quit_menu_item_activate": ga_Gtk.main_quit, }) # various state tracking for async operations self._show_overrides = False self._can_redeem = False self.backend.cs.add_callback(self.on_cert_sorter_cert_change) self.main_window.show_all() # Check to see if already registered to old RHN/Spacewalk # and show dialog if so self._check_rhn_classic() # Update everything with compliance data self.backend.cs.notify() # managergui needs cert_sort.cert_monitor.run_check() to run # on a timer to detect cert changes from outside the gui # (via rhsmdd for example, or manually provisioned). cert_monitor_thread = threading.Thread(target=self._cert_check_timer, name="CertMonitorThread") cert_monitor_thread.daemon = True cert_monitor_thread.start() if auto_launch_registration and not self.registered(): self._register_item_clicked(None) enabled_yum_plugins = YumPluginManager.enable_pkg_plugins() if len(enabled_yum_plugins) > 0: messageWindow.InfoDialog( YumPluginManager.warning_message(enabled_yum_plugins), self._get_window(), _("Warning - subscription-manager plugins were automatically enabled") )
class RegisterScreen: """ Registration Widget Screen """ def __init__(self, backend, consumer, facts=None, callbacks=None): """ Callbacks will be executed when registration status changes. """ self.backend = backend self.consumer = consumer self.facts = facts self.callbacks = callbacks self.async = AsyncBackend(self.backend) dic = {"on_register_cancel_button_clicked": self.cancel, "on_register_button_clicked": self.on_register_button_clicked, "on_proxy_config_button_clicked": self._on_proxy_config_button_clicked, "on_import_certs_button_clicked": self._on_import_certs_button_clicked, "on_rhn_radio_toggled": self._server_radio_toggled, "on_local_radio_toggled": self._server_radio_toggled, "on_offline_radio_toggled": self._server_radio_toggled, } registration_xml.signal_autoconnect(dic) self.registerWin = registration_xml.get_widget("register_dialog") self.registerWin.connect("hide", self.cancel) self.registerWin.connect("delete_event", self.delete_event) self.initializeConsumerName() self.uname = registration_xml.get_widget("account_login") self.passwd = registration_xml.get_widget("account_password") self.consumer_name = registration_xml.get_widget("consumer_name") self.skip_auto_bind = registration_xml.get_widget("skip_auto_bind") self.register_notebook = \ registration_xml.get_widget("register_notebook") self.register_progressbar = \ registration_xml.get_widget("register_progressbar") self.register_details_label = \ registration_xml.get_widget("register_details_label") self.owner_treeview = registration_xml.get_widget("owner_treeview") renderer = gtk.CellRendererText() column = gtk.TreeViewColumn(_("Organization"), renderer, text=1) self.owner_treeview.set_property("headers-visible", False) self.owner_treeview.append_column(column) self.environment_treeview = registration_xml.get_widget("environment_treeview") renderer = gtk.CellRendererText() column = gtk.TreeViewColumn(_("Environment"), renderer, text=1) self.environment_treeview.set_property("headers-visible", False) self.environment_treeview.append_column(column) self.cancel_button = registration_xml.get_widget("cancel_button") self.register_button = registration_xml.get_widget("register_button") register_tip_label = registration_xml.get_widget("registrationTip") register_tip_label.set_label("<small>%s</small>" % \ get_branding().GUI_FORGOT_LOGIN_TIP) register_header_label = \ registration_xml.get_widget("registrationHeader") register_header_label.set_label("<b>%s</b>" % \ get_branding().GUI_REGISTRATION_HEADER) self.rhn_radio = registration_xml.get_widget("rhn_radio") self.local_radio = registration_xml.get_widget("local_radio") self.offline_radio = registration_xml.get_widget("offline_radio") self.local_entry = registration_xml.get_widget("local_entry") self.import_certs_button = registration_xml.get_widget( "import_certs_button") self.proxy_label = registration_xml.get_widget("proxy_label") self.proxy_config_button = registration_xml.get_widget( "proxy_config_button") self.network_config_dialog = networkConfig.NetworkConfigDialog() self.import_certs_dialog = ImportSubDialog() def show(self): # Ensure that we start on the first page and that # all widgets are cleared. self._show_choose_server_page() self._clear_registration_widgets() self.registerWin.present() def _show_choose_server_page(self): # Override the button text to clarify we're not actually registering # by pressing that button here. self.register_button.set_label(_("Next")) self.register_notebook.set_page(CHOOSE_SERVER_PAGE) def _show_credentials_page(self): # Set the button text back after we changed it when showing the # choose server screen. self.register_button.set_label(_("Register")) self.register_notebook.set_page(CREDENTIALS_PAGE) def delete_event(self, event, data=None): return self.close_window() def cancel(self, button): self.close_window() def initializeConsumerName(self): consumername = registration_xml.get_widget("consumer_name") if not consumername.get_text(): consumername.set_text(socket.gethostname()) # callback needs the extra arg, so just a wrapper here def on_register_button_clicked(self, button): self.register() def _on_proxy_config_button_clicked(self, button): self.network_config_dialog.set_parent_window(self.registerWin) self.network_config_dialog.show() def _on_import_certs_button_clicked(self, button): self.import_certs_dialog.set_parent_window(self.registerWin) self.import_certs_dialog.show() def register(self, testing=None): if self.register_notebook.get_current_page() == CHOOSE_SERVER_PAGE: self._server_selected() return True if self.register_notebook.get_current_page() == OWNER_SELECT_PAGE: # we're on the owner select page self._owner_selected() return True elif self.register_notebook.get_current_page() == ENVIRONMENT_SELECT_PAGE: self._environment_selected() return True username = self.uname.get_text().strip() password = self.passwd.get_text().strip() consumername = self.consumer_name.get_text() if not self.validate_consumername(consumername): return False if not self.validate_account(): return False # for firstboot -t if testing: return True self.backend.create_admin_uep(username=username, password=password) self.async.get_owner_list(username, self._on_get_owner_list_cb) self.timer = gobject.timeout_add(100, self._timeout_callback) self.register_notebook.set_page(PROGRESS_PAGE) self._set_register_details_label(_("Fetching list of possible organizations")) self.cancel_button.set_sensitive(False) self.register_button.set_sensitive(False) return True def _timeout_callback(self): self.register_progressbar.pulse() # return true to keep it pulsing return True def _on_get_owner_list_cb(self, owners, error=None): if error != None: handle_gui_exception(error, REGISTER_ERROR, self.registerWin) self._finish_registration(failed=True) return owners = [(owner['key'], owner['displayName']) for owner in owners] if len(owners) == 0: handle_gui_exception(None, _("<b>User %s is not able to register with any orgs.</b>") \ % (self.uname.get_text().strip()), self.registerWin) self._finish_registration(failed=True) return if len(owners) == 1: self.owner_key = owners[0][0] self.async.get_environment_list(self.owner_key, self._on_get_environment_list_cb) else: owner_model = gtk.ListStore(str, str) for owner in owners: owner_model.append(owner) self.owner_treeview.set_model(owner_model) self.owner_treeview.get_selection().select_iter( owner_model.get_iter_first()) self.cancel_button.set_sensitive(True) self.register_button.set_sensitive(True) self.register_notebook.set_page(OWNER_SELECT_PAGE) def _on_get_environment_list_cb(self, result_tuple, error=None): environments = result_tuple if error != None: handle_gui_exception(error, REGISTER_ERROR, self.registerWin) self._finish_registration(failed=True) return if not environments: self._run_register_step(self.owner_key, None) return envs = [(env['id'], env['name']) for env in environments] if len(envs) == 1: self._run_register_step(self.owner_key, envs[0][0]) else: environment_model = gtk.ListStore(str, str) for env in envs: environment_model.append(env) self.environment_treeview.set_model(environment_model) self.environment_treeview.get_selection().select_iter( environment_model.get_iter_first()) self.cancel_button.set_sensitive(True) self.register_button.set_sensitive(True) self.register_notebook.set_page(ENVIRONMENT_SELECT_PAGE) # Callback used by the owner selection screen: def _owner_selected(self): self.cancel_button.set_sensitive(False) self.register_button.set_sensitive(False) self.register_notebook.set_page(PROGRESS_PAGE) model, tree_iter = self.owner_treeview.get_selection().get_selected() self.owner_key = model.get_value(tree_iter, 0) self.async.get_environment_list(self.owner_key, self._on_get_environment_list_cb) def _server_radio_toggled(self, widget): self.local_entry.set_sensitive(self.local_radio.get_active()) def _server_selected(self): if self.rhn_radio.get_active(): CFG.set('server', 'hostname', config.DEFAULT_HOSTNAME) CFG.set('server', 'port', config.DEFAULT_PORT) CFG.set('server', 'prefix', config.DEFAULT_PREFIX) elif self.offline_radio.get_active(): # We'll signal the user set offline by setting an empty hostname: CFG.set('server', 'hostname', '') CFG.set('server', 'port', config.DEFAULT_PORT) CFG.set('server', 'prefix', config.DEFAULT_PREFIX) elif self.local_radio.get_active(): local_server = self.local_entry.get_text() try: (hostname, port, prefix) = parse_server_info(local_server) CFG.set('server', 'hostname', hostname) CFG.set('server', 'port', port) CFG.set('server', 'prefix', prefix) try: if not is_valid_server_info(hostname, port, prefix): errorWindow(_("Unable to reach the server at %s:%s%s" % (hostname, port, prefix))) return except MissingCaCertException: errorWindow(_("CA certificate for subscription service has not been installed.")) return except ServerUrlParseError: errorWindow(_("Please provide a hostname with optional port and/or prefix: hostname[:port][/prefix]"), self.registerWin) return log.info("Writing server data to rhsm.conf") CFG.save() self.backend.update() if self.offline_radio.get_active(): # Because the user selected offline, the whole registration process # must end here. self._offline_selected() else: self._show_credentials_page() def _offline_selected(self): self.close_window() def _environment_selected(self): self.cancel_button.set_sensitive(False) self.register_button.set_sensitive(False) self.register_notebook.set_page(PROGRESS_PAGE) model, tree_iter = self.environment_treeview.get_selection().get_selected() env = model.get_value(tree_iter, 0) self._run_register_step(self.owner_key, env) def _run_register_step(self, owner, env): log.info("Registering to owner: %s environment: %s" % (owner, env)) self.async.register_consumer(self.consumer_name.get_text(), self.facts, owner, env, self._on_registration_finished_cb) self._set_register_details_label(_("Registering your system")) def _on_registration_finished_cb(self, new_account, error=None): try: if error != None: raise error managerlib.persist_consumer_cert(new_account) self.consumer.reload() self._finish_registration() except Exception, e: handle_gui_exception(e, REGISTER_ERROR, self.registerWin) self._finish_registration(failed=True)
def __init__(self, backend, consumer, facts=None, callbacks=None): """ Callbacks will be executed when registration status changes. """ self.backend = backend self.consumer = consumer self.facts = facts self.callbacks = callbacks self.async = AsyncBackend(self.backend) dic = {"on_register_cancel_button_clicked": self.cancel, "on_register_button_clicked": self.on_register_button_clicked, "on_proxy_config_button_clicked": self._on_proxy_config_button_clicked, "on_import_certs_button_clicked": self._on_import_certs_button_clicked, "on_rhn_radio_toggled": self._server_radio_toggled, "on_local_radio_toggled": self._server_radio_toggled, "on_offline_radio_toggled": self._server_radio_toggled, } registration_xml.signal_autoconnect(dic) self.registerWin = registration_xml.get_widget("register_dialog") self.registerWin.connect("hide", self.cancel) self.registerWin.connect("delete_event", self.delete_event) self.initializeConsumerName() self.uname = registration_xml.get_widget("account_login") self.passwd = registration_xml.get_widget("account_password") self.consumer_name = registration_xml.get_widget("consumer_name") self.skip_auto_bind = registration_xml.get_widget("skip_auto_bind") self.register_notebook = \ registration_xml.get_widget("register_notebook") self.register_progressbar = \ registration_xml.get_widget("register_progressbar") self.register_details_label = \ registration_xml.get_widget("register_details_label") self.owner_treeview = registration_xml.get_widget("owner_treeview") renderer = gtk.CellRendererText() column = gtk.TreeViewColumn(_("Organization"), renderer, text=1) self.owner_treeview.set_property("headers-visible", False) self.owner_treeview.append_column(column) self.environment_treeview = registration_xml.get_widget("environment_treeview") renderer = gtk.CellRendererText() column = gtk.TreeViewColumn(_("Environment"), renderer, text=1) self.environment_treeview.set_property("headers-visible", False) self.environment_treeview.append_column(column) self.cancel_button = registration_xml.get_widget("cancel_button") self.register_button = registration_xml.get_widget("register_button") register_tip_label = registration_xml.get_widget("registrationTip") register_tip_label.set_label("<small>%s</small>" % \ get_branding().GUI_FORGOT_LOGIN_TIP) register_header_label = \ registration_xml.get_widget("registrationHeader") register_header_label.set_label("<b>%s</b>" % \ get_branding().GUI_REGISTRATION_HEADER) self.rhn_radio = registration_xml.get_widget("rhn_radio") self.local_radio = registration_xml.get_widget("local_radio") self.offline_radio = registration_xml.get_widget("offline_radio") self.local_entry = registration_xml.get_widget("local_entry") self.import_certs_button = registration_xml.get_widget( "import_certs_button") self.proxy_label = registration_xml.get_widget("proxy_label") self.proxy_config_button = registration_xml.get_widget( "proxy_config_button") self.network_config_dialog = networkConfig.NetworkConfigDialog() self.import_certs_dialog = ImportSubDialog()
def __init__(self, backend=None, facts=None, ent_dir=None, prod_dir=None, auto_launch_registration=False): super(MainWindow, self).__init__('mainwindow.glade') self.backend = backend or Backend() self.identity = require(IDENTITY) self.facts = facts or Facts(self.backend.entitlement_dir, self.backend.product_dir) # We need to make sure facts are loaded immediately, some GUI operations # are done in separate threads, and if facts try to load in another # thread the virt guest detection code breaks due to hwprobe's use of # signals. self.facts.get_facts() log.debug("Client Versions: %s " % get_client_versions()) log.debug("Server Versions: %s " % get_server_versions( self.backend.cp_provider.get_consumer_auth_cp())) self.product_dir = prod_dir or self.backend.product_dir self.entitlement_dir = ent_dir or self.backend.entitlement_dir self.system_facts_dialog = factsgui.SystemFactsDialog( self.backend, self.facts) self.registration_dialog = registergui.RegisterScreen( self.backend, self.facts, self._get_window()) self.preferences_dialog = PreferencesDialog(self.backend, self._get_window()) self.import_sub_dialog = ImportSubDialog() self.network_config_dialog = networkConfig.NetworkConfigDialog() self.network_config_dialog.xml.get_widget("closeButton").connect( "clicked", self._config_changed) self.redeem_dialog = redeem.RedeemDialog(self.backend) self.installed_tab_icon = gtk.Image() self.installed_tab_icon.set_from_stock(gtk.STOCK_YES, gtk.ICON_SIZE_MENU) self.installed_tab = InstalledProductsTab(self.backend, self.facts, self.installed_tab_icon, self, ent_dir=self.entitlement_dir, prod_dir=self.product_dir) self.my_subs_tab = MySubscriptionsTab(self.backend, self.main_window, ent_dir=self.entitlement_dir, prod_dir=self.product_dir) self.all_subs_tab = AllSubscriptionsTab(self.backend, self.facts, self.main_window) hbox = gtk.HBox(spacing=6) hbox.pack_start(self.installed_tab_icon, False, False) hbox.pack_start(gtk.Label(self.installed_tab.get_label()), False, False) self.notebook.append_page(self.installed_tab.get_content(), hbox) hbox.show_all() self.notebook.append_page(self.my_subs_tab.get_content(), gtk.Label(self.my_subs_tab.get_label())) self.glade.signal_autoconnect({ "on_register_menu_item_activate": self._register_item_clicked, "on_unregister_menu_item_activate": self._unregister_item_clicked, "on_import_cert_menu_item_activate": self._import_cert_item_clicked, "on_view_facts_menu_item_activate": self._facts_item_clicked, "on_proxy_config_menu_item_activate": self._proxy_config_item_clicked, "on_redeem_menu_item_activate": self._redeem_item_clicked, "on_preferences_menu_item_activate": self._preferences_item_clicked, "on_about_menu_item_activate": self._about_item_clicked, "on_getting_started_menu_item_activate": self._getting_started_item_clicked, "on_online_docs_menu_item_activate": self._online_docs_item_clicked, "on_quit_menu_item_activate": gtk.main_quit, }) def on_cert_change(): # Update installed products self.installed_tab.update_products() self.installed_tab._set_validity_status() # Update attached subs self.my_subs_tab.update_subscriptions() # Update main window self.refresh() self.backend.cs.add_callback(on_cert_change) self.main_window.show_all() # Check to see if already registered to old RHN/Spacewalk # and show dialog if so self._check_rhn_classic() # Update everything with compliance data self.backend.cs.notify() if auto_launch_registration and not self.registered(): self._register_item_clicked(None)
def __init__(self, backend=None, ent_dir=None, prod_dir=None, auto_launch_registration=False): super(MainWindow, self).__init__() if not self.test_proxy_connection(): print_error(_("Proxy connection failed, please check your settings.")) error_dialog = messageWindow.ContinueDialog(_("Proxy connection failed, please check your settings."), self._get_window()) error_dialog.connect("response", self._on_proxy_error_dialog_response) self.network_config_dialog = networkConfig.NetworkConfigDialog() self.network_config_dialog.saveButton.connect("clicked", self._exit) self.network_config_dialog.cancelButton.connect("clicked", self._exit) return self.backend = backend or Backend() self.identity = require(IDENTITY) log.debug("Client Versions: %s " % get_client_versions()) # Log the server version asynchronously ga_GLib.idle_add(self.log_server_version, self.backend.cp_provider.get_consumer_auth_cp()) settings = self.main_window.get_settings() # prevent gtk from trying to save a list of recently used files, which # as root, causes gtk warning: # "Attempting to set the permissions of `/root/.local/share/recently-used.xbel' # The __name__ use is just for the 'origin' value gtk uses to store # where a Gtk.Settings value was set. settings.set_long_property('gtk-recent-files-max-age', 0, "%s:%s" % (__name__, type(self).__name__)) ga_Gtk.Window.set_default_icon_name("subscription-manager") self.product_dir = prod_dir or self.backend.product_dir self.entitlement_dir = ent_dir or self.backend.entitlement_dir self.system_facts_dialog = factsgui.SystemFactsDialog(update_callback=self._handle_facts_updated) self.preferences_dialog = PreferencesDialog(self.backend, self._get_window()) self.repos_dialog = RepositoriesDialog(self.backend, self._get_window()) self.import_sub_dialog = ImportSubDialog() self.network_config_dialog = networkConfig.NetworkConfigDialog() self.network_config_dialog.saveButton.connect("clicked", self._config_changed) self.redeem_dialog = redeem.RedeemDialog(self.backend) self.installed_tab_icon = ga_Gtk.Image() self.installed_tab_icon.set_from_stock(ga_Gtk.STOCK_YES, ga_Gtk.IconSize.MENU) self.installed_tab = InstalledProductsTab(self.backend, self.installed_tab_icon, self, ent_dir=self.entitlement_dir, prod_dir=self.product_dir) self.my_subs_tab = MySubscriptionsTab(self.backend, self.main_window, ent_dir=self.entitlement_dir, prod_dir=self.product_dir) self.all_subs_tab = AllSubscriptionsTab(self.backend, self.main_window) hbox = ga_Gtk.HBox(spacing=6) hbox.pack_start(self.installed_tab_icon, False, False, 0) hbox.pack_start(ga_Gtk.Label(self.installed_tab.get_label()), False, False, 0) self.notebook.append_page(self.installed_tab.get_content(), hbox) hbox.show_all() self.notebook.append_page(self.my_subs_tab.get_content(), ga_Gtk.Label(self.my_subs_tab.get_label())) self.connect_signals({ "on_register_menu_item_activate": self._register_item_clicked, "on_unregister_menu_item_activate": self._unregister_item_clicked, "on_import_cert_menu_item_activate": self._import_cert_item_clicked, "on_view_facts_menu_item_activate": self._facts_item_clicked, "on_proxy_config_menu_item_activate": self._proxy_config_item_clicked, "on_redeem_menu_item_activate": self._redeem_item_clicked, "on_preferences_menu_item_activate": self._preferences_item_clicked, "on_repos_menu_item_activate": self._repos_item_clicked, "on_about_menu_item_activate": self._about_item_clicked, "on_getting_started_menu_item_activate": self._getting_started_item_clicked, "on_online_docs_menu_item_activate": self._online_docs_item_clicked, "on_quit_menu_item_activate": ga_Gtk.main_quit, }) # various state tracking for async operations self._show_overrides = False self._can_redeem = False self.backend.cs.add_callback(self.on_cert_sorter_cert_change) self.main_window.show_all() # Check to see if already registered to old RHN/Spacewalk # and show dialog if so self._check_rhn_classic() # Update everything with compliance data self.backend.cs.notify() # managergui needs cert_sort.cert_monitor.run_check() to run # on a timer to detect cert changes from outside the gui # (via rhsmdd for example, or manually provisioned). cert_monitor_thread = threading.Thread(target=self._cert_check_timer, name="CertMonitorThread") cert_monitor_thread.daemon = True cert_monitor_thread.start() if auto_launch_registration and not self.registered(): self._register_item_clicked(None)
class MainWindow(widgets.SubmanBaseWidget): """ The new RHSM main window. """ widget_names = [ 'main_window', 'notebook', 'system_name_label', 'register_menu_item', 'unregister_menu_item', 'redeem_menu_item', 'settings_menu_item', 'repos_menu_item', 'import_cert_menu_item' ] gui_file = "mainwindow" def log_server_version(self, uep): server_versions = get_server_versions(uep) log.debug("Server Versions: %s" % server_versions) # Remove this from the GTK main loop return False def _on_proxy_error_dialog_response(self, window, response): if response: self.network_config_dialog.show() else: system_exit(os.EX_UNAVAILABLE) def _exit(self, *args): system_exit(0) def __init__(self, backend=None, ent_dir=None, prod_dir=None, auto_launch_registration=False): super(MainWindow, self).__init__() # When proxy server is set in configuration and it is not # possible to connect to proxy server, then open dialog # for setting proxy server. if not utils.test_proxy_reachability(): print_error( _("Proxy connection failed, please check your settings.")) error_dialog = messageWindow.ContinueDialog( _("Proxy connection failed, please check your settings."), self._get_window()) error_dialog.connect("response", self._on_proxy_error_dialog_response) self.network_config_dialog = networkConfig.NetworkConfigDialog() # Sub-man gui will be terminated after saving settings and it is # necessary to start it once again. self.network_config_dialog.saveButton.connect( "clicked", self._exit) self.network_config_dialog.cancelButton.connect( "clicked", self._exit) return self.backend = backend or Backend() self.identity = require(IDENTITY) log.debug("Client Versions: %s " % get_client_versions()) # Log the server version asynchronously ga_GLib.idle_add(self.log_server_version, self.backend.cp_provider.get_consumer_auth_cp()) settings = self.main_window.get_settings() # prevent gtk from trying to save a list of recently used files, which # as root, causes gtk warning: # "Attempting to set the permissions of `/root/.local/share/recently-used.xbel' # The __name__ use is just for the 'origin' value gtk uses to store # where a Gtk.Settings value was set. settings.set_long_property('gtk-recent-files-max-age', 0, "%s:%s" % (__name__, type(self).__name__)) ga_Gtk.Window.set_default_icon_name("subscription-manager") self.product_dir = prod_dir or self.backend.product_dir self.entitlement_dir = ent_dir or self.backend.entitlement_dir self.system_facts_dialog = factsgui.SystemFactsDialog( update_callback=self._handle_facts_updated) self.preferences_dialog = PreferencesDialog(self.backend, self._get_window()) self.repos_dialog = RepositoriesDialog(self.backend, self._get_window()) self.import_sub_dialog = ImportSubDialog() self.network_config_dialog = networkConfig.NetworkConfigDialog() self.network_config_dialog.saveButton.connect("clicked", self._config_changed) self.redeem_dialog = redeem.RedeemDialog(self.backend) self.installed_tab_icon = ga_Gtk.Image() self.installed_tab_icon.set_from_stock(ga_Gtk.STOCK_YES, ga_Gtk.IconSize.MENU) self.installed_tab = InstalledProductsTab(self.backend, self.installed_tab_icon, self, ent_dir=self.entitlement_dir, prod_dir=self.product_dir) self.my_subs_tab = MySubscriptionsTab(self.backend, self.main_window, ent_dir=self.entitlement_dir, prod_dir=self.product_dir) self.all_subs_tab = AllSubscriptionsTab(self.backend, self.main_window) hbox = ga_Gtk.HBox(spacing=6) hbox.pack_start(self.installed_tab_icon, False, False, 0) hbox.pack_start(ga_Gtk.Label(self.installed_tab.get_label()), False, False, 0) self.notebook.append_page(self.installed_tab.get_content(), hbox) hbox.show_all() self.notebook.append_page(self.my_subs_tab.get_content(), ga_Gtk.Label(self.my_subs_tab.get_label())) self.connect_signals({ "on_register_menu_item_activate": self._register_item_clicked, "on_unregister_menu_item_activate": self._unregister_item_clicked, "on_import_cert_menu_item_activate": self._import_cert_item_clicked, "on_view_facts_menu_item_activate": self._facts_item_clicked, "on_proxy_config_menu_item_activate": self._proxy_config_item_clicked, "on_redeem_menu_item_activate": self._redeem_item_clicked, "on_preferences_menu_item_activate": self._preferences_item_clicked, "on_repos_menu_item_activate": self._repos_item_clicked, "on_about_menu_item_activate": self._about_item_clicked, "on_getting_started_menu_item_activate": self._getting_started_item_clicked, "on_online_docs_menu_item_activate": self._online_docs_item_clicked, "on_quit_menu_item_activate": ga_Gtk.main_quit, }) # various state tracking for async operations self._show_overrides = False self._can_redeem = False self.backend.cs.add_callback(self.on_cert_sorter_cert_change) self.main_window.show_all() # Check to see if already registered to old RHN/Spacewalk # and show dialog if so self._check_rhn_classic() # Update everything with compliance data self.backend.cs.notify() # managergui needs cert_sort.cert_monitor.run_check() to run # on a timer to detect cert changes from outside the gui # (via rhsmdd for example, or manually provisioned). cert_monitor_thread = threading.Thread(target=self._cert_check_timer, name="CertMonitorThread") cert_monitor_thread.daemon = True cert_monitor_thread.start() if auto_launch_registration and not self.registered(): self._register_item_clicked(None) enabled_yum_plugins = YumPluginManager.enable_yum_plugins() if len(enabled_yum_plugins) > 0: messageWindow.InfoDialog( YumPluginManager.warning_message(enabled_yum_plugins), self._get_window(), _("Warning - subscription-manager plugins were automatically enabled" )) def registered(self): return self.identity.is_valid() def _cert_check_timer(self): while True: self.backend.on_cert_check_timer() time.sleep(2.0) def _cert_change_update(self): # Update installed products self.installed_tab.refresh() # Update attached subs self.my_subs_tab.refresh() # Update main window self.refresh() # Reset repos dialog, see bz 1132919 self.repos_dialog = RepositoriesDialog(self.backend, self._get_window()) # When something causes cert_sorter to update it's state, refresh the gui # The cert directories being updated will cause this (either noticed # from a timer, or via cert_sort.force_cert_check). def on_cert_sorter_cert_change(self): # gather data used in GUI refresh self._show_overrides = self._should_show_overrides() self._can_redeem = self._should_show_redeem() self.installed_tab.update() self.my_subs_tab.update_subscriptions( update_gui=False ) # don't update GUI since we're in a different thread # queue up in the main thread since the cert check may be done by another thread. ga_GLib.idle_add(self._cert_change_update) def _on_sla_back_button_press(self): self._perform_unregister() self._register_item_clicked(None) def _on_sla_cancel_button_press(self): self._perform_unregister() def on_registration_changed(self): # Show the All Subscriptions tab if registered, hide it otherwise: if self.registered() and self.notebook.get_n_pages() == 2: self.notebook.append_page( self.all_subs_tab.get_content(), ga_Gtk.Label(self.all_subs_tab.get_label())) elif not self.registered() and self.notebook.get_n_pages() == 3: self.notebook.set_current_page(0) self.notebook.remove_page(2) # we've unregistered, clear pools from all subscriptions tab # so it's correct if we reshow it self.all_subs_tab.sub_details.clear() self.all_subs_tab.clear_pools() self.installed_tab.set_registered(self.registered()) self._show_buttons() self._show_redemption_buttons() def refresh(self): """ Refresh the UI. """ # Always run on startup, when there is no last_uuid if not hasattr(self, 'last_uuid') or self.identity.uuid != self.last_uuid: self.last_uuid = self.identity.uuid self.on_registration_changed() self.all_subs_tab.refresh() self.installed_tab.refresh() self.my_subs_tab.refresh() def _get_window(self): """ Return the window containing this widget (might be different for firstboot). """ return self.main_window def _show_buttons(self): """ Renders the Tools buttons dynamically. """ is_registered = self.registered() if is_registered: #self.register_menu_item.hide() self.register_menu_item.set_sensitive(False) self.unregister_menu_item.set_sensitive(True) self.settings_menu_item.set_sensitive(True) # preferences self.import_cert_menu_item.set_sensitive(False) else: self.register_menu_item.set_sensitive(True) self.unregister_menu_item.set_sensitive(False) self.settings_menu_item.set_sensitive(False) self.import_cert_menu_item.set_sensitive(True) if self._show_overrides: self.repos_menu_item.set_sensitive(True) else: self.repos_menu_item.set_sensitive(False) def _should_show_overrides(self): is_registered = self.registered() show_overrides = False try: cp = self.backend.cp_provider.get_consumer_auth_cp() # This can throw an exception if we cannot connect to the server, bz 1058374 show_overrides = is_registered and cp.supports_resource( 'content_overrides') except Exception as e: log.debug( "Failed to check if the server supports resource content_overrides" ) log.debug(e) return show_overrides def _show_redemption_buttons(self): if self._can_redeem: self.redeem_menu_item.set_sensitive(True) else: self.redeem_menu_item.set_sensitive(False) def _should_show_redeem(self): # Check if consumer can redeem a subscription - if an identity cert exists can_redeem = False if self.identity.uuid: try: consumer = self.backend.cp_provider.get_consumer_auth_cp( ).getConsumer(self.identity.uuid, None, None) can_redeem = consumer['canActivate'] except Exception: can_redeem = False return can_redeem def _register_item_clicked(self, widget): registration_dialog = registergui.RegisterDialog(self.backend) registration_dialog.register_dialog.connect('destroy', self._on_dialog_destroy, widget) registration_dialog.window.set_transient_for(self._get_window()) if registration_dialog and widget: widget.set_sensitive(False) registration_dialog.initialize() registration_dialog.show() def _on_dialog_destroy(self, obj, widget): # bz#1382897 make sure register menu item is left in appropriate state if (widget is not self.register_menu_item or not self.registered()) and widget: widget.set_sensitive(True) return False def _preferences_item_clicked(self, widget): try: self.preferences_dialog.show() except Exception as e: handle_gui_exception( e, _("Error in preferences dialog." "Please see /var/log/rhsm/rhsm.log for more information."), self._get_window()) def _repos_item_clicked(self, widget): try: self.repos_dialog.show() except Exception as e: handle_gui_exception( e, _("Error in repos dialog. " "Please see /var/log/rhsm/rhsm.log for more information."), self._get_window()) def _on_unregister_prompt_response(self, dialog, response): if not response: log.debug("unregister prompt not confirmed. cancelling") return log.info("Proceeding with un-registration: %s", self.identity.uuid) self._perform_unregister() def _perform_unregister(self): try: reset_resolver() unregister.UnregisterService( self.backend.cp_provider.get_consumer_auth_cp()).unregister() except Exception as e: log.error("Error unregistering system with entitlement platform.") handle_gui_exception( e, _("<b>Errors were encountered during unregister.</b>") + "\n%s\n" + _("Please see /var/log/rhsm/rhsm.log for more information."), self.main_window, log_msg="Consumer may need to be manually cleaned up: %s" % self.identity.uuid) # managerlib.unregister removes product and entitlement directories self.backend.product_dir.__init__() self.backend.entitlement_dir.__init__() # We have new credentials, restart virt-who restart_virt_who() self.backend.cs.force_cert_check() def _unregister_item_clicked(self, widget): log.info("Unregister button pressed, asking for confirmation.") prompt = messageWindow.YesNoDialog( _("<b>Are you sure you want to unregister?</b>"), self._get_window()) prompt.connect('response', self._on_unregister_prompt_response) def _proxy_config_item_clicked(self, widget): self.network_config_dialog.set_parent_window(self._get_window()) self.network_config_dialog.show() def _facts_item_clicked(self, widget): self.system_facts_dialog.set_parent_window(self._get_window()) self.system_facts_dialog.show() def _import_cert_item_clicked(self, widget): self.import_sub_dialog.set_parent_window(self._get_window()) self.import_sub_dialog.show() def _update_certificates_button_clicked(self, widget): autobind_wizard = registergui.AutobindWizardDialog(self.backend) autobind_wizard.register_dialog.connect('destroy', self._on_dialog_destroy, widget) autobind_wizard.window.set_transient_for(self._get_window()) if autobind_wizard and widget: widget.set_sensitive(False) autobind_wizard.initialize() autobind_wizard.show() def _redeem_item_clicked(self, widget): self.redeem_dialog.set_parent_window(self._get_window()) self.redeem_dialog.show() def _getting_started_item_clicked(self, widget): try: # try to open documentation in yelp ga_Gtk.show_uri(None, 'ghelp:subscription-manager', time.time()) except Exception as e: # if we can't open it, it's probably because the user didn't # install the docs, or yelp. no need to bother them. log.warn("Unable to open help documentation: %s", e) def _about_item_clicked(self, widget): about = AboutDialog(self._get_window(), self.backend) about.show() def _online_docs_item_clicked(self, widget): browser = None for possible_browser in PREFERRED_BROWSERS: try: browser = webbrowser.get(possible_browser) break except webbrowser.Error: pass if browser is None: utils.show_error_window(NO_BROWSER_MESSAGE % (self._get_online_doc_url())) else: webbrowser.open_new(self._get_online_doc_url()) def _quit_item_clicked(self): self.hide() def _config_changed(self, widget): # update the backend's UEP in case we changed proxy # config. We specify all these settings since they # are new and the default UEP init won't get them # (it's default args are set at class init time) self.backend.update() def _check_rhn_classic(self): if ClassicCheck().is_registered_with_classic(): prompt = messageWindow.ContinueDialog( linkify(get_branding().REGISTERED_TO_OTHER_WARNING), self.main_window, _("System Already Registered")) prompt.connect('response', self._on_rhn_classic_response) def _on_rhn_classic_response(self, dialog, response): if not response: self.main_window.hide() def _get_online_doc_url(self): lang, encoding = locale.getdefaultlocale() if lang is not None: url = ONLINE_DOC_URL_TEMPLATE % (lang.replace("_", "-")) else: url = ONLINE_DOC_FALLBACK_URL try: urllib.request.urlopen(url) except urllib.error.URLError: # Use the default if there is no translation. url = ONLINE_DOC_FALLBACK_URL return url def _handle_facts_updated(self): # see bz 1323271 - update compliance on update of facts self.backend.cs.load() self.backend.cs.notify()
def __init__(self, backend, consumer, facts=None, callbacks=None): """ Callbacks will be executed when registration status changes. """ self.backend = backend self.consumer = consumer self.facts = facts self.callbacks = callbacks self. async = AsyncBackend(self.backend) dic = { "on_register_cancel_button_clicked": self.cancel, "on_register_button_clicked": self.on_register_button_clicked, "on_proxy_config_button_clicked": self._on_proxy_config_button_clicked, "on_import_certs_button_clicked": self._on_import_certs_button_clicked, "on_rhn_radio_toggled": self._server_radio_toggled, "on_local_radio_toggled": self._server_radio_toggled, "on_offline_radio_toggled": self._server_radio_toggled, } registration_xml.signal_autoconnect(dic) self.registerWin = registration_xml.get_widget("register_dialog") self.registerWin.connect("hide", self.cancel) self.registerWin.connect("delete_event", self.delete_event) self.initializeConsumerName() self.uname = registration_xml.get_widget("account_login") self.passwd = registration_xml.get_widget("account_password") self.consumer_name = registration_xml.get_widget("consumer_name") self.skip_auto_bind = registration_xml.get_widget("skip_auto_bind") self.register_notebook = \ registration_xml.get_widget("register_notebook") self.register_progressbar = \ registration_xml.get_widget("register_progressbar") self.register_details_label = \ registration_xml.get_widget("register_details_label") self.owner_treeview = registration_xml.get_widget("owner_treeview") renderer = gtk.CellRendererText() column = gtk.TreeViewColumn(_("Organization"), renderer, text=1) self.owner_treeview.set_property("headers-visible", False) self.owner_treeview.append_column(column) self.environment_treeview = registration_xml.get_widget( "environment_treeview") renderer = gtk.CellRendererText() column = gtk.TreeViewColumn(_("Environment"), renderer, text=1) self.environment_treeview.set_property("headers-visible", False) self.environment_treeview.append_column(column) self.cancel_button = registration_xml.get_widget("cancel_button") self.register_button = registration_xml.get_widget("register_button") register_tip_label = registration_xml.get_widget("registrationTip") register_tip_label.set_label("<small>%s</small>" % \ get_branding().GUI_FORGOT_LOGIN_TIP) register_header_label = \ registration_xml.get_widget("registrationHeader") register_header_label.set_label("<b>%s</b>" % \ get_branding().GUI_REGISTRATION_HEADER) self.rhn_radio = registration_xml.get_widget("rhn_radio") self.local_radio = registration_xml.get_widget("local_radio") self.offline_radio = registration_xml.get_widget("offline_radio") self.local_entry = registration_xml.get_widget("local_entry") self.import_certs_button = registration_xml.get_widget( "import_certs_button") self.proxy_label = registration_xml.get_widget("proxy_label") self.proxy_config_button = registration_xml.get_widget( "proxy_config_button") self.network_config_dialog = networkConfig.NetworkConfigDialog() self.import_certs_dialog = ImportSubDialog()
class RegisterScreen: """ Registration Widget Screen """ def __init__(self, backend, consumer, facts=None, callbacks=None): """ Callbacks will be executed when registration status changes. """ self.backend = backend self.consumer = consumer self.facts = facts self.callbacks = callbacks self. async = AsyncBackend(self.backend) dic = { "on_register_cancel_button_clicked": self.cancel, "on_register_button_clicked": self.on_register_button_clicked, "on_proxy_config_button_clicked": self._on_proxy_config_button_clicked, "on_import_certs_button_clicked": self._on_import_certs_button_clicked, "on_rhn_radio_toggled": self._server_radio_toggled, "on_local_radio_toggled": self._server_radio_toggled, "on_offline_radio_toggled": self._server_radio_toggled, } registration_xml.signal_autoconnect(dic) self.registerWin = registration_xml.get_widget("register_dialog") self.registerWin.connect("hide", self.cancel) self.registerWin.connect("delete_event", self.delete_event) self.initializeConsumerName() self.uname = registration_xml.get_widget("account_login") self.passwd = registration_xml.get_widget("account_password") self.consumer_name = registration_xml.get_widget("consumer_name") self.skip_auto_bind = registration_xml.get_widget("skip_auto_bind") self.register_notebook = \ registration_xml.get_widget("register_notebook") self.register_progressbar = \ registration_xml.get_widget("register_progressbar") self.register_details_label = \ registration_xml.get_widget("register_details_label") self.owner_treeview = registration_xml.get_widget("owner_treeview") renderer = gtk.CellRendererText() column = gtk.TreeViewColumn(_("Organization"), renderer, text=1) self.owner_treeview.set_property("headers-visible", False) self.owner_treeview.append_column(column) self.environment_treeview = registration_xml.get_widget( "environment_treeview") renderer = gtk.CellRendererText() column = gtk.TreeViewColumn(_("Environment"), renderer, text=1) self.environment_treeview.set_property("headers-visible", False) self.environment_treeview.append_column(column) self.cancel_button = registration_xml.get_widget("cancel_button") self.register_button = registration_xml.get_widget("register_button") register_tip_label = registration_xml.get_widget("registrationTip") register_tip_label.set_label("<small>%s</small>" % \ get_branding().GUI_FORGOT_LOGIN_TIP) register_header_label = \ registration_xml.get_widget("registrationHeader") register_header_label.set_label("<b>%s</b>" % \ get_branding().GUI_REGISTRATION_HEADER) self.rhn_radio = registration_xml.get_widget("rhn_radio") self.local_radio = registration_xml.get_widget("local_radio") self.offline_radio = registration_xml.get_widget("offline_radio") self.local_entry = registration_xml.get_widget("local_entry") self.import_certs_button = registration_xml.get_widget( "import_certs_button") self.proxy_label = registration_xml.get_widget("proxy_label") self.proxy_config_button = registration_xml.get_widget( "proxy_config_button") self.network_config_dialog = networkConfig.NetworkConfigDialog() self.import_certs_dialog = ImportSubDialog() def show(self): # Ensure that we start on the first page and that # all widgets are cleared. self._show_choose_server_page() self._clear_registration_widgets() self.registerWin.present() def _show_choose_server_page(self): # Override the button text to clarify we're not actually registering # by pressing that button here. self.register_button.set_label(_("Next")) self.register_notebook.set_page(CHOOSE_SERVER_PAGE) def _show_credentials_page(self): # Set the button text back after we changed it when showing the # choose server screen. self.register_button.set_label(_("Register")) self.register_notebook.set_page(CREDENTIALS_PAGE) def delete_event(self, event, data=None): return self.close_window() def cancel(self, button): self.close_window() def initializeConsumerName(self): consumername = registration_xml.get_widget("consumer_name") if not consumername.get_text(): consumername.set_text(socket.gethostname()) # callback needs the extra arg, so just a wrapper here def on_register_button_clicked(self, button): self.register() def _on_proxy_config_button_clicked(self, button): self.network_config_dialog.set_parent_window(self.registerWin) self.network_config_dialog.show() def _on_import_certs_button_clicked(self, button): self.import_certs_dialog.set_parent_window(self.registerWin) self.import_certs_dialog.show() def register(self, testing=None): if self.register_notebook.get_current_page() == CHOOSE_SERVER_PAGE: self._server_selected() return True if self.register_notebook.get_current_page() == OWNER_SELECT_PAGE: # we're on the owner select page self._owner_selected() return True elif self.register_notebook.get_current_page( ) == ENVIRONMENT_SELECT_PAGE: self._environment_selected() return True username = self.uname.get_text().strip() password = self.passwd.get_text().strip() consumername = self.consumer_name.get_text() if not self.validate_consumername(consumername): return False if not self.validate_account(): return False # for firstboot -t if testing: return True self.backend.create_admin_uep(username=username, password=password) self. async .get_owner_list(username, self._on_get_owner_list_cb) self.timer = gobject.timeout_add(100, self._timeout_callback) self.register_notebook.set_page(PROGRESS_PAGE) self._set_register_details_label( _("Fetching list of possible organizations")) self.cancel_button.set_sensitive(False) self.register_button.set_sensitive(False) return True def _timeout_callback(self): self.register_progressbar.pulse() # return true to keep it pulsing return True def _on_get_owner_list_cb(self, owners, error=None): if error != None: handle_gui_exception(error, REGISTER_ERROR, self.registerWin) self._finish_registration(failed=True) return owners = [(owner['key'], owner['displayName']) for owner in owners] if len(owners) == 0: handle_gui_exception(None, _("<b>User %s is not able to register with any orgs.</b>") \ % (self.uname.get_text().strip()), self.registerWin) self._finish_registration(failed=True) return if len(owners) == 1: self.owner_key = owners[0][0] self. async .get_environment_list(self.owner_key, self._on_get_environment_list_cb) else: owner_model = gtk.ListStore(str, str) for owner in owners: owner_model.append(owner) self.owner_treeview.set_model(owner_model) self.owner_treeview.get_selection().select_iter( owner_model.get_iter_first()) self.cancel_button.set_sensitive(True) self.register_button.set_sensitive(True) self.register_notebook.set_page(OWNER_SELECT_PAGE) def _on_get_environment_list_cb(self, result_tuple, error=None): environments = result_tuple if error != None: handle_gui_exception(error, REGISTER_ERROR, self.registerWin) self._finish_registration(failed=True) return if not environments: self._run_register_step(self.owner_key, None) return envs = [(env['id'], env['name']) for env in environments] if len(envs) == 1: self._run_register_step(self.owner_key, envs[0][0]) else: environment_model = gtk.ListStore(str, str) for env in envs: environment_model.append(env) self.environment_treeview.set_model(environment_model) self.environment_treeview.get_selection().select_iter( environment_model.get_iter_first()) self.cancel_button.set_sensitive(True) self.register_button.set_sensitive(True) self.register_notebook.set_page(ENVIRONMENT_SELECT_PAGE) # Callback used by the owner selection screen: def _owner_selected(self): self.cancel_button.set_sensitive(False) self.register_button.set_sensitive(False) self.register_notebook.set_page(PROGRESS_PAGE) model, tree_iter = self.owner_treeview.get_selection().get_selected() self.owner_key = model.get_value(tree_iter, 0) self. async .get_environment_list(self.owner_key, self._on_get_environment_list_cb) def _server_radio_toggled(self, widget): self.local_entry.set_sensitive(self.local_radio.get_active()) def _server_selected(self): if self.rhn_radio.get_active(): CFG.set('server', 'hostname', config.DEFAULT_HOSTNAME) CFG.set('server', 'port', config.DEFAULT_PORT) CFG.set('server', 'prefix', config.DEFAULT_PREFIX) elif self.offline_radio.get_active(): # We'll signal the user set offline by setting an empty hostname: CFG.set('server', 'hostname', '') CFG.set('server', 'port', config.DEFAULT_PORT) CFG.set('server', 'prefix', config.DEFAULT_PREFIX) elif self.local_radio.get_active(): local_server = self.local_entry.get_text() try: (hostname, port, prefix) = parse_server_info(local_server) CFG.set('server', 'hostname', hostname) CFG.set('server', 'port', port) CFG.set('server', 'prefix', prefix) try: if not is_valid_server_info(hostname, port, prefix): errorWindow( _("Unable to reach the server at %s:%s%s" % (hostname, port, prefix))) return except MissingCaCertException: errorWindow( _("CA certificate for subscription service has not been installed." )) return except ServerUrlParseError: errorWindow( _("Please provide a hostname with optional port and/or prefix: hostname[:port][/prefix]" ), self.registerWin) return log.info("Writing server data to rhsm.conf") CFG.save() self.backend.update() if self.offline_radio.get_active(): # Because the user selected offline, the whole registration process # must end here. self._offline_selected() else: self._show_credentials_page() def _offline_selected(self): self.close_window() def _environment_selected(self): self.cancel_button.set_sensitive(False) self.register_button.set_sensitive(False) self.register_notebook.set_page(PROGRESS_PAGE) model, tree_iter = self.environment_treeview.get_selection( ).get_selected() env = model.get_value(tree_iter, 0) self._run_register_step(self.owner_key, env) def _run_register_step(self, owner, env): log.info("Registering to owner: %s environment: %s" % (owner, env)) self. async .register_consumer(self.consumer_name.get_text(), self.facts, owner, env, self._on_registration_finished_cb) self._set_register_details_label(_("Registering your system")) def _on_registration_finished_cb(self, new_account, error=None): try: if error != None: raise error managerlib.persist_consumer_cert(new_account) self.consumer.reload() self._finish_registration() except Exception, e: handle_gui_exception(e, REGISTER_ERROR, self.registerWin) self._finish_registration(failed=True)
def __init__(self, backend=None, ent_dir=None, prod_dir=None, auto_launch_registration=False): super(MainWindow, self).__init__() rhsm_cfg = config.initConfig() proxy_server = rhsm_cfg.get("server", "proxy_hostname") proxy_port = int( rhsm_cfg.get("server", "proxy_port") or config.DEFAULT_PROXY_PORT) def show_proxy_error_dialog(proxy_auth_required=False): """ When proxy server is set in configuration and it is not possible to connect to proxy server, then open dialog for setting proxy server. """ if proxy_auth_required: proxy_user = rhsm_cfg.get("server", "proxy_user") proxy_password = rhsm_cfg.get("server", "proxy_password") if proxy_user or proxy_password: err_msg = _( "Wrong proxy username or password, please check your settings." ) else: err_msg = _( "Proxy authentication required, please check your settings." ) else: err_msg = _( "Proxy connection failed, please check your settings.") print_error(err_msg) error_dialog = messageWindow.ContinueDialog( err_msg, self._get_window()) error_dialog.connect("response", self._on_proxy_error_dialog_response) self.network_config_dialog = networkConfig.NetworkConfigDialog() # Sub-man gui will be terminated after saving settings and it is # necessary to start it once again. self.network_config_dialog.saveButton.connect( "clicked", self._exit) self.network_config_dialog.cancelButton.connect( "clicked", self._exit) self.backend = backend or Backend() cp = self.backend.cp_provider.get_consumer_auth_cp() if proxy_server: if not utils.test_proxy_reachability(proxy_server, proxy_port): show_proxy_error_dialog() return try: # Try to send to the simplest Rest API call to Candlepin server. # This result will be used for getting version of Candlepin server. # See self.log_server_version. cp.supports_resource("status") except socket.error as err: # See https://tools.ietf.org/html/rfc7235#section-4.3 if "407 Proxy Authentication Required" in err.message: show_proxy_error_dialog(proxy_auth_required=True) return self.identity = require(IDENTITY) log.debug("Client Versions: %s " % get_client_versions()) ga_GLib.idle_add(self.log_server_version, cp) settings = self.main_window.get_settings() # prevent gtk from trying to save a list of recently used files, which # as root, causes gtk warning: # "Attempting to set the permissions of `/root/.local/share/recently-used.xbel' # The __name__ use is just for the 'origin' value gtk uses to store # where a Gtk.Settings value was set. settings.set_long_property('gtk-recent-files-max-age', 0, "%s:%s" % (__name__, type(self).__name__)) ga_Gtk.Window.set_default_icon_name("subscription-manager") self.product_dir = prod_dir or self.backend.product_dir self.entitlement_dir = ent_dir or self.backend.entitlement_dir self.system_facts_dialog = factsgui.SystemFactsDialog( update_callback=self._handle_facts_updated) self.preferences_dialog = PreferencesDialog(self.backend, self._get_window()) self.repos_dialog = RepositoriesDialog(self.backend, self._get_window()) self.import_sub_dialog = ImportSubDialog() self.network_config_dialog = networkConfig.NetworkConfigDialog() self.network_config_dialog.saveButton.connect("clicked", self._config_changed) self.redeem_dialog = redeem.RedeemDialog(self.backend) self.installed_tab_icon = ga_Gtk.Image() self.installed_tab_icon.set_from_stock(ga_Gtk.STOCK_YES, ga_Gtk.IconSize.MENU) self.installed_tab = InstalledProductsTab(self.backend, self.installed_tab_icon, self, ent_dir=self.entitlement_dir, prod_dir=self.product_dir) self.my_subs_tab = MySubscriptionsTab(self.backend, self.main_window, ent_dir=self.entitlement_dir, prod_dir=self.product_dir) self.all_subs_tab = AllSubscriptionsTab(self.backend, self.main_window) hbox = ga_Gtk.HBox(spacing=6) hbox.pack_start(self.installed_tab_icon, False, False, 0) hbox.pack_start(ga_Gtk.Label(self.installed_tab.get_label()), False, False, 0) self.notebook.append_page(self.installed_tab.get_content(), hbox) hbox.show_all() self.notebook.append_page(self.my_subs_tab.get_content(), ga_Gtk.Label(self.my_subs_tab.get_label())) self.connect_signals({ "on_register_menu_item_activate": self._register_item_clicked, "on_unregister_menu_item_activate": self._unregister_item_clicked, "on_import_cert_menu_item_activate": self._import_cert_item_clicked, "on_view_facts_menu_item_activate": self._facts_item_clicked, "on_proxy_config_menu_item_activate": self._proxy_config_item_clicked, "on_redeem_menu_item_activate": self._redeem_item_clicked, "on_preferences_menu_item_activate": self._preferences_item_clicked, "on_repos_menu_item_activate": self._repos_item_clicked, "on_about_menu_item_activate": self._about_item_clicked, "on_getting_started_menu_item_activate": self._getting_started_item_clicked, "on_online_docs_menu_item_activate": self._online_docs_item_clicked, "on_quit_menu_item_activate": ga_Gtk.main_quit, }) # various state tracking for async operations self._show_overrides = False self._can_redeem = False self.backend.cs.add_callback(self.on_cert_sorter_cert_change) self.main_window.show_all() # Check to see if already registered to old RHN/Spacewalk # and show dialog if so self._check_rhn_classic() # Update everything with compliance data self.backend.cs.notify() # managergui needs cert_sort.cert_monitor.run_check() to run # on a timer to detect cert changes from outside the gui # (via rhsmdd for example, or manually provisioned). cert_monitor_thread = threading.Thread(target=self._cert_check_timer, name="CertMonitorThread") cert_monitor_thread.daemon = True cert_monitor_thread.start() if auto_launch_registration and not self.registered(): self._register_item_clicked(None) enabled_yum_plugins = YumPluginManager.enable_pkg_plugins() if len(enabled_yum_plugins) > 0: messageWindow.InfoDialog( YumPluginManager.warning_message(enabled_yum_plugins), self._get_window(), _("Warning - subscription-manager plugins were automatically enabled" ))
def __init__(self, backend=None, consumer=None, facts=None, ent_dir=None, prod_dir=None, auto_launch_registration=False): super(MainWindow, self).__init__('mainwindow.glade') self.backend = backend or Backend() self.consumer = consumer or Consumer() self.facts = facts or Facts(self.backend.entitlement_dir, self.backend.product_dir) log.debug("Client Versions: %s " % get_client_versions()) log.debug("Server Versions: %s " % get_server_versions(self.backend.uep)) self.product_dir = prod_dir or self.backend.product_dir self.entitlement_dir = ent_dir or self.backend.entitlement_dir self.system_facts_dialog = factsgui.SystemFactsDialog( self.backend, self.consumer, self.facts) self.registration_dialog = registergui.RegisterScreen( self.backend, self.consumer, self.facts, callbacks=[self.registration_changed]) self.preferences_dialog = PreferencesDialog(self.backend, self.consumer, self._get_window()) self.import_sub_dialog = ImportSubDialog() self.network_config_dialog = networkConfig.NetworkConfigDialog() self.network_config_dialog.xml.get_widget("closeButton").connect( "clicked", self._config_changed) self.redeem_dialog = redeem.RedeemDialog(self.backend, self.consumer) self.installed_tab_icon = gtk.Image() self.installed_tab_icon.set_from_stock(gtk.STOCK_YES, gtk.ICON_SIZE_MENU) self.installed_tab = InstalledProductsTab(self.backend, self.consumer, self.facts, self.installed_tab_icon, self, ent_dir=self.entitlement_dir, prod_dir=self.product_dir) self.my_subs_tab = MySubscriptionsTab(self.backend, self.consumer, self.facts, self.main_window, ent_dir=self.entitlement_dir, prod_dir=self.product_dir) self.all_subs_tab = AllSubscriptionsTab(self.backend, self.consumer, self.facts, self.main_window) hbox = gtk.HBox(spacing=6) hbox.pack_start(self.installed_tab_icon, False, False) hbox.pack_start(gtk.Label(self.installed_tab.get_label()), False, False) self.notebook.append_page(self.installed_tab.get_content(), hbox) hbox.show_all() self.notebook.append_page(self.my_subs_tab.get_content(), gtk.Label(self.my_subs_tab.get_label())) self.glade.signal_autoconnect({ "on_register_menu_item_activate": self._register_item_clicked, "on_unregister_menu_item_activate": self._unregister_item_clicked, "on_import_cert_menu_item_activate": self._import_cert_item_clicked, "on_view_facts_menu_item_activate": self._facts_item_clicked, "on_proxy_config_menu_item_activate": self._proxy_config_item_clicked, "on_redeem_menu_item_activate": self._redeem_item_clicked, "on_preferences_menu_item_activate": self._preferences_item_clicked, "on_about_menu_item_activate": self._about_item_clicked, "on_getting_started_menu_item_activate": self._getting_started_item_clicked, "on_online_docs_menu_item_activate": self._online_docs_item_clicked, "on_quit_menu_item_activate": gtk.main_quit, }) def on_identity_change(filemonitor): self.consumer.reload() self.refresh() self.backend.monitor_identity(on_identity_change) self.main_window.show_all() self.refresh() # Check to see if already registered to old RHN/Spacewalk # and show dialog if so self._check_rhn_classic() if auto_launch_registration and not self.registered(): self._register_item_clicked(None)