静音 Yum API 输出 [英] Silencing Yum API Output

查看:33
本文介绍了静音 Yum API 输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在 python 中静音"yum API 的调试级别.例如,我将两个 yum 命令分配给如下变量;

I am looking to "silence" the debug level of the yum API in python. For example I am assigning two yum commands to variables like below;

import yum
yb = yum.YumBase()

yum_conf = yb.conf.config_file_path
package_list = yb.doPackageLists(pkgnarrow='updates', patterns='', ignore_case=True)

当运行脚本时,它会返回 CentOS 7 的以下内容:

When running the script it comes back with the following for CentOS 7:

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.sov.uk.goscomb.net
* extras: mirror.sov.uk.goscomb.net
* updates: mirror.sov.uk.goscomb.net

然后在 CentOS 6 上:

And then on CentOS 6:

Loaded plugins: fastestmirror
Determining fastest mirrors

我不想要这种冗长的打印水平.我认为这与日志记录级别有关,但我不知道如何改变这一点.

I don't want this verbose level of printing. I'm thinking this is something to do with the logging level, but am at cross path as to how to alter this.

推荐答案

你只需要这两行,

  yb.preconf.debuglevel = 0
  yb.preconf.errorlevel = 0

例如,一个 python scipt,getpkg.py 看起来像下面这样:

e.g., a python scipt, getpkg.py looks something like the following:

  import yum

  yb = yum.YumBase()
  yb.preconf.debuglevel = 0
  yb.preconf.errorlevel = 0
  yb.install(name='emacs-nox')
  yb.resolveDeps()
  yb.processTransaction()

结果:

~]# python getpkg.py 
Installing: 1:perl-parent-0.225-244.el7.noarch 0/8868 [1/32]
Installing: 1:perl-parent-0.225-244.el7.noarch 144/8868 [1/32]
Installing: 1:perl-parent-0.225-244.el7.noarch 2649/8868 [1/32]
Installing: 1:perl-parent-0.225-244.el7.noarch 5686/8868 [1/32]
....
....

这篇关于静音 Yum API 输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