给定一个 rpm 包名,查询 yum 数据库以获取更新 [英] Given an rpm package name, query the yum database for updates

查看:35
本文介绍了给定一个 rpm 包名,查询 yum 数据库以获取更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在想象一个 3 行 Python 脚本来执行此操作,但 yum Python API 是难以理解的.这甚至可能吗?

I was imagining a 3-line Python script to do this but the yum Python API is impenetrable. Is this even possible?

为yum list package-name"编写包装器是唯一的方法吗?

Is writing a wrapper for 'yum list package-name' the only way to do this?

推荐答案

正如 Seth 所指出的,您可以使用更新 API 来询问是否有可用的更新.对于接近yum 列表"的内容,您可能想要使用 doPackageLists().例如.

As Seth points out, you can use the updates APIs to ask if something is available as an update. For something that's close to what the "yum list" does you probably want to use the doPackageLists(). Eg.

import os, sys
import yum

yb = yum.YumBase()
yb.conf.cache = os.geteuid() != 1
pl = yb.doPackageLists(patterns=sys.argv[1:])
if pl.installed:
    print "Installed Packages"
    for pkg in sorted(pl.installed):
        print pkg
if pl.available:
    print "Available Packages"
    for pkg in sorted(pl.available):
        print pkg, pkg.repo
if pl.reinstall_available:
    print "Re-install Available Packages"
    for pkg in sorted(pl.reinstall_available):
        print pkg, pkg.repo

这篇关于给定一个 rpm 包名,查询 yum 数据库以获取更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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