Beispiel #1
0
    def package_url(self, pkgname):

        def cmpEVR(p1, p2):
            ed1 = p1.edition()
            ed2 = p2.edition()
            (e1, v1, r1) = map(str, [ed1.epoch(), ed1.version(), ed1.release()])
            (e2, v2, r2) = map(str, [ed2.epoch(), ed2.version(), ed2.release()])
            return rpm.labelCompare((e1, v1, r1), (e2, v2, r2))

        if not self.Z:
            self.__initialize_zypp()

        q = zypp.PoolQuery()
        q.addKind(zypp.ResKind.package)
        q.setMatchExact()
        q.addAttribute(zypp.SolvAttr.name, pkgname)
        items = sorted(q.queryResults(self.Z.pool()),
                       cmp=lambda x,y: cmpEVR(zypp.asKindPackage(x), zypp.asKindPackage(y)),
                       reverse=True)

        if items:
            item = zypp.asKindPackage(items[0])
            url = self.get_url(item)
            proxies = self.get_proxies(item)
            return (url, proxies)

        return (None, None)
Beispiel #2
0
    def selectGroup(self, grp, include = ksconstants.GROUP_DEFAULT):
        if not self.Z:
            self.__initialize_zypp()
        found = False
        q=zypp.PoolQuery()
        q.addKind(zypp.ResKind.pattern)
        msger.debug("looking for %s" % grp)
        for item in sorted(
                        q.queryResults(self.Z.pool()),
                        key=cmp_to_key(lambda x,y: cmpPackage(self._castKind(x), self._castKind(y))),
                        reverse=True):
            xitem = self._castKind(item)
            summary = "%s" % xitem.summary()
            name = "%s" % xitem.name()
            msger.debug("checking %s version %s" % (name, xitem.edition()))
            if name == grp or summary == grp:
                found = True
                msger.info("marking pattern %s %s to be installed" % ( name, xitem.edition() ))
                item.status().setToBeInstalled (zypp.ResStatus.USER)
                break

        if found:
            if include == ksconstants.GROUP_REQUIRED:
                list(map(
                    lambda p: self.deselectPackage(p),
                    list(grp.default_packages.keys())))

            return None
        else:
            raise CreatorError("Unable to find pattern: %s" % (grp,))
Beispiel #3
0
    def selectGroup(self, grp, include = ksparser.GROUP_DEFAULT):
        def compareGroup(pitem):
            item = zypp.asKindPattern(pitem)
            return item.repoInfo().priority()
        if not self.Z:
            self.__initialize_zypp()
        found = False
        q = zypp.PoolQuery()
        q.addKind(zypp.ResKind.pattern)
        for pitem in sorted(q.queryResults(self.Z.pool()), key=compareGroup):
            item = zypp.asKindPattern(pitem)
            summary = "%s" % item.summary()
            name = "%s" % item.name()
            if name == grp or summary == grp:
                found = True
                pitem.status().setToBeInstalled (zypp.ResStatus.USER)
                break

        if found:
            if include == ksparser.GROUP_REQUIRED:
                map(
                    lambda p: self.deselectPackage(p),
                    grp.default_packages.keys())

            return None
        else:
            raise CreatorError("Unable to find pattern: %s" % (grp,))
Beispiel #4
0
 def whatObsolete(self, pkg):
     query = zypp.PoolQuery()
     query.addKind(zypp.ResKind.package)
     query.addAttribute(zypp.SolvAttr.obsoletes, pkg)
     query.setMatchExact()
     for pi in query.queryResults(self.Z.pool()):
         return pi
     return None
Beispiel #5
0
 def whatObsolete(self, pkg):
     query = zypp.PoolQuery()
     query.addKind(zypp.ResKind.package)
     query.addDependency(zypp.SolvAttr.obsoletes, pkg.name(), pkg.edition())
     query.setMatchExact()
     for pi in query.queryResults(self.Z.pool()):
         return pi
     return None
