本文整理汇总了Python中yum.YumBase.update方法的典型用法代码示例。如果您正苦于以下问题:Python YumBase.update方法的具体用法?Python YumBase.update怎么用?Python YumBase.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yum.YumBase
的用法示例。
在下文中一共展示了YumBase.update方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from yum import YumBase [as 别名]
# 或者: from yum.YumBase import update [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