Esempio n. 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)
Esempio n. 2
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)
 def getSoftware(self):
     """ Get the packagenames and so on
     """
     groupDict = {}
     versionDict = {}
     summaryDict = {}
     descrDict = {}
     #
     # try to iterate over the pool
     try: 
         #
         # iterate over the pool
         for item in self.pool:
             #
             # only packages, no sources/patches
             if zypp.isKindPackage(item):
                 #
                 # name of the package
                 name = item.name()
                 #
                 # group of the package
                 group = zypp.asKindPackage(item).group()
                 descr = zypp.asKindPackage(item).description()
                 summary = zypp.asKindPackage(item).summary()
                 version = zypp.asKindPackage(item).edition()
                 #
                 # fill in tempdict
                 groupDict[name] = group
                 summaryDict[name] = summary
                 descrDict[name] = descr
                 versionDict[name] = version
         #
         # only use first part of Group  e.g.: System/network/x -> System
         for i,j in groupDict.iteritems():
             x = {}
             x["Group"] = j.partition("/")[0]
             self.softwareDict[i] = x
         for i,j in summaryDict.iteritems():
             self.softwareDict[i]["Summary"]=str(j)
         for i,j in descrDict.iteritems():
             self.softwareDict[i]["Description"]=str(j)
         for i,j in versionDict.iteritems():
             self.softwareDict[i]["Version"]=str(j)
         #
         # push to configDict
         self.configDict["softwareDict"]=self.softwareDict
     #
     # manage exceptions
     except: # print the exception
             e = sys.exc_info()[1]
             msg = u"Error:\n ".encode("utf-8")+str(e).encode("utf-8")+"\n".encode("utf-8")
             #
             # error popup
             WARNING_URL_GUI = GUI_warning_popup.GUI_warning_popup(self.factory, self.repositoryDialog.this, msg)
             WARNING_URL_GUI.handleEvent()
             #
             # exit test
             return False
     return True
 def getLocalPkgPath(self, po):
     repoinfo = po.repoInfo()
     cacheroot = repoinfo.packagesPath()
     location= zypp.asKindPackage(po).location()
     rpmpath = str(location.filename())
     pkgpath = "%s/%s" % (cacheroot, os.path.basename(rpmpath))
     return pkgpath
Esempio n. 5
0
 def getLocalPkgPath(self, po):
     repoinfo = po.repoInfo()
     cacheroot = repoinfo.packagesPath()
     location = zypp.asKindPackage(po).location()
     rpmpath = str(location.filename())
     pkgpath = "%s/%s" % (cacheroot, rpmpath)
     return pkgpath
Esempio n. 6
0
    def downloadPkgs(self, package_objects, count):
        localpkgs = self.localpkgs.keys()
        progress_obj = rpmmisc.TextProgress(count)
        for po in package_objects:
            if po.name() in localpkgs:
                continue
            filename = self.getLocalPkgPath(po)
            if os.path.exists(filename):
                if self.checkPkg(filename) == 0:
                    continue
            dirn = os.path.dirname(filename)
            if not os.path.exists(dirn):
                os.makedirs(dirn)
            baseurl = str(po.repoInfo().baseUrls()[0])
            index = baseurl.find("?")
            if index > -1:
                baseurl = baseurl[:index]
            proxy = self.get_proxy(po.repoInfo())
            proxies = {}
            if proxy:
                proxies = {str(proxy.split(":")[0]):str(proxy)}

            location = zypp.asKindPackage(po).location()
            location = str(location.filename())
            if location.startswith("./"):
                location = location[2:]
            url = baseurl + "/%s" % location
            try:
                filename = rpmmisc.myurlgrab(url, filename, proxies, progress_obj)
            except CreatorError:
                self.close()
                raise
Esempio n. 7
0
    def downloadPkgs(self, package_objects, count):
        localpkgs = self.localpkgs.keys()
        progress_obj = rpmmisc.TextProgress(count)
        for po in package_objects:
            if po.name() in localpkgs:
                continue
            filename = self.getLocalPkgPath(po)
            if os.path.exists(filename):
                if self.checkPkg(filename) == 0:
                    continue
            dirn = os.path.dirname(filename)
            if not os.path.exists(dirn):
                os.makedirs(dirn)
            baseurl = str(po.repoInfo().baseUrls()[0])
            index = baseurl.find("?")
            if index > -1:
                baseurl = baseurl[:index]
            proxy = self.get_proxy(po.repoInfo())
            proxies = {}
            if proxy:
                proxies = {str(proxy.split(":")[0]): str(proxy)}

            location = zypp.asKindPackage(po).location()
            location = str(location.filename())
            if location.startswith("./"):
                location = location[2:]
            url = baseurl + "/%s" % location
            try:
                filename = rpmmisc.myurlgrab(url, filename, proxies,
                                             progress_obj)
            except CreatorError:
                self.close()
                raise
