示例#1
0
    def __init__(self,
                 table_widget,
                 yes_id=gtk.STOCK_APPLY,
                 no_id=gtk.STOCK_REMOVE):
        """
        Create a new products table, populating the gtk.TreeView.

        yes_id and no_id are GTK constants that specify the icon to
        use for representing if a product is installed.
        """

        self.table_widget = table_widget
        self.product_store = gtk.ListStore(str, gtk.gdk.Pixbuf)
        table_widget.set_model(self.product_store)

        self.yes_icon = self._render_icon(yes_id)
        self.no_icon = self._render_icon(no_id)
        self.product_dir = ProductDirectory()

        name_column = gtk.TreeViewColumn(_("Product"),
                                         gtk.CellRendererText(),
                                         markup=0)
        name_column.set_expand(True)
        installed_column = gtk.TreeViewColumn(_("Installed"),
                                              gtk.CellRendererPixbuf(),
                                              pixbuf=1)

        table_widget.append_column(name_column)
        table_widget.append_column(installed_column)
示例#2
0
 def test_get_installed_products(self, MockExists):
     MockExists.return_value = True
     pd = ProductDirectory()
     top_product = StubProduct("top")
     provided_products = [StubProduct("provided")]
     pd.list = lambda: [StubProductCertificate(top_product, provided_products)]
     installed_products = pd.get_installed_products()
     self.assertTrue("top" in installed_products)
示例#3
0
    def __init__(self, product_dir=None):

        if not product_dir:
            product_dir = ProductDirectory()

        self.installed = {}
        for prod_cert in product_dir.list():
            prod = prod_cert.getProduct()
            self.installed[prod.getHash()] = prod.getName()
示例#4
0
    def __init__(self, product_dir=None):

        if not product_dir:
            product_dir = ProductDirectory()

        self.installed = {}
        for prod_cert in product_dir.list():
            prod = prod_cert.products[0]
            self.installed[prod.id] = prod.name
示例#5
0
    def __init__(self,
                 lock=ActionLock(),
                 uep=None,
                 facts_dict=None,
                 product_dir=None):
        self.facts_dict = facts_dict
        DataLib.__init__(self, lock, uep)

        self._product_dir = product_dir or ProductDirectory()
示例#6
0
 def test_default_products_matching_ids(self, MockExists):
     MockExists.return_value = True
     pd = ProductDirectory()
     top_product = StubProduct("top")
     default_product = StubProduct("top")
     pd.installed_prod_dir.list = lambda: [StubProductCertificate(top_product, [])]
     pd.default_prod_dir.list = lambda: [StubProductCertificate(default_product, [])]
     results = pd.list()
     self.assertEquals(1, len(results))
     resulting_ids = [cert.products[0].id for cert in results]
     self.assertTrue("top" in resulting_ids)
示例#7
0
    def __init__(self):
        self.create_uep(cert_file=ConsumerIdentity.certpath(),
                        key_file=ConsumerIdentity.keypath())

        self.create_content_connection()
        # we don't know the user/pass yet, so no point in
        # creating an admin uep till we need it
        self.admin_uep = None

        self.product_dir = ProductDirectory()
        self.entitlement_dir = EntitlementDirectory()
        self.certlib = CertLib(uep=self.uep)

        self.product_monitor = file_monitor.Monitor(self.product_dir.path)
        self.entitlement_monitor = file_monitor.Monitor(
            self.entitlement_dir.path)
        self.identity_monitor = file_monitor.Monitor(ConsumerIdentity.PATH)
