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


Python YumBase.searchPackages方法代码示例

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


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

示例1: main

# 需要导入模块: from yum import YumBase [as 别名]
# 或者: from yum.YumBase import searchPackages [as 别名]
def main(directory, version):
    """
    Update packages in directory and install all those available

    @type  directory: string
    @param directory: path to the directory which contains a copy of the whole system

    @type  version: string
    @param version: PowerKVM version used to update system

    @rtype: boolean
    @returns: True if the packages was successfully updated;
              False otherwise
    """
    os.chroot(directory)

    # update all packages
    yumBase = YumBase()

    # get all enabled repos
    enabledRepos = yumBase.repos.listEnabled()

    # disable all yum repos
    yumBase.repos.disableRepo('*')

    # enable only the powerkvm repo
    yumBase.repos.enableRepo('powerkvm-%s' % version)

    # update system
    yumBase.update()

    rc, msgs = yumBase.buildTransaction()
    if rc != 2:
        return False

    try:
        yumBase.processTransaction()
    except:
        return False

    # check if there is more than one kernel installed
    # if so, remove one
    availableKernels = yumBase.searchPackages(['name'], ['kernel'])
    installedKernels = 0

    for pkg in availableKernels:
        if pkg.repoid == 'installed' and pkg.name == 'kernel':
            installedKernels += 1

    if installedKernels != 1:
        yumBase.remove(name='kernel')

    # install new packages available in the repo
    pkgs = yumBase.doPackageLists().available
    for pkg in pkgs:
        yumBase.install(pkg)

    # build and process the YUM transaction
    rc, msgs = yumBase.buildTransaction()
    if rc != 2:
        return False

    try:
        yumBase.processTransaction()
    except:
        return False

    # re-enable the repos
    for repo in enabledRepos:
        repo.enable()

    return True
开发者ID:bjwt,项目名称:leopard,代码行数:74,代码来源:updatepackages.py


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