Esempio n. 8
0
 def _castKind(self, poolitem):
     item = None
     if zypp.isKindPattern(poolitem):
         item = zypp.asKindPattern(poolitem)
     elif zypp.isKindPackage(poolitem):
         item = zypp.asKindPackage(poolitem)
     elif zypp.isKindResolvable(poolitem):
         item = zypp.asKindResolvable(poolitem)
     return item
Esempio n. 9
0
 def testpath(self):
   import zypp
   Z = zypp.ZYppFactory.instance().getZYpp()
   assert Z
   Z.initializeTarget( zypp.Pathname("/") )
   Z.target().load()
   installed_pkgs = Z.pool()
   for item in installed_pkgs:
       if zypp.isKindPackage(item):
           print("Repopath %s" % item.repoInfo().packagesPath())
           item = zypp.asKindPackage(item)
           print("Location filename %s" % item.location().filename())
           print("%s.%s %s:%d" % (item.name(), item.arch(), item.edition(), item.installSize()))
 def testpath(self):
   import zypp
   Z = zypp.ZYppFactory.instance().getZYpp()
   assert Z
   Z.initializeTarget( zypp.Pathname("/") )
   Z.target().load()
   installed_pkgs = Z.pool()
   for item in installed_pkgs:
       if zypp.isKindPackage(item):
           print "Repopath %s" % item.repoInfo().packagesPath()
           item = zypp.asKindPackage(item)
           print "Location filename %s" % item.location().filename()
           print "%s.%s %s:%d" % (item.name(), item.arch(), item.edition(), item.installSize())
Esempio n. 11
0
    def get_url(self, pobj):
        if not pobj:
            return None

        name = str(pobj.repoInfo().name())
        try:
            repo = filter(lambda r: r.name == name, self.repos)[0]
        except IndexError:
            return None

        baseurl = repo.baseurl[0]

        index = baseurl.find("?")
        if index > -1:
            baseurl = baseurl[:index]

        location = zypp.asKindPackage(pobj).location()
        location = str(location.filename())
        if location.startswith("./"):
            location = location[2:]

        return os.path.join(baseurl, location)
Esempio n. 12
0
    def get_url(self, pobj):
        if not pobj:
            return None

        name = str(pobj.repoInfo().name())
        try:
            repo = filter(lambda r: r.name == name, self.repos)[0]
        except IndexError:
            return None

        baseurl = repo.baseurl[0]

        index = baseurl.find("?")
        if index > -1:
            baseurl = baseurl[:index]

        location = zypp.asKindPackage(pobj).location()
        location = str(location.filename())
        if location.startswith("./"):
            location = location[2:]

        return os.path.join(baseurl, location)
Esempio n. 13
0
    def inDeselectPackages(self, pitem):
        """check if specified pacakges are in the list of inDeselectPackages
        """
        item = zypp.asKindPackage(pitem)
        name = item.name()
        for pkg in self.to_deselect:
            startx = pkg.startswith("*")
            endx = pkg.endswith("*")
            ispattern = startx or endx
            pkgname, pkgarch = self._splitPkgString(pkg)
            if not ispattern:
                if pkgarch:
                    if name == pkgname and str(item.arch()) == pkgarch:
                        return True;
                else:
                    if name == pkgname:
                        return True;
            else:
                if startx and name.endswith(pkg[1:]):
                    return True;
                if endx and name.startswith(pkg[:-1]):
                    return True;

        return False;
Esempio n. 14
0
    def package_url(self, pkg):

        def cmpEVR(ed1, ed2):
            (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,pkg)
        items = sorted(q.queryResults(self.Z.pool()),
                       cmp=lambda x,y: cmpEVR(x.edition(), y.edition()),
                       reverse=True)

        if items:
            baseurl = items[0].repoInfo().baseUrls()[0]
            location = zypp.asKindPackage(items[0]).location()
            return os.path.join(str(baseurl), str(location.filename()))

        return None
