织物与预期

发布于 2024-10-02 19:35:07 字数 239 浏览 4 评论 0原文

我偶然发现了 pexpect ,我的印象是它看起来与 织物。我试图找到一些比较,但没有成功,所以我在这里询问——以防有人对这两种工具都有经验。

我的印象(它们大致相当)是正确的,还是只是表面上的样子?

I've stumbled upon pexpect and my impression is that it looks roughly similar to fabric. I've tried to find some comparison, without success, so I'm asking here--in case someone has experience with both tools.

Is my impression (that they are roughly equivalent) correct, or it's just how it looks on the surface ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

染年凉城似染瑾 2024-10-09 19:35:07

我都用过。 Fabric 比 pexpect 更高级别,恕我直言,要好得多。这取决于您使用它的目的,但如果您的用途是部署和配置软件,那么 Fabric 是正确的选择。

I've used both. Fabric is more high level than pexpect, and IMHO a lot better. It depends what you're using it for, but if your use is deployment and configuration of software then Fabric is the right way to go.

你在我安 2024-10-09 19:35:07

您还可以将它们结合起来,以获得两全其美的效果:结构远程处理功能和提示处理。看看这些答案:https://stackoverflow.com/a/10007635/708221https://stackoverflow.com/a/9614913/708221

You can also combine them, to have the best of both worlds, fabrics remoting capabilities and pexpects handling of prompts. Have a look at these answers: https://stackoverflow.com/a/10007635/708221 and https://stackoverflow.com/a/9614913/708221

假装爱人 2024-10-09 19:35:07

两者都有不同的用例。 Fabric 所不具备的 pexpect 功能是保存状态。每个 Fabric api 命令(例如:run/sudo)都是它自己的单独命令。因此,如果您这样做:

run("cd project_dir && workon project")
run("make")

这不会位于该目录中,也不会位于 virtualenv 中。虽然现在 Fabric 中有 cd() 的上下文管理器,但它们或多或少会在每次运行前加上 cd。

从总体上看,这与大多数项目的运作方式关系不大,而且基本上没有被注意到。但是,对于某些需要,您可以使用 pexpect 来管理此状态,例如多个 sudo 或某种无法使用标志自动化的交互式任务。

不过,所有这些对于 Fabric 来说都不是缺点,因为它只是 Python,所以您完全能够在 Fabric 任务中包含 pexpect 代码。

尽管在所有其他方面,Fabric 本质上都比您使用 pexpect 从头开始​​编写代码更好地管理远程连接和运行命令的所有艰苦工作。

更新 我已获悉有一个与 Fabric 和 pexpect 配合使用的项目,您可以查看有关此问题的更多信息回答

There are different use cases for both. Something that pexpect does that Fabric doesn't is preserving state. Each Fabric api command (eg: run/sudo) is it's own individual command. So if you do:

run("cd project_dir && workon project")
run("make")

This won't be in that directory nor will it be in the virtualenv. While there are context managers for cd() in Fabric now, they're more or less prepending each run with a cd.

In the scheme of things this has little bearing on how the majority of projects work, and is essentially unnoticed. For some needs however you might use pexpect to manage this state, for multiple sudos or some sort of interactive task that can't be automated with flags.

All of this though isn't a demerit for Fabric, as being only python, you're more than able to include pexpect code inside fabric tasks.

Though in all other ways, Fabric essentially manages all the hard work of remote connections and running commands better than you'd get writing code from the ground up with pexpect.

Update I've been informed of a project that works with Fabric and pexepect, you can see more on this question's answer

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文