确定是否使用 Yum Python API 安装了软件包?
TLDR;我需要一个简单的 Python 调用,给出一个包名称(例如“make”)来查看它是否已安装;如果没有,请安装它(我可以做后一部分)。
问题:
http://yum.baseurl.org/wiki/ 中给出了一些代码示例YumCodeSnippets,但除了在 ipython 内部乱七八糟并猜测每个方法的作用之外,似乎没有任何关于 yum 的 Python API 的实际文档。这显然都是部落知识。
[编辑] 显然,我只是偶然发现了 API 文档(当然是在收到可接受的答案之后)。它没有从主页链接,但供将来参考: http://yum.baseurl.org/api/yum /
我需要做什么:
我有一个依赖于其他系统包(make、gcc等)的部署配置脚本。我知道我可以像这样安装它们: http://yum.baseurl.org/wiki/YumCodeSnippet/SimplestTransaction但我希望可以选择在执行此操作之前查询它们是否已安装,这样我就可以选择在软件包不存在时简单地失败而不是强制安装。执行此操作的正确调用是什么(或者更好的是,是否有人真正费心在代码示例之外正确记录 API?)
在这个项目之前我从未接触过 Python,而且我真的很喜欢它,但是......一些模块文档的内容比骑着独角兽的妖精更难以捉摸。
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).
Problem:
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] 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/
What I need to do:
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?)
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以在子系统上运行“which”来查看系统是否具有您正在查找的二进制文件:
You could run 'which' on the subsystem to see if the system has the binaries you are looking for:
对于后来偶然发现这篇文章的人,这就是我的想法。请注意,“testing”和“skip_install”是我从脚本调用中解析的标志。
For anyone who stumbles across this post later, here's what I came up with. Note that "testing" and "skip_install" are flags that I parse from the script invocation.