示例#1
0
class ProductsTable(object):
    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)

    def clear(self):
        """
        Remove all products from the table.
        """
        self.product_store.clear()

    def add_product(self, product_name, product_id):
        """
        Add a product with the given name and id to the table.
        """
        self.product_store.append([product_name, self._get_icon(product_id)])

    def set_accessibility_name(self, accessibility_name):
        self.table_widget.get_accessible().set_name(accessibility_name)

    def _render_icon(self, icon_id):
        return self.table_widget.render_icon(icon_id, gtk.ICON_SIZE_MENU)

    def _get_icon(self, product_id):
        if self.product_dir.findByProduct(product_id):
            return self.yes_icon
        else:
            return self.no_icon
示例#2
0
class ProductsTable(object):

    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)

    def clear(self):
        """
        Remove all products from the table.
        """
        self.product_store.clear()

    def add_product(self, product_name, product_id):
        """
        Add a product with the given name and id to the table.
        """
        self.product_store.append([product_name, self._get_icon(product_id)])

    def set_accessibility_name(self, accessibility_name):
        self.table_widget.get_accessible().set_name(accessibility_name)

    def _render_icon(self, icon_id):
        return self.table_widget.render_icon(icon_id, gtk.ICON_SIZE_MENU)

    def _get_icon(self, product_id):
        if self.product_dir.findByProduct(product_id):
            return self.yes_icon
        else:
            return self.no_icon
class ProductManager:

    REPO = 'from_repo'
    PRODUCTID = 'productid'

    def __init__(self):
        self.pdir = ProductDirectory()
        self.db = ProductDatabase()
        self.db.read()
        self.meta_data_errors = []

    def update(self, yb):
        if yb is None:
            yb = yum.YumBase()
        enabled = self.getEnabled(yb)
        active = self.getActive(yb)

        #only execute this on versions of yum that track
        #which repo a package came from
        if yum.__version_info__[2] >= 28:
            # check that we have any repo's enabled
            # and that we have some enabled repo's. Not just
            # that we have packages from repo's that are
            # not active. See #806457
            if enabled and active:
                self.updateRemoved(active)
        self.updateInstalled(enabled, active)

    def _isWorkstation(self, product):
        if product.getName() == "Red Hat Enterprise Linux Workstation" and \
                "rhel-5-client-workstation" in product.getProvidedTags() and \
                product.getVersion()[0] == '5':
            return True
        return False

    def _isDesktop(self, product):
        if product.getName() == "Red Hat Enterprise Linux Desktop" and \
                "rhel-5-client" in product.getProvidedTags() and \
                product.getVersion()[0] == '5':
            return True
        return False

    def updateInstalled(self, enabled, active):
        for cert, repo in enabled:
            #nothing from this repo is installed
            if repo not in active:
                continue

            p = cert.getProduct()
            prod_hash = p.getHash()

            # Are we installing Workstation cert?
            if self._isWorkstation(p):
                # is the Desktop product cert installed?
                for pc in self.pdir.list():
                    if self._isDesktop(pc.getProduct()):
                        # Desktop product cert is installed,
                        # delete the Desktop product cert
                        pc.delete()
                        self.db.delete(prod_hash)
                        self.db.write()

            # no point installing desktop only to delete it
            if self._isDesktop(p):
                for pc in self.pdir.list():
                    if self._isWorkstation(pc.getProduct()):
                        # we are installing Desktop, but we already have workstation
                        return

            if self.pdir.findByProduct(prod_hash):
                continue

            fn = '%s.pem' % prod_hash
            path = self.pdir.abspath(fn)
            cert.write(path)
            self.db.add(prod_hash, repo)
            self.db.write()

    # We should only delete productcerts if there are no
    # packages from that repo installed (not "active")
    # and we have the product cert installed.
    def updateRemoved(self, active):
        for cert in self.pdir.list():
            p = cert.getProduct()
            prod_hash = p.getHash()
            repo = self.db.findRepo(prod_hash)

            # if we had errors with the repo or productid metadata
            # we could be very confused here, so do not
            # delete anything. see bz #736424
            if repo in self.meta_data_errors:
                log.info("%s has meta-data errors.  Not deleting product cert %s." % (repo, prod_hash))
                continue

            # FIXME: not entirely sure why we do this
            #  to avoid a none on cert.delete surely
            # but is there another reason?
            if repo is None:
                continue
            if repo in active:
                continue

            log.info("product cert %s for %s is being deleted" % (prod_hash, p.getName()))
            cert.delete()

            self.db.delete(prod_hash)
            self.db.write()

    # find the list of repo's that provide packages that
    # are actually installed.
    def getActive(self, yb):
        active = set()

        packages = yb.pkgSack.returnPackages()
        for p in packages:
            repo = p.repoid

            # if a pkg is in multiple repo's, this will consider
            # all the repo's with the pkg "active".
            db_pkg = yb.rpmdb.searchNevra(name=p.name, arch=p.arch)

            # that pkg is not actually installed
            if not db_pkg:
                continue

            # yum on 5.7 list everything as "installed" instead
            # of the repo it came from
            if repo in (None, "installed"):
                continue
            active.add(repo)
        return active

    def getEnabled(self, yb):
        lst = []
        enabled = yb.repos.listEnabled()

        for repo in enabled:
            try:
                fn = repo.retrieveMD(self.PRODUCTID)
                cert = self.__getCert(fn)
                if cert is None:
                    continue
                lst.append((cert, repo.id))
            except Exception, e:
                log.warn("Error loading productid metadata for %s." % repo)
                log.exception(e)
                self.meta_data_errors.append(repo.id)
        return lst