Esempio n. 15
0
    def inDeselectPackages(self, pitem):
        """check if specified pacakges are in the list of inDeselectPackages
        """
        item = zypp.asKindPackage(pitem)
        name = item.name()
        for pkg in self.to_deselect:
            startx = pkg.startswith("*")
            endx = pkg.endswith("*")
            ispattern = startx or endx
            pkgname, pkgarch = self._splitPkgString(pkg)
            if not ispattern:
                if pkgarch:
                    if name == pkgname and str(item.arch()) == pkgarch:
                        return True
                else:
                    if name == pkgname:
                        return True
            else:
                if startx and name.endswith(pkg[1:]):
                    return True
                if endx and name.startswith(pkg[:-1]):
                    return True

        return False
Esempio n. 16
0
    def installPkgs(self, package_objects):
        if not self.ts:
            self.__initialize_transaction()
        """ Set filters """
        probfilter = 0
        for flag in self.probFilterFlags:
            probfilter |= flag
        self.ts.setProbFilter(probfilter)

        localpkgs = self.localpkgs.keys()
        for po in package_objects:
            pkgname = po.name()
            if pkgname in localpkgs:
                rpmpath = self.localpkgs[pkgname]
            else:
                rpmpath = self.getLocalPkgPath(po)
            if not os.path.exists(rpmpath):
                """ Maybe it is a local repo """
                baseurl = str(po.repoInfo().baseUrls()[0])
                baseurl = baseurl.strip()
                location = zypp.asKindPackage(po).location()
                location = str(location.filename())
                if baseurl.startswith("file:/"):
                    rpmpath = baseurl[5:] + "/%s" % (location)
            if not os.path.exists(rpmpath):
                raise RpmError("Error: %s doesn't exist" % rpmpath)
            h = rpmmisc.readRpmHeader(self.ts, rpmpath)
            self.ts.addInstall(h, rpmpath, 'u')

        unresolved_dependencies = self.ts.check()
        if not unresolved_dependencies:
            self.ts.order()
            cb = rpmmisc.RPMInstallCallback(self.ts)
            installlogfile = "%s/__catched_stderr.buf" % (
                self.creator._instroot)
            msger.enable_logstderr(installlogfile)
            errors = self.ts.run(cb.callback, '')
            if errors is None:
                pass
            elif len(errors) == 0:
                msger.warning(
                    'scriptlet or other non-fatal errors occurred during transaction.'
                )
            else:
                for e in errors:
                    msger.warning(e[0])
                msger.error('Could not run transaction.')
            msger.disable_logstderr()

            self.ts.closeDB()
            self.ts = None
        else:
            for pkg, need, needflags, sense, key in unresolved_dependencies:
                package = '-'.join(pkg)
                if needflags == rpm.RPMSENSE_LESS:
                    deppkg = ' < '.join(need)
                elif needflags == rpm.RPMSENSE_EQUAL:
                    deppkg = ' = '.join(need)
                elif needflags == rpm.RPMSENSE_GREATER:
                    deppkg = ' > '.join(need)
                else:
                    deppkg = '-'.join(need)

                if sense == rpm.RPMDEP_SENSE_REQUIRES:
                    msger.warning("[%s] Requires [%s], which is not provided" %
                                  (package, deppkg))
                elif sense == rpm.RPMDEP_SENSE_CONFLICTS:
                    msger.warning("[%s] Conflicts with [%s]" %
                                  (package, deppkg))

            raise RepoError("Unresolved dependencies, transaction failed.")