Beispiel #6
0
    def whatObsolete(self, pkg, flag, evr):
        query = zypp.PoolQuery()
        query.addKind(zypp.ResKind.package)
        query.addAttribute(zypp.SolvAttr.obsoletes, pkg)
        query.setMatchExact()
        if flag and evr:
            query.addAttribute(zypp.SolvAttr.edition, flag+evr)

        for pi in sorted(query.queryResults(self.Z.pool()),
                         key=cmp_to_key(lambda x,y: cmpPackage(self._castKind(x), self._castKind(y))),
                         reverse=True):
            return pi
        return None
Beispiel #7
0
    def package_url(self, pkgname):

        if not self.Z:
            self.__initialize_zypp()

        q = zypp.PoolQuery()
        q.addKind(zypp.ResKind.package)
        q.setMatchExact()
        q.addAttribute(zypp.SolvAttr.name, pkgname)
        items = q.queryResults(self.Z.pool())

        if items:
            items = sorted(items,
                           key=cmp_to_key(lambda x,y: cmpPackage(self._castKind(x), self._castKind(y))),
                           reverse=True)

            item = self._castKind(items[0])
            url = self.get_url(item)
            proxies = self.get_proxies(item)
            return (url, proxies)

        return (None, None)
Beispiel #8
0
    def selectPackage(self, pkg):
        """ Select a given package or package pattern, can be specified with name.arch or name* or *name """
        if not self.Z:
            self.__initialize_zypp()

        def markPoolItem(obs, pi):
            if obs == None:
                pi.status().setToBeInstalled(zypp.ResStatus.USER)
            else:
                obs.status().setToBeInstalled(zypp.ResStatus.USER)

        found = False
        startx = pkg.startswith("*")
        endx = pkg.endswith("*")
        ispattern = startx or endx
        name, arch = self._splitPkgString(pkg)

        q = zypp.PoolQuery()
        q.addKind(zypp.ResKind.package)
        if ispattern:
            if startx and not endx:
                pattern = '%s$' % (pkg[1:])
            if endx and not startx:
                pattern = '^%s' % (pkg[0:-1])
            if endx and startx:
                pattern = '%s' % (pkg[1:-1])
            q.setMatchRegex()
            q.addAttribute(zypp.SolvAttr.name, pattern)
        elif arch:
            q.setMatchExact()
            q.addAttribute(zypp.SolvAttr.name, name)
        else:
            q.setMatchExact()
            q.addAttribute(zypp.SolvAttr.name, pkg)

        for item in sorted(q.queryResults(self.Z.pool()),
                           key=lambda item: str(item.edition()),
                           reverse=True):
            if item.name() in self.excpkgs.keys() and self.excpkgs[
                    item.name()] == item.repoInfo().name():
                continue
            if item.name() in self.incpkgs.keys(
            ) and self.incpkgs[item.name()] != item.repoInfo().name():
                continue
            found = True
            obspkg = self.whatObsolete(item.name())
            if arch:
                if arch == str(item.arch()):
                    item.status().setToBeInstalled(zypp.ResStatus.USER)
            else:
                markPoolItem(obspkg, item)
            if not ispattern:
                break
        # Can't match using package name, then search from packge provides infomation
        if found == False and not ispattern:
            q.addAttribute(zypp.SolvAttr.provides, pkg)
            q.addAttribute(zypp.SolvAttr.name, '')
            for item in sorted(q.queryResults(self.Z.pool()),
                               key=lambda item: str(item.edition()),
                               reverse=True):
                if item.name() in self.excpkgs.keys() and self.excpkgs[
                        item.name()] == item.repoInfo().name():
                    continue
                if item.name() in self.incpkgs.keys(
                ) and self.incpkgs[item.name()] != item.repoInfo().name():
                    continue
                found = True
                obspkg = self.whatObsolete(item.name())
                markPoolItem(obspkg, item)
                break
        if found:
            return None
        else:
            raise CreatorError("Unable to find package: %s" % (pkg, ))
