确定是否使用Yum Python API安装了软件包? [英] Determine if package installed with Yum Python API?

查看:135
本文介绍了确定是否使用Yum Python API安装了软件包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TLDR ;我需要一个简单的Python调用,给出一个包名称(例如"make"),以查看它是否已安装;如果没有,请安装它(我可以做后一部分).

TLDR; I need simple a Python call given a package name (e.g., 'make') to see if it's installed; if not, install it (I can do the latter part).

问题:

因此 http://yum.baseurl.org/wiki/YumCodeSnippets 中提供了一些代码示例,但是除了在ipython内浏览并猜测每种方法的作用之外,似乎没有任何有关yum的Python API的实际文档.显然所有部落知识.

So there are a few code examples given in http://yum.baseurl.org/wiki/YumCodeSnippets, but other than kludging around inside ipython and guessing at what each method does, there doesn't appear to be any actual documentation for the Python API for yum. It's apparently all tribal knowledge.

[edit] 显然,我只是偶然发现了 API文档(当然,在收到可接受的答案之后).它不是从主页链接的,但是在这里供以后参考: http://yum.baseurl.org/api/yum /

[edit] Apparently I just accidentally discovered the API documentation (after receiving an acceptable answer, of course). It's not linked from the main page, but here it is for future reference: http://yum.baseurl.org/api/yum/

我需要做什么:

我有一个部署配置脚本,该脚本依赖于其他系统软件包(make,gcc等).我知道我可以这样安装它们: http://yum.baseurl.org/wiki/YumCodeSnippet/SimplestTransaction 但我想在执行此操作之前先查询是否已安装它们,因此我可以有一个附加选项,即如果不存在这些软件包就简单地失败,而不是强制安装.这样做的正确调用是什么(或者更好的方法是,有没有人真正愿意在代码示例之外适当地记录API?)

I have a deployment configuration script that relies on other system packages (make, gcc, etc.). I know I can install them like this: http://yum.baseurl.org/wiki/YumCodeSnippet/SimplestTransaction but I'd like to have the option to query if they're already installed before doing so, so I can have the additional option of simply failing if the packages aren't present instead of forcing installation. What's the proper call to do this (or better, has anyone actually bothered to properly document the API outside of code samples?)

在这个项目之前,我从未接触过Python,我真的很喜欢它,但是...一些模块文档比骑独角兽的妖精更难以捉摸.

I've never touched Python prior to this project, and I'm really liking it, but... some of the module documentation is more elusive than unicorn-riding leprechauns.

推荐答案

import yum

yb = yum.YumBase()
if yb.rpmdb.searchNevra(name='make'):
   print "installed"
else:
   print "not installed"

这篇关于确定是否使用Yum Python API安装了软件包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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