コード例 #1
0
ファイル: zypppkgmgr.py プロジェクト: xiaoqiang0/mic
 def installLocal(self, pkg, po=None, updateonly=False):
     if not self.ts:
         self.__initialize_transaction()
     solvfile = "%s/.solv" % (self.creator.cachedir)
     rc, out = runner.runtool([fs_related.find_binary_path("rpms2solv"), pkg])
     if rc == 0:
         f = open(solvfile, "w+")
         f.write(out)
         f.close()
         warnmsg = self.repo_manager.loadSolvFile(solvfile , os.path.basename(pkg))
         if warnmsg:
             msger.warning(warnmsg)
         os.unlink(solvfile)
     else:
         msger.warning('Can not get %s solv data.' % pkg)
     hdr = rpmmisc.readRpmHeader(self.ts, pkg)
     arch = zypp.Arch(hdr['arch'])
     if self.creator.target_arch == None:
         # TODO, get the default_arch from conf or detected from global settings
         sysarch = zypp.Arch('i686')
     else:
         sysarch = zypp.Arch(self.creator.target_arch)
     if arch.compatible_with (sysarch):
         pkgname = hdr['name']
         self.localpkgs[pkgname] = pkg
         self.selectPackage(pkgname)
         msger.info("Marking %s to be installed" % (pkg))
     else:
         msger.warning ("Cannot add package %s to transaction. Not a compatible architecture: %s" % (pkg, hdr['arch']))
コード例 #2
0
ファイル: bootstrap.py プロジェクト: sanyaade-mobiledev/mic
    def installPkgs(self):
        for pkg in self.localpkgs.keys():
            rpmpath = self.localpkgs[pkg]

            hdr = readRpmHeader(self.ts, rpmpath)

            # save prein and postin scripts
            self.preins[pkg] = (hdr['PREINPROG'], hdr['PREIN'])
            self.postins[pkg] = (hdr['POSTINPROG'], hdr['POSTIN'])

            # mark pkg as install
            self.ts.addInstall(hdr, rpmpath, 'u')

        # run transaction
        self.ts.order()
        cb = RPMInstallCallback(self.ts)
        self.ts.run(cb.callback, '')
コード例 #3
0
ファイル: bootstrap.py プロジェクト: 01org/mic
    def installPkgs(self):
        for pkg in self.localpkgs.keys():
            rpmpath = self.localpkgs[pkg]

            hdr = readRpmHeader(self.ts, rpmpath)

            # save prein and postin scripts
            self.preins[pkg] = (hdr['PREINPROG'], hdr['PREIN'])
            self.postins[pkg] = (hdr['POSTINPROG'], hdr['POSTIN'])

            # mark pkg as install
            self.ts.addInstall(hdr, rpmpath, 'u')

        # run transaction
        self.ts.order()
        cb = RPMInstallCallback(self.ts)
        errs = self.ts.run(cb.callback, '')

        # ts.run() exit codes are, hmm, "creative": None means all ok, empty 
        # list means some errors happened in the transaction and non-empty 
        # list that there were errors preventing the ts from starting...
        if errs is not None:
             raise errors.BootstrapError("Transaction couldn't start: %s" % '\n'.join(errs))
コード例 #4
0
ファイル: zypppkgmgr.py プロジェクト: 117111302/poky
    def installPkgs(self, package_objects):
        if not self.ts:
            self.__initialize_transaction()

        # clean rpm lock
        self._cleanupRpmdbLocks(self.instroot)
        self._cleanupZyppJunk(self.instroot)
        # 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
                rpmuri = self.get_url(po)
                if rpmuri.startswith("file:/"):
                    rpmpath = rpmuri[5:]

            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.")
コード例 #5
0
ファイル: zypppkgmgr.py プロジェクト: 117111302/poky
    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,))
コード例 #6
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,))
コード例 #7
0
ファイル: zypppkgmgr.py プロジェクト: xiaoqiang0/mic
    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.")
コード例 #8
0
ファイル: zypppkgmgr.py プロジェクト: xiaoqiang0/mic
    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,))