Beispiel #9
0
    def selectPackage(self, pkg):
        """Select a given package or package pattern, can be specified
        with name.arch or name* or *name
        """

        if not self.Z:
            self.__initialize_zypp()

        def markPoolItem(obs, pi):
            if obs == None:
                pi.status().setToBeInstalled (zypp.ResStatus.USER)
            else:
                obs.status().setToBeInstalled (zypp.ResStatus.USER)

        found = False
        startx = pkg.startswith("*")
        endx = pkg.endswith("*")
        ispattern = startx or endx
        name, arch, flag, evr = self._splitPkgString(pkg)
        msger.debug("selectPackage %s %s %s %s" % (name, arch, flag, evr))

        q = zypp.PoolQuery()
        q.addKind(zypp.ResKind.package)

        if ispattern:
            if startx and not endx:
                pattern = '%s$' % (pkg[1:])
            if endx and not startx:
                pattern = '^%s' % (pkg[0:-1])
            if endx and startx:
                pattern = '%s' % (pkg[1:-1])
            q.setMatchRegex()
            q.addAttribute(zypp.SolvAttr.name,pattern)

        elif arch:
            q.setMatchExact()
            q.addAttribute(zypp.SolvAttr.name,name)

        elif flag and evr:
            q.setMatchExact()
            q.addAttribute(zypp.SolvAttr.name,name)
            q.addAttribute(zypp.SolvAttr.edition,flag+evr)

        else:
            q.setMatchExact()
            q.addAttribute(zypp.SolvAttr.name,pkg)


        for item in sorted(
                        q.queryResults(self.Z.pool()),
                        key=cmp_to_key(lambda x,y: cmpPackage(self._castKind(x), self._castKind(y))),
                        reverse=True):

            xitem = self._castKind(item)
            msger.debug("item found %s %s" % (xitem.name(), xitem.edition()))
            if xitem.name() in list(self.excpkgs.keys()) and \
               self.excpkgs[xitem.name()] == xitem.repoInfo().name():
                continue
            if xitem.name() in list(self.incpkgs.keys()) and \
               self.incpkgs[xitem.name()] != xitem.repoInfo().name():
                continue

            found = True
            obspkg = self.whatObsolete(xitem.name(), flag, evr)
            if obspkg:
                msger.debug("selecting %s %s which obsoletes %s" % (self._castKind(obspkg).name(), self._castKind(obspkg).edition(), xitem.name()))

            if arch:
                if arch == str(xitem.arch()):
                    item.status().setToBeInstalled (zypp.ResStatus.USER)
            else:
                markPoolItem(obspkg, item)
            if not ispattern:
                break

        # Can't match using package name, then search from packge
        # provides infomation
        if found == False and not ispattern:
            msger.debug("package name %s not found searching provides" % name)
            q.addAttribute(zypp.SolvAttr.provides, name)
            q.addAttribute(zypp.SolvAttr.name,'')

            if flag and evr:
                q.addAttribute(zypp.SolvAttr.edition,flag+evr)

            for item in sorted(
                            q.queryResults(self.Z.pool()),
                            key=cmp_to_key(lambda x,y: cmpPackage(self._castKind(x), self._castKind(y))),
                            reverse=True):

                xitem = self._castKind(item)
                msger.debug("item found %s %s" % (xitem.name(), xitem.edition()))
                if xitem.name() in list(self.excpkgs.keys()) and \
                   self.excpkgs[xitem.name()] == xitem.repoInfo().name():
                    continue
                if xitem.name() in list(self.incpkgs.keys()) and \
                   self.incpkgs[xitem.name()] != xitem.repoInfo().name():
                    continue

                found = True
                obspkg = self.whatObsolete(xitem.name(), flag, evr)
                if obspkg:
                    msger.debug("selecting %s %s which obsoletes %s" % (self._castKind(obspkg).name(), self._castKind(obspkg).edition(), xitem.name()))

                markPoolItem(obspkg, item)
                break

        if found:
            return None
        else:
            raise CreatorError("Unable to find package: %s" % (pkg,))
