当前位置: 首页>>代码示例>>Python>>正文


Python YumBase.downloadPkgs方法代码示例

本文整理汇总了Python中yum.YumBase.downloadPkgs方法的典型用法代码示例。如果您正苦于以下问题:Python YumBase.downloadPkgs方法的具体用法?Python YumBase.downloadPkgs怎么用?Python YumBase.downloadPkgs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yum.YumBase的用法示例。


在下文中一共展示了YumBase.downloadPkgs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _run_transaction

# 需要导入模块: from yum import YumBase [as 别名]
# 或者: from yum.YumBase import downloadPkgs [as 别名]
def _run_transaction(transaction_name, install_mode, remove_mode):
    import os
    from yum import YumBase

    transaction = open(os.path.join(config.STACKDIR, transaction_name),
            'r')

    my_yum = YumBase()
    
    for line in transaction:
        line = line.strip()
        parts = line.split(' ')
        if parts[0] == install_mode:
            fn = my_yum.install
        elif parts[0] == remove_mode:
            fn = my_yum.remove
        else:
            assert False, "corrupt transaction file"

        if parts[2] == 'None':
            parts[2] = None
        fn(name=parts[1], epoch=parts[2], version=parts[3],
                release=parts[4], arch=parts[5])

    dlpkgs = map(lambda x: x.po, filter(lambda txmbr:
                                        txmbr.ts_state in ("i", "u"),
                                        my_yum.tsInfo.getMembers()))
    my_yum.downloadPkgs(dlpkgs)

    my_yum.initActionTs() # make a new, blank ts to populate
    my_yum.populateTs(keepold=0)
    my_yum.ts.check() #required for ordering
    my_yum.ts.order() # order

    # FIXME: is it really sane to use this from here?
    import sys
    sys.path.append('/usr/share/yum-cli')
    import callback

    cb = callback.RPMInstallCallback(output = 0)
    cb.filelog = True
    cb.tsInfo = my_yum.tsInfo
    my_yum.runTransaction(cb)
开发者ID:jbowes,项目名称:yq,代码行数:45,代码来源:yumbackend.py

示例2: YumDebugInfoDownload

# 需要导入模块: from yum import YumBase [as 别名]
# 或者: from yum.YumBase import downloadPkgs [as 别名]

#.........这里部分代码省略.........
                repo.close()
                self.base.repos.disableRepo(repo.id)
            except YumBaseError as ex:
                print(_("Can't disable repository '{0!s}': {1!s}").format(repo.id, str(ex)))

    def initialize_repositories(self):
        # setting-up repos one-by-one, so we can skip the broken ones...
        # this helps when users are using 3rd party repos like rpmfusion
        # in rawhide it results in: Can't find valid base url...
        for r in self.base.repos.findRepos(pattern=self.repo_pattern):
            try:
                rid = self.base.repos.enableRepo(r.id)
                self.base.repos.doSetup(thisrepo=str(r.id))
                log1("enabled repo %s", rid)
                setattr(r, "skip_if_unavailable", True)
                # yes, we want async download, otherwise our progressCallback
                # is not called and the internal yum's one  is used,
                # which causes artifacts on output
                try:
                    setattr(r, "_async", False)
                except (NameError, AttributeError) as ex:
                    print(str(ex))
                    print(_("Can't disable async download, the output might contain artifacts!"))
            except YumBaseError as ex:
                print(_("Can't setup {0}: {1}, disabling").format(r.id, str(ex)))
                self.base.repos.disableRepo(r.id)

        # This is somewhat "magic", it unpacks the metadata making it usable.
        # Looks like this is the moment when yum talks to remote servers,
        # which takes time (sometimes minutes), let user know why
        # we have "paused":
        try:
            self.base.repos.populateSack(mdtype='metadata', cacheonly=1)
        except YumBaseError as ex:
            print(_("Error retrieving metadata: '{0!s}'").format(str(ex)))
            #we don't want to die here, some metadata might be already retrieved
            # so there is a chance we already have what we need
            #return 1

        try:
            # Saw this exception here:
            # raise Errors.NoMoreMirrorsRepoError, errstr
            # NoMoreMirrorsRepoError: failure:
            # repodata/7e6632b82c91a2e88a66ad848e231f14c48259cbf3a1c3e992a77b1fc0e9d2f6-filelists.sqlite.bz2
            # from fedora-debuginfo: [Errno 256] No more mirrors to try.
            self.base.repos.populateSack(mdtype='filelists', cacheonly=1)
        except YumBaseError as ex:
            print(_("Error retrieving filelists: '{0!s}'").format(str(ex)))
            # we don't want to die here, some repos might be already processed
            # so there is a chance we already have what we need
            #return 1

    def triage(self, files):
        not_found = []
        package_files_dict = {}
        todownload_size = 0
        installed_size = 0
        for debuginfo_path in files:
            log2("yum whatprovides %s", debuginfo_path)
            pkg = self.base.pkgSack.searchFiles(debuginfo_path)
            # sometimes one file is provided by more rpms, we can use either of
            # them, so let's use the first match
            if pkg:
                if pkg[0] in package_files_dict.keys():
                    package_files_dict[pkg[0]].append(debuginfo_path)
                else:
                    package_files_dict[pkg[0]] = [debuginfo_path]
                    todownload_size += float(pkg[0].size)
                    installed_size += float(pkg[0].installedsize)

                log2("found pkg for %s: %s", debuginfo_path, pkg[0])
            else:
                log2("not found pkg for %s", debuginfo_path)
                not_found.append(debuginfo_path)

        return (package_files_dict, not_found, todownload_size, installed_size)

    def download_package(self, pkg):
        remote = pkg.returnSimple('relativepath')
        local = os.path.basename(remote)
        local = os.path.join(self.tmpdir, local)

        remote_path = pkg.returnSimple('remote_url')
        # check if the pkg is in a local repo and copy it if it is
        err = None
        if remote_path.startswith('file:///'):
            pkg_path = remote_path[7:]
            log2("copying from local repo: %s", remote)
            try:
                shutil.copy(pkg_path, local)
            except OSError as ex:
                err = _("Cannot copy file '{0}': {1}").format(pkg_path, str(ex))
        else:
            # pkg is in a remote repo, we need to download it to tmpdir
            pkg.localpath = local # Hack: to set the localpath we want
            err = self.base.downloadPkgs(pkglist=[pkg])

        # normalize the name
        # just str(pkg) doesn't work because it can have epoch
        return (local, err)
开发者ID:scottgfhong,项目名称:libreport,代码行数:104,代码来源:yumdebuginfo.py


注:本文中的yum.YumBase.downloadPkgs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。