Esempio n. 17
0
    def runInstall(self, checksize = 0):
        os.environ["HOME"] = "/"
        self.buildTransaction()

        todo = zypp.GetResolvablesToInsDel(self.Z.pool())
        installed_pkgs = todo._toInstall
        dlpkgs = []
        for item in installed_pkgs:
            if not zypp.isKindPattern(item) and not self.inDeselectPackages(item):
                dlpkgs.append(item)

        # record the total size of installed pkgs
        pkgs_total_size = sum(map(lambda x: int(x.installSize()), dlpkgs))

        # check needed size before actually download and install
        if checksize and pkgs_total_size > checksize:
            raise CreatorError("Size of specified root partition in kickstart file is too small to install all selected packages.")

        # record all pkg and the content
        localpkgs = self.localpkgs.keys()
        for pkg in dlpkgs:
            license = ''
            if pkg.name() in localpkgs:
                hdr = rpmmisc.readRpmHeader(self.ts, self.localpkgs[pkg.name()])
                pkg_long_name = "%s-%s-%s.%s.rpm" % (hdr['name'], hdr['version'], hdr['release'], hdr['arch'])
                license = hdr['license']
            else:
                pkg_long_name = "%s-%s.%s.rpm" % (pkg.name(), pkg.edition(), pkg.arch())
                package = zypp.asKindPackage(pkg)
                license = package.license()
            self.__pkgs_content[pkg_long_name] = {} #TBD: to get file list
            if license in self.__pkgs_license.keys():
                self.__pkgs_license[license].append(pkg_long_name)
            else:
                self.__pkgs_license[license] = [pkg_long_name]

        total_count = len(dlpkgs)
        cached_count = 0
        localpkgs = self.localpkgs.keys()
        msger.info("Checking packages cache and packages integrity ...")
        for po in dlpkgs:
            """ Check if it is cached locally """
            if po.name() in localpkgs:
                cached_count += 1
            else:
                local = self.getLocalPkgPath(po)
                if os.path.exists(local):
                    if self.checkPkg(local) != 0:
                        os.unlink(local)
                    else:
                        cached_count += 1
        download_count =  total_count - cached_count
        msger.info("%d packages to be installed, %d packages gotten from cache, %d packages to be downloaded" % (total_count, cached_count, download_count))
        try:
            if download_count > 0:
                msger.info("Downloading packages ...")
            self.downloadPkgs(dlpkgs, download_count)
            self.installPkgs(dlpkgs)

        except RepoError, e:
            raise CreatorError("Unable to download from repo : %s" % (e,))
Z = zypp.ZYppFactory_instance().getZYpp()
Z.initializeTarget( zypp.Pathname("/") )
Z.target().load();

repoManager = zypp.RepoManager()
repos = repoManager.knownRepositories()

for repo in repos:
    if not repo.enabled():
        continue
    if not repoManager.isCached( repo ):
        repoManager.buildCache( repo )
    repoManager.loadFromCache( repo );

print "Items: %d" % ( Z.pool().size() )

for item in Z.pool():
    if item.status().isInstalled():
      t = "i"
    else:
      t = "*"

    print "%s %s:%s-%s.%s\t(%s)" % ( t,
                                     item.kind(),
                                     item.name(),
                                     item.edition(),
                                     item.arch(),
                                     item.repoInfo().alias() )
    if zypp.isKindPackage( item ):
      print " Group: %s" %(zypp.asKindPackage( item ).group( ) )
Esempio n. 19
0
    def runInstall(self, checksize=0):
        os.environ["HOME"] = "/"
        self.buildTransaction()

        todo = zypp.GetResolvablesToInsDel(self.Z.pool())
        installed_pkgs = todo._toInstall
        dlpkgs = []
        for item in installed_pkgs:
            if not zypp.isKindPattern(item) and not self.inDeselectPackages(
                    item):
                dlpkgs.append(item)

        # record the total size of installed pkgs
        pkgs_total_size = sum(map(lambda x: int(x.installSize()), dlpkgs))

        # check needed size before actually download and install
        if checksize and pkgs_total_size > checksize:
            raise CreatorError(
                "Size of specified root partition in kickstart file is too small to install all selected packages."
            )

        # record all pkg and the content
        localpkgs = self.localpkgs.keys()
        for pkg in dlpkgs:
            license = ''
            if pkg.name() in localpkgs:
                hdr = rpmmisc.readRpmHeader(self.ts,
                                            self.localpkgs[pkg.name()])
                pkg_long_name = "%s-%s-%s.%s.rpm" % (
                    hdr['name'], hdr['version'], hdr['release'], hdr['arch'])
                license = hdr['license']
            else:
                pkg_long_name = "%s-%s.%s.rpm" % (pkg.name(), pkg.edition(),
                                                  pkg.arch())
                package = zypp.asKindPackage(pkg)
                license = package.license()
            self.__pkgs_content[pkg_long_name] = {}  #TBD: to get file list
            if license in self.__pkgs_license.keys():
                self.__pkgs_license[license].append(pkg_long_name)
            else:
                self.__pkgs_license[license] = [pkg_long_name]

        total_count = len(dlpkgs)
        cached_count = 0
        localpkgs = self.localpkgs.keys()
        msger.info("Checking packages cache and packages integrity ...")
        for po in dlpkgs:
            """ Check if it is cached locally """
            if po.name() in localpkgs:
                cached_count += 1
            else:
                local = self.getLocalPkgPath(po)
                if os.path.exists(local):
                    if self.checkPkg(local) != 0:
                        os.unlink(local)
                    else:
                        cached_count += 1
        download_count = total_count - cached_count
        msger.info(
            "%d packages to be installed, %d packages gotten from cache, %d packages to be downloaded"
            % (total_count, cached_count, download_count))
        try:
            if download_count > 0:
                msger.info("Downloading packages ...")
            self.downloadPkgs(dlpkgs, download_count)
            self.installPkgs(dlpkgs)

        except RepoError, e:
            raise CreatorError("Unable to download from repo : %s" % (e, ))
