search

Home  >  Q&A  >  body text

fabric - 怎么使用 python 直接运行 fabfiles, 而不是通过 fab?

是的, 我知道使用 fab 能执行 fabfiles , 但我想通过 python 直接运行 fab task, 而不是通过 fab, 请问该怎么做?

大家讲道理大家讲道理2892 days ago399

reply all(3)I'll reply

  • 巴扎黑

    巴扎黑2017-04-18 09:34:00

    The solution has been found, execute(fab_fun) can be run directly

    reply
    0
  • PHPz

    PHPz2017-04-18 09:34:00

    Encapsulate it into a new script

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 09:34:00

    Same as above, encapsulate the fab command into a script

    test.py script content

    #!/usr/bin/env python
    
    import subprocess
    
    p = subprocess.Popen("/usr/bin/fab uname_a",shell=True)
    p.wait()
    

    fabfile.py content:

    #!/usr/bin/env python
    
    from fabric.api import *
    from fabric.colors import red
    
    env.abort_exception = True
    
    
    def uname_a():
        run("uname -a")  
    

    Originally, fab uname_a was executed to execute the fab command. Now use python test.py

    reply
    0
  • Cancelreply