示例#8
0
    def __init__(self):
        self.create_uep(cert_file=ConsumerIdentity.certpath(),
                        key_file=ConsumerIdentity.keypath())

        self.create_content_connection()
        # we don't know the user/pass yet, so no point in
        # creating an admin uep till we need it
        self.admin_uep = None

        self.product_dir = ProductDirectory()
        self.entitlement_dir = EntitlementDirectory()
        self.certlib = CertLib(uep=self.uep)

        self.product_monitor = file_monitor.Monitor(self.product_dir.path)
        self.entitlement_monitor = file_monitor.Monitor(
            self.entitlement_dir.path)
        self.identity_monitor = file_monitor.Monitor(ConsumerIdentity.PATH)

        # connect handlers to refresh the cached data when we notice a change.
        # do this before any other handlers might connect
        self.product_monitor.connect(
            "changed", lambda monitor: self.product_dir.refresh())
        self.entitlement_monitor.connect(
            "changed", lambda monitor: self.entitlement_dir.refresh())
    def __init__(self,
                 backend,
                 consumer,
                 facts,
                 tab_icon,
                 parent,
                 ent_dir=None,
                 prod_dir=None):

        widgets = [
            'product_text', 'product_id_text', 'validity_text',
            'subscription_text', 'subscription_status_label',
            'update_certificates_button', 'register_button'
        ]
        super(InstalledProductsTab, self).__init__('installed.glade', widgets)

        self.tab_icon = tab_icon

        self.product_dir = prod_dir or ProductDirectory()
        self.entitlement_dir = ent_dir or EntitlementDirectory()

        self.facts = facts
        self.cs = cert_sorter.CertSorter(prod_dir, ent_dir,
                                         self.facts.get_facts())

        # Product column
        text_renderer = gtk.CellRendererText()
        image_renderer = gtk.CellRendererPixbuf()
        column = gtk.TreeViewColumn(_('Product'),
                                    image_renderer,
                                    pixbuf=self.store['image'])

        column.set_expand(True)
        column.pack_end(text_renderer, True)
        column.add_attribute(text_renderer, 'text', self.store['product'])
        column.add_attribute(text_renderer, 'cell-background',
                             self.store['background'])
        self.top_view.append_column(column)
        cols = []
        cols.append((column, 'text', 'product'))

        column = self.add_text_column(_('Version'), 'version')
        cols.append((column, 'text', 'version'))

        column = self.add_text_column(_('Arch'), 'arch')
        column.set_alignment(0.5)
        cols.append((column, 'text', 'arch'))

        column = self.add_text_column(_('Status'), 'status')
        cols.append((column, 'text', 'status'))

        column = self.add_date_column(_('Start Date'), 'start_date')
        cols.append((column, 'date', 'start_date'))

        column = self.add_date_column(_('End Date'), 'expiration_date')
        cols.append((column, 'date', 'expiration_date'))

        self.set_sorts(cols)

        self.glade.signal_autoconnect({
            "on_update_certificates_button_clicked":
            parent._update_certificates_button_clicked,
        })
        self.glade.signal_autoconnect({
            "on_register_button_clicked":
            parent._register_item_clicked,
        })

        self.update_products()

        # Monitor entitlements/products for additions/deletions
        def on_cert_change(filemonitor):
            self.update_products()
            self._set_validity_status()

        backend.monitor_certs(on_cert_change)
示例#10
0
 def __init__(self):
     self.pdir = ProductDirectory()
     self.db = ProductDatabase()
     self.db.read()
     self.meta_data_errors = []
