1、pip show fabric
2、fab --list / fab -l
3、安装fabric
pip install fabric
例子
[root@localhost me]# cat fabfile.py
#!/usr/bin/python
from fabric import Connection
from invoke import task
#@task
#def build(c):
# print("Building!")
@task
def build(c, clean=False):
if clean:
print("Cleaning!")
print("Building!")
@task
def hi(c, name):
print("Hi {}!".format(name))
@task(help={'name': "Name of the person to say hi to."})
def hi(c, name, sex):
"""
Say hi to someone.
"""
print("Hi {}!, {}".format(name, sex))
@task
def build1(c):
c.run("ls")
@task
def connect(c):
c = Connection('192.168.231.131', port=22, user='root', connect_kwargs={'password':'123456'})
c.run('ls')
@task
def svnup(c):
with c.cd("/home/me/project"):
c.run("ls")
c.run("svn up")
@task
def m(c,line,p=False):
for ll in line.split(" "):
with c.cd("/home/me/project/mm"):
c.run("svn up")
a= int(ll)-1
b = "svn merge -r {}:{} svn://localhost/project".format(a,ll)
print(b)
if p :
print("bbb")
c.run(b)
@task
def co(c,line,p=False):
with c.cd("/home/me/project/mm"):
c.run("svn commit -m '{}'".format(line))
@task
def clean(c, docs=False, bytecode=False, extra=''):
patterns = ['build']
if docs:
patterns.append('docs/_build')
if bytecode:
patterns.append('**/*.pyc')
if extra:
patterns.append(extra)
for pattern in patterns:
c.run("rm -rf {}".format(pattern))