Beispiel #10
0
    def selectPackage(self, pkg):
        """Select a given package or package pattern, can be specified
        with name.arch or name* or *name
        """

        if not self.Z:
            self.__initialize_zypp()

        def markPoolItem(obs, pi):
            if obs == None:
                pi.status().setToBeInstalled (zypp.ResStatus.USER)
            else:
                obs.status().setToBeInstalled (zypp.ResStatus.USER)

        def cmpEVR(p1, p2):
            # compare criterion: arch compatibility first, then repo
            # priority, and version last
            a1 = p1.arch()
            a2 = p2.arch()
            if str(a1) != str(a2):
                if a1.compatible_with(a2):
                    return -1
                else:
                    return 1
            # Priority of a repository is an integer value between 0 (the
            # highest priority) and 99 (the lowest priority)
            pr1 = int(p1.repoInfo().priority())
            pr2 = int(p2.repoInfo().priority())
            if pr1 > pr2:
                return -1
            elif pr1 < pr2:
                return 1

            ed1 = p1.edition()
            ed2 = p2.edition()
            (e1, v1, r1) = map(str, [ed1.epoch(), ed1.version(), ed1.release()])
            (e2, v2, r2) = map(str, [ed2.epoch(), ed2.version(), ed2.release()])
            return rpm.labelCompare((e1, v1, r1), (e2, v2, r2))

        found = False
        startx = pkg.startswith("*")
        endx = pkg.endswith("*")
        ispattern = startx or endx
        name, arch = self._splitPkgString(pkg)

        q = zypp.PoolQuery()
        q.addKind(zypp.ResKind.package)

        if ispattern:
            if startx and not endx:
                pattern = '%s$' % (pkg[1:])
            if endx and not startx:
                pattern = '^%s' % (pkg[0:-1])
            if endx and startx:
                pattern = '%s' % (pkg[1:-1])
            q.setMatchRegex()
            q.addAttribute(zypp.SolvAttr.name, pattern)

        elif arch:
            q.setMatchExact()
            q.addAttribute(zypp.SolvAttr.name, name)

        else:
            q.setMatchExact()
            q.addAttribute(zypp.SolvAttr.name, pkg)

        for pitem in sorted(
                        q.queryResults(self.Z.pool()),
                        cmp=lambda x,y: cmpEVR(zypp.asKindPackage(x), zypp.asKindPackage(y)),
                        reverse=True):
            item = zypp.asKindPackage(pitem)
            if item.name() in self.excpkgs.keys() and \
               self.excpkgs[item.name()] == item.repoInfo().name():
                continue
            if item.name() in self.incpkgs.keys() and \
               self.incpkgs[item.name()] != item.repoInfo().name():
                continue

            found = True
            obspkg = self.whatObsolete(item)
            if arch:
                if arch == str(item.arch()):
                    pitem.status().setToBeInstalled (zypp.ResStatus.USER)
            else:
                markPoolItem(obspkg, pitem)
            if not ispattern:
                break

        # Can't match using package name, then search from packge
        # provides infomation
        if found == False and not ispattern:
            q.addAttribute(zypp.SolvAttr.provides, pkg)
            q.addAttribute(zypp.SolvAttr.name,'')

            for pitem in sorted(
                            q.queryResults(self.Z.pool()),
                            cmp=lambda x,y: cmpEVR(zypp.asKindPackage(x), zypp.asKindPackage(y)),
                            reverse=True):
                item = zypp.asKindPackage(pitem)
                if item.name() in self.excpkgs.keys() and \
                   self.excpkgs[item.name()] == item.repoInfo().name():
                    continue
                if item.name() in self.incpkgs.keys() and \
                   self.incpkgs[item.name()] != item.repoInfo().name():
                    continue

                found = True
                obspkg = self.whatObsolete(item)
                markPoolItem(obspkg, pitem)
                break

        if found:
            return None
        else:
            raise CreatorError("Unable to find package: %s" % (pkg,))