Python yum模块无法扫描过时的补丁

时间:2018-02-06 10:32:46

标签: python centos yum

我在centos中使用yum check-update命令来获取更新列表并显示过时的包。     下面是获取更新列表的centos命令,您可以在下面看到一个列表。

[root@CentOS7-G2-3 ~]# yum check-update
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.xmission.com
* extras: linux.mirrors.es.net
* updates: mirror.web-ster.com
Obsoleting Packages
python-gobject-base.x86_64  3.22.0-1.el7_4.1    updates  
pygobject3-base.x86_64  3.14.0-3.el7        @anaconda
rdma-core.i686          13-7.el7        base     
rdma.noarch         7.3_4.7_rc2-6.el7_3 @updates 
rdma-core.x86_64        13-7.el7        base     
rdma.noarch         7.3_4.7_rc2-6.el7_3 @updates

但是当我运行下面的python脚本时,它没有显示任何过时的包。     你能明白为什么它没有显示过时的包裹吗?     有没有办法得到过时的包裹清单?     下面的python代码无法扫描过时的补丁。

import yum
from distutils import version
yumObj = yum.YumBase()
YUM_VER = version.StrictVersion(yum.__version__)
YUM_MAJOR = YUM_VER.version[0]
if YUM_MAJOR == 2:
    yumObj.doTsSetup()
    yumObj.doRepoSetup()
    yumObj.doRepoSetup()
updates = yumObj.doPackageLists('updates').updates
print "updates:"+str(updates)

执行脚本的输出如下:

[root@CentOS7-G2-3 ~]# python
 Python 2.7.5 (default, Aug  4 2017, 00:39:18) 
 [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import yum
 >>> yumObj = yum.YumBase()
 >>> from distutils import version
 >>> YUM_VER = version.StrictVersion(yum.__version__)
 >>> YUM_VER
 StrictVersion ('3.4.3')
 >>> YUM_MAJOR = YUM_VER.version[0]
 >>> YUM_MAJOR
 3
 >>> updates = yumObj.doPackageLists('updates').updates
 Loaded plugins: fastestmirror
 Loading mirror speeds from cached hostfile
  * base: mirrors.xmission.com
  * extras: linux.mirrors.es.net
  * updates: mirror.web-ster.com
 >>> print "updates:"+str(updates)
 updates:[]
 >>> 

0 个答案:

没有答案