fabric学习记录

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))
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值