织物与预期
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我都用过。 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.
您还可以将它们结合起来,以获得两全其美的效果:结构远程处理功能和提示处理。看看这些答案:https://stackoverflow.com/a/10007635/708221和https://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
两者都有不同的用例。 Fabric 所不具备的 pexpect 功能是保存状态。每个 Fabric api 命令(例如:run/sudo)都是它自己的单独命令。因此,如果您这样做:
这不会位于该目录中,也不会位于 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:
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