fabric vs pexpect

前端 未结 3 1140
轻奢々
轻奢々 2021-02-07 08:58

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 some

相关标签:
3条回答
  • 2021-02-07 08:58

    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

    0 讨论(0)
  • 2021-02-07 09:02

    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

    0 讨论(0)
  • 2021-02-07 09:16

    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.

    0 讨论(0)
提交回复
热议问题