Esempio n. 20
0
    def runInstall(self, checksize=0):
        os.environ["HOME"] = "/"
        self.buildTransaction()

        todo = zypp.GetResolvablesToInsDel(self.Z.pool())
        installed_pkgs = todo._toInstall
        dlpkgs = []
        for item in installed_pkgs:
            if not zypp.isKindPattern(item) and \
               not self.inDeselectPackages(item):
                dlpkgs.append(item)

        # record all pkg and the content
        localpkgs = self.localpkgs.keys()
        for pkg in dlpkgs:
            license = ''
            if pkg.name() in localpkgs:
                hdr = rpmmisc.readRpmHeader(self.ts,
                                            self.localpkgs[pkg.name()])
                pkg_long_name = misc.RPM_FMT % {
                    'name': hdr['name'],
                    'arch': hdr['arch'],
                    'ver_rel': '%s-%s' % (hdr['version'], hdr['release']),
                }
                license = hdr['license']

            else:
                pkg_long_name = misc.RPM_FMT % {
                    'name': pkg.name(),
                    'arch': pkg.arch(),
                    'ver_rel': pkg.edition(),
                }

                package = zypp.asKindPackage(pkg)
                license = package.license()

            self.__pkgs_content[pkg_long_name] = {}  #TBD: to get file list

            if license in self.__pkgs_license.keys():
                self.__pkgs_license[license].append(pkg_long_name)
            else:
                self.__pkgs_license[license] = [pkg_long_name]

        total_count = len(dlpkgs)
        cached_count = 0
        download_total_size = sum(map(lambda x: int(x.downloadSize()), dlpkgs))
        localpkgs = self.localpkgs.keys()

        msger.info("Checking packages cache and packages integrity ...")
        for po in dlpkgs:
            # Check if it is cached locally
            if po.name() in localpkgs:
                cached_count += 1
            else:
                local = self.getLocalPkgPath(po)
                if os.path.exists(local):
                    if self.checkPkg(local) != 0:
                        os.unlink(local)
                    else:
                        download_total_size -= int(po.downloadSize())
                        cached_count += 1
        cache_avail_size = misc.get_filesystem_avail(self.cachedir)
        if cache_avail_size < download_total_size:
            raise CreatorError("No enough space used for downloading.")

        # record the total size of installed pkgs
        install_total_size = sum(map(lambda x: int(x.installSize()), dlpkgs))
        # check needed size before actually download and install
        if checksize and install_total_size > checksize:
            raise CreatorError("No enough space used for installing, "
                               "please resize partition size in ks file")

        download_count = total_count - cached_count
        msger.info("%d packages to be installed, "
                   "%d packages gotten from cache, "
                   "%d packages to be downloaded" \
                   % (total_count, cached_count, download_count))

        try:
            if download_count > 0:
                msger.info("Downloading packages ...")
            self.downloadPkgs(dlpkgs, download_count)

            self.installPkgs(dlpkgs)

        except RepoError, e:
            raise CreatorError("Unable to download from repo : %s" % (e, ))