示例#11
0
def find_first_invalid_date(ent_dir=None, product_dir=None, facts_dict=None):
    """
    Find the first date when the system is invalid at midnight
    GMT.

    WARNING: This method does *not* return the exact first datetime when
    we're invalid. Due to it's uses in the GUI it needs to
    return a datetime into the first day of being completely invalid, so
    the subscription assistant can search for that time and find expired
    products.

    If there are no products installed, return None, as there technically
    is no first invalid date.
    """
    if not ent_dir:
        ent_dir = EntitlementDirectory()
    if not product_dir:
        product_dir = ProductDirectory()
    if facts_dict is None:
        facts_dict = Facts().get_facts()

    current_date = datetime.now(GMT())

    if not product_dir.list():
        # If there are no products installed, return None, there is no
        # invalid date:
        log.debug("Unable to determine first invalid date, no products "
                  "installed.")
        return None

    # change _scan_entitlement_certs to take product lists,
    # run it for the future to figure this out
    # First check if we have anything installed but not entitled *today*:
    cs = cert_sorter.CertSorter(product_dir,
                                ent_dir,
                                facts_dict,
                                on_date=current_date)
    if not cs.is_valid():
        log.debug("Found unentitled products or partial stacks.")
        return current_date

    # Sort all the ent certs by end date. (ascending)
    all_ent_certs = ent_dir.list()

    def get_date(ent_cert):
        return ent_cert.validRange().end()

    all_ent_certs.sort(key=get_date)

    # Loop through all current and future entitlement certs, check validity
    # status on their end date, and return the first date where we're not
    # valid.
    for ent_cert in all_ent_certs:
        # Adding a timedelta of one day here so we can be sure we get a date
        # the subscription assitant (which does not use time) can use to search
        # for.
        end_date = ent_cert.validRange().end() + timedelta(days=1)
        if end_date < current_date:
            # This cert is expired, ignore it:
            continue
        log.debug("Checking cert: %s, end date: %s" %
                  (ent_cert.serialNumber(), end_date))

        # new cert_sort stuff, use _scan_for_entitled_products, since
        # we just need to know if stuff is expired
        cs = cert_sorter.CertSorter(product_dir,
                                    ent_dir,
                                    facts_dict,
                                    on_date=end_date)
        if not cs.is_valid():
            log.debug("Found non-valid status on %s" % end_date)
            return end_date
        else:
            log.debug("Valid status on %s" % end_date)

    # Should never hit this:
    raise Exception("Unable to determine first invalid date.")
示例#12
0
    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', [
            'main_window', 'notebook', 'system_name_label',
            'next_update_label', 'next_update_title', 'register_menu_item',
            'unregister_menu_item', 'redeem_menu_item'
        ])

        self.backend = backend or Backend()
        self.consumer = consumer or Consumer()
        self.facts = facts or Facts()

        log.debug("Versions: %s " % get_version_dict(self.backend.uep))

        self.product_dir = prod_dir or ProductDirectory()
        self.entitlement_dir = ent_dir or EntitlementDirectory()

        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.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)
示例#13
0
    def __init__(self,
                 backend,
                 consumer,
                 facts,
                 parent_win,
                 ent_dir=None,
                 prod_dir=None):
        """
        Create a new 'My Subscriptions' tab.
        """
        super(MySubscriptionsTab,
              self).__init__('mysubs.glade',
                             ['details_box', 'unsubscribe_button'])
        self.backend = backend
        self.consumer = consumer
        self.facts = facts
        self.parent_win = parent_win
        self.entitlement_dir = ent_dir or EntitlementDirectory()
        self.product_dir = prod_dir or ProductDirectory()

        self.sub_details = widgets.SubDetailsWidget()

        # Put the details widget in the middle
        details = self.sub_details.get_widget()
        self.details_box.pack_start(details)

        # Set up columns on the view
        column = self.add_text_column(_("Subscription"), 'subscription', True)
        cols = []
        cols.append((column, 'text', 'subscription'))

        progress_renderer = gtk.CellRendererProgress()
        products_column = gtk.TreeViewColumn(
            _("Installed Products"),
            progress_renderer,
            value=self.store['installed_value'],
            text=self.store['installed_text'])
        self.empty_progress_renderer = gtk.CellRendererText()
        products_column.pack_end(self.empty_progress_renderer, True)
        products_column.set_cell_data_func(progress_renderer,
                                           self._update_progress_renderer)
        self.top_view.append_column(products_column)

        column = self.add_date_column(_("End Date"), 'expiration_date')
        cols.append((column, 'date', 'expiration_date'))

        # Disable row striping on the tree view as we are overriding the behavior
        # to display stacking groups as one color.
        self.top_view.set_rules_hint(False)

        column = self.add_text_column(_("Quantity"), 'quantity')
        cols.append((column, 'text', 'quantity'))

        self.set_sorts(cols)

        self.top_view.connect(
            "row_activated", widgets.expand_collapse_on_row_activated_callback)

        self.update_subscriptions()

        self.glade.signal_autoconnect(
            {'on_unsubscribe_button_clicked': self.unsubscribe_button_clicked})

        # Monitor entitlements/products for additions/deletions
        def on_cert_change(filemonitor):
            self.update_subscriptions()

        self.backend.monitor_certs(on_cert_change)