示例#4
0
class ProductManager:

    REPO = 'from_repo'
    PRODUCTID = 'productid'

    def __init__(self):
        self.pdir = ProductDirectory()
        self.db = ProductDatabase()
        self.db.read()
        self.meta_data_errors = []

    def update(self, yb):
        if yb is None:
            yb = yum.YumBase()
        enabled = self.getEnabled(yb)
        active = self.getActive(yb)

        #only execute this on versions of yum that track
        #which repo a package came from
        if yum.__version_info__[2] >= 28:
            # check that we have any repo's enabled
            # and that we have some enabled repo's. Not just
            # that we have packages from repo's that are
            # not active. See #806457
            if enabled and active:
                self.updateRemoved(active)
        self.updateInstalled(enabled, active)

    def _isWorkstation(self, product):
        if product.getName() == "Red Hat Enterprise Linux Workstation" and \
                "rhel-5-client-workstation" in product.getProvidedTags() and \
                product.getVersion()[0] == '5':
            return True
        return False

    def _isDesktop(self, product):
        if product.getName() == "Red Hat Enterprise Linux Desktop" and \
                "rhel-5-client" in product.getProvidedTags() and \
                product.getVersion()[0] == '5':
            return True
        return False

    def updateInstalled(self, enabled, active):
        for cert, repo in enabled:
            #nothing from this repo is installed
            if repo not in active:
                continue

            p = cert.getProduct()
            prod_hash = p.getHash()

            # Are we installing Workstation cert?
            if self._isWorkstation(p):
                # is the Desktop product cert installed?
                for pc in self.pdir.list():
                    if self._isDesktop(pc.getProduct()):
                        # Desktop product cert is installed,
                        # delete the Desktop product cert
                        pc.delete()
                        self.db.delete(prod_hash)
                        self.db.write()

            # no point installing desktop only to delete it
            if self._isDesktop(p):
                for pc in self.pdir.list():
                    if self._isWorkstation(pc.getProduct()):
                        # we are installing Desktop, but we already have workstation
                        return

            if self.pdir.findByProduct(prod_hash):
                continue

            fn = '%s.pem' % prod_hash
            path = self.pdir.abspath(fn)
            cert.write(path)
            self.db.add(prod_hash, repo)
            self.db.write()

    # We should only delete productcerts if there are no
    # packages from that repo installed (not "active")
    # and we have the product cert installed.
    def updateRemoved(self, active):
        for cert in self.pdir.list():
            p = cert.getProduct()
            prod_hash = p.getHash()
            repo = self.db.findRepo(prod_hash)

            # if we had errors with the repo or productid metadata
            # we could be very confused here, so do not
            # delete anything. see bz #736424
            if repo in self.meta_data_errors:
                log.info(
                    "%s has meta-data errors.  Not deleting product cert %s." %
                    (repo, prod_hash))
                continue

            # FIXME: not entirely sure why we do this
            #  to avoid a none on cert.delete surely
            # but is there another reason?
            if repo is None:
                continue
            if repo in active:
                continue

            log.info("product cert %s for %s is being deleted" %
                     (prod_hash, p.getName()))
            cert.delete()

            self.db.delete(prod_hash)
            self.db.write()

    # find the list of repo's that provide packages that
    # are actually installed.
    def getActive(self, yb):
        active = set()

        packages = yb.pkgSack.returnPackages()
        for p in packages:
            repo = p.repoid

            # if a pkg is in multiple repo's, this will consider
            # all the repo's with the pkg "active".
            db_pkg = yb.rpmdb.searchNevra(name=p.name, arch=p.arch)

            # that pkg is not actually installed
            if not db_pkg:
                continue

            # yum on 5.7 list everything as "installed" instead
            # of the repo it came from
            if repo in (None, "installed"):
                continue
            active.add(repo)
        return active

    def getEnabled(self, yb):
        lst = []
        enabled = yb.repos.listEnabled()

        for repo in enabled:
            try:
                fn = repo.retrieveMD(self.PRODUCTID)
                cert = self.__getCert(fn)
                if cert is None:
                    continue
                lst.append((cert, repo.id))
            except Exception, e:
                log.warn("Error loading productid metadata for %s." % repo)
                log.exception(e)
                self.meta_data_errors.append(repo.id)
        return lst