Esempio n. 21
0
    def runInstall(self, checksize = 0):
        os.environ["HOME"] = "/"
        os.environ["LD_PRELOAD"] = ""
        self.buildTransaction()

        todo = zypp.GetResolvablesToInsDel(self.Z.pool())
        installed_pkgs = todo._toInstall
        dlpkgs = []
        for pitem in installed_pkgs:
            if not zypp.isKindPattern(pitem) and \
              not self.inDeselectPackages(pitem):
                item = zypp.asKindPackage(pitem)
                dlpkgs.append(item)

                if not self.install_debuginfo or str(item.arch()) == "noarch":
                    continue

                dipkg = self._zyppQueryPackage("%s-debuginfo" % item.name())
                if dipkg:
                    ditem = zypp.asKindPackage(dipkg)
                    dlpkgs.append(ditem)
                else:
                    msger.warning("No debuginfo rpm found for: %s" \
                                  % item.name())

        # record all pkg and the content
        localpkgs = self.localpkgs.keys()
        for pkg in dlpkgs:
            license = ''
            if pkg.name() in localpkgs:
                hdr = rpmmisc.readRpmHeader(self.ts, self.localpkgs[pkg.name()])
                pkg_long_name = misc.RPM_FMT % {
                                    'name': hdr['name'],
                                    'arch': hdr['arch'],
                                    'version': hdr['version'],
                                    'release': hdr['release']
                                }
                license = hdr['license']

            else:
                pkg_long_name = misc.RPM_FMT % {
                                    'name': pkg.name(),
                                    'arch': pkg.arch(),
                                    'version': pkg.edition().version(),
                                    'release': pkg.edition().release()
                                }

                license = pkg.license()

            if license in self.__pkgs_license.keys():
                self.__pkgs_license[license].append(pkg_long_name)
            else:
                self.__pkgs_license[license] = [pkg_long_name]

        total_count = len(dlpkgs)
        cached_count = 0
        download_total_size = sum(map(lambda x: int(x.downloadSize()), dlpkgs))
        localpkgs = self.localpkgs.keys()

        msger.info("Checking packages cached ...")
        for po in dlpkgs:
            # Check if it is cached locally
            if po.name() in localpkgs:
                cached_count += 1
            else:
                local = self.getLocalPkgPath(po)
                name = str(po.repoInfo().name())
                try:
                    repo = filter(lambda r: r.name == name, self.repos)[0]
                except IndexError:
                    repo = None
                nocache = repo.nocache if repo else False

                if os.path.exists(local):
                    if nocache or self.checkPkg(local) !=0:
                        os.unlink(local)
                    else:
                        download_total_size -= int(po.downloadSize())
                        cached_count += 1
        cache_avail_size = misc.get_filesystem_avail(self.cachedir)
        if cache_avail_size < download_total_size:
            raise CreatorError("No enough space used for downloading.")

        # record the total size of installed pkgs
        install_total_size = sum(map(lambda x: int(x.installSize()), dlpkgs))
        # check needed size before actually download and install

        # FIXME: for multiple partitions for loop type, check fails
        #        skip the check temporarily
        #if checksize and install_total_size > checksize:
        #    raise CreatorError("No enough space used for installing, "
        #                       "please resize partition size in ks file")

        download_count =  total_count - cached_count
        msger.info("Packages: %d Total, %d Cached, %d Missed" \
                   % (total_count, cached_count, download_count))

        try:
            if download_count > 0:
                msger.info("Downloading packages ...")
            self.downloadPkgs(dlpkgs, download_count)

            self.installPkgs(dlpkgs)

        except (RepoError, RpmError):
            raise
        except Exception, e:
            raise CreatorError("Package installation failed: %s" % (e,))
Esempio n. 22
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.name())
            if arch:
                if arch == str(item.arch()):
                    item.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.name())
                markPoolItem(obspkg, pitem)
                break

        if found:
            return None
        else:
            raise CreatorError("Unable to find package: %s" % (pkg,))
