本文整理汇总了Python中yum.YumBase.doPackageLists方法的典型用法代码示例。如果您正苦于以下问题:Python YumBase.doPackageLists方法的具体用法?Python YumBase.doPackageLists怎么用?Python YumBase.doPackageLists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yum.YumBase
的用法示例。
在下文中一共展示了YumBase.doPackageLists方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Copyright
# 需要导入模块: from yum import YumBase [as 别名]
# 或者: from yum.YumBase import doPackageLists [as 别名]
#coding: utf-8
#
# Ailurus - a simple application installer and GNOME tweaker
#
# Copyright (C) 2009-2010, Ailurus developers and Ailurus contributors
# Copyright (C) 2007-2010, Trusted Digital Technology Laboratory, Shanghai Jiao Tong University, China.
#
# Ailurus is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Ailurus is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ailurus; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
import sys
from yum import YumBase
base = YumBase()
ygh = base.doPackageLists()
for available in ygh.available:
name = available.pkgtup[0]
print >>sys.stderr, name # because base.doPackageLists prints text to stdout
示例2: main
# 需要导入模块: from yum import YumBase [as 别名]
# 或者: from yum.YumBase import doPackageLists [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