Esempio n. 23
0
    def installPkgs(self, package_objects):
        if not self.ts:
            self.__initialize_transaction()

        # Set filters
        probfilter = 0
        for flag in self.probFilterFlags:
            probfilter |= flag
        self.ts.setProbFilter(probfilter)
        self.ts_pre.setProbFilter(probfilter)

        localpkgs = self.localpkgs.keys()

        for po in package_objects:
            pkgname = po.name()
            if pkgname in localpkgs:
                rpmpath = self.localpkgs[pkgname]
            else:
                rpmpath = self.getLocalPkgPath(po)

            if not os.path.exists(rpmpath):
                # Maybe it is a local repo
                baseurl = str(po.repoInfo().baseUrls()[0])
                baseurl = baseurl.strip()

                location = zypp.asKindPackage(po).location()
                location = str(location.filename())

                if baseurl.startswith("file:/"):
                    rpmpath = baseurl[5:] + "/%s" % (location)

            if not os.path.exists(rpmpath):
                raise RpmError("Error: %s doesn't exist" % rpmpath)

            h = rpmmisc.readRpmHeader(self.ts, rpmpath)

            if pkgname in self.pre_pkgs:
                msger.verbose("pre-install package added: %s" % pkgname)
                self.ts_pre.addInstall(h, rpmpath, 'u')

            self.ts.addInstall(h, rpmpath, 'u')

        unresolved_dependencies = self.ts.check()
        if not unresolved_dependencies:
            if self.pre_pkgs:
                self.preinstallPkgs()

            self.ts.order()
            cb = rpmmisc.RPMInstallCallback(self.ts)
            installlogfile = "%s/__catched_stderr.buf" % (self.instroot)

            # start to catch stderr output from librpm
            msger.enable_logstderr(installlogfile)

            errors = self.ts.run(cb.callback, '')
            # stop catch
            msger.disable_logstderr()
            self.ts.closeDB()
            self.ts = None

            if errors is not None:
                if len(errors) == 0:
                    msger.warning('scriptlet or other non-fatal errors occurred '
                                  'during transaction.')

                else:
                    for e in errors:
                        msger.warning(e[0])
                    raise RepoError('Could not run transaction.')

        else:
            for pkg, need, needflags, sense, key in unresolved_dependencies:
                package = '-'.join(pkg)

                if needflags == rpm.RPMSENSE_LESS:
                    deppkg = ' < '.join(need)
                elif needflags == rpm.RPMSENSE_EQUAL:
                    deppkg = ' = '.join(need)
                elif needflags == rpm.RPMSENSE_GREATER:
                    deppkg = ' > '.join(need)
                else:
                    deppkg = '-'.join(need)

                if sense == rpm.RPMDEP_SENSE_REQUIRES:
                    msger.warning("[%s] Requires [%s], which is not provided" \
                                  % (package, deppkg))

                elif sense == rpm.RPMDEP_SENSE_CONFLICTS:
                    msger.warning("[%s] Conflicts with [%s]" %(package,deppkg))

            raise RepoError("Unresolved dependencies, transaction failed.")
Esempio n. 24
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,))
Esempio n. 25
0
    def runInstall(self, checksize = 0):
        os.environ["HOME"] = "/"
        self.buildTransaction()

        todo = zypp.GetResolvablesToInsDel(self.Z.pool())
        installed_pkgs = todo._toInstall
        dlpkgs = []
        for item in installed_pkgs:
            if not zypp.isKindPattern(item) and \
               not self.inDeselectPackages(item):
                dlpkgs.append(item)

        # record all pkg and the content
        localpkgs = self.localpkgs.keys()
        for pkg in dlpkgs:
            license = ''
            if pkg.name() in localpkgs:
                hdr = rpmmisc.readRpmHeader(self.ts, self.localpkgs[pkg.name()])
                pkg_long_name = misc.RPM_FMT % {
                                    'name': hdr['name'],
                                    'arch': hdr['arch'],
                                    'ver_rel': '%s-%s' % (hdr['version'],
                                                          hdr['release']),
                                }
                license = hdr['license']

            else:
                pkg_long_name = misc.RPM_FMT % {
                                    'name': pkg.name(),
                                    'arch': pkg.arch(),
                                    'ver_rel': pkg.edition(),
                                }

                package = zypp.asKindPackage(pkg)
                license = package.license()

            self.__pkgs_content[pkg_long_name] = {} #TBD: to get file list

            if license in self.__pkgs_license.keys():
                self.__pkgs_license[license].append(pkg_long_name)
            else:
                self.__pkgs_license[license] = [pkg_long_name]

        total_count = len(dlpkgs)
        cached_count = 0
        download_total_size = sum(map(lambda x: int(x.downloadSize()), dlpkgs))
        localpkgs = self.localpkgs.keys()

        msger.info("Checking packages cache and packages integrity ...")
        for po in dlpkgs:
            # Check if it is cached locally
            if po.name() in localpkgs:
                cached_count += 1
            else:
                local = self.getLocalPkgPath(po)
                if os.path.exists(local):
                    if self.checkPkg(local) != 0:
                        os.unlink(local)
                    else:
                        download_total_size -= int(po.downloadSize())
                        cached_count += 1
        cache_avail_size = misc.get_filesystem_avail(self.cachedir)
        if cache_avail_size < download_total_size:
            raise CreatorError("No enough space used for downloading.")

        # record the total size of installed pkgs
        install_total_size = sum(map(lambda x: int(x.installSize()), dlpkgs))
        # check needed size before actually download and install

        # FIXME: for multiple partitions for loop type, check fails
        #        skip the check temporarily
        #if checksize and install_total_size > checksize:
        #    raise CreatorError("No enough space used for installing, "
        #                       "please resize partition size in ks file")

        download_count =  total_count - cached_count
        msger.info("%d packages to be installed, "
                   "%d packages gotten from cache, "
                   "%d packages to be downloaded" \
                   % (total_count, cached_count, download_count))

        try:
            if download_count > 0:
                msger.info("Downloading packages ...")
            self.downloadPkgs(dlpkgs, download_count)

            self.installPkgs(dlpkgs)

        except (RepoError, RpmError):
            raise
        except Exception, e:
            raise CreatorError("Package installation failed: %s" % (e,))
Esempio n. 26
0
    def runInstall(self, checksize = 0):
        os.environ["HOME"] = "/"
        os.environ["LD_PRELOAD"] = ""
        self.buildTransaction()

        todo = zypp.GetResolvablesToInsDel(self.Z.pool())
        installed_pkgs = todo._toInstall
        dlpkgs = []

        for pitem in installed_pkgs:
            if not zypp.isKindPattern(pitem) and \
              not self.inDeselectPackages(pitem):
                item = zypp.asKindPackage(pitem)
                dlpkgs.append(item)

                if item.name() in self.check_pkgs:
                    self.check_pkgs.remove(item.name())

                if not self.install_debuginfo or str(item.arch()) == "noarch":
                    continue

                dipkg = self._zyppQueryPackage("%s-debuginfo" % item.name())
                if dipkg:
                    ditem = zypp.asKindPackage(dipkg)
                    dlpkgs.append(ditem)
                else:
                    msger.warning("No debuginfo rpm found for: %s" \
                                  % item.name())

        if self.check_pkgs:
            raise CreatorError('Packages absent in image: %s' % ','.join(self.check_pkgs))

        # record all pkg and the content
        localpkgs = self.localpkgs.keys()
        for pkg in dlpkgs:
            license = ''
            if pkg.name() in localpkgs:
                hdr = rpmmisc.readRpmHeader(self.ts, self.localpkgs[pkg.name()])
                pkg_long_name = misc.RPM_FMT % {
                                    'name': hdr['name'],
                                    'arch': hdr['arch'],
                                    'version': hdr['version'],
                                    'release': hdr['release']
                                }
                license = hdr['license']

            else:
                pkg_long_name = misc.RPM_FMT % {
                                    'name': pkg.name(),
                                    'arch': pkg.arch(),
                                    'version': pkg.edition().version(),
                                    'release': pkg.edition().release()
                                }

                license = pkg.license()

            if license in self.__pkgs_license.keys():
                self.__pkgs_license[license].append(pkg_long_name)
            else:
                self.__pkgs_license[license] = [pkg_long_name]

        total_count = len(dlpkgs)
        cached_count = 0
        download_total_size = sum(map(lambda x: int(x.downloadSize()), dlpkgs))
        localpkgs = self.localpkgs.keys()

        msger.info("Checking packages cached ...")
        for po in dlpkgs:
            # Check if it is cached locally
            if po.name() in localpkgs:
                cached_count += 1
            else:
                local = self.getLocalPkgPath(po)
                name = str(po.repoInfo().name())
                try:
                    repo = filter(lambda r: r.name == name, self.repos)[0]
                except IndexError:
                    repo = None
                nocache = repo.nocache if repo else False

                if os.path.exists(local):
                    if nocache or self.checkPkg(local) !=0:
                        os.unlink(local)
                    else:
                        download_total_size -= int(po.downloadSize())
                        cached_count += 1
        cache_avail_size = misc.get_filesystem_avail(self.cachedir)
        if cache_avail_size < download_total_size:
            raise CreatorError("No enough space used for downloading.")

        # record the total size of installed pkgs
        install_total_size = sum(map(lambda x: int(x.installSize()), dlpkgs))
        # check needed size before actually download and install

        # FIXME: for multiple partitions for loop type, check fails
        #        skip the check temporarily
        #if checksize and install_total_size > checksize:
        #    raise CreatorError("No enough space used for installing, "
        #                       "please resize partition size in ks file")

        download_count =  total_count - cached_count
        msger.info("Packages: %d Total, %d Cached, %d Missed" \
                   % (total_count, cached_count, download_count))

        try:
            if download_count > 0:
                msger.info("Downloading packages ...")
            self.downloadPkgs(dlpkgs, download_count)
        except CreatorError, e:
            raise CreatorError("Package download failed: %s" %(e,))