如何将字符串或列表对象作为参数传递给fabric?

时间:2014-10-07 21:23:22

标签: python fabric

我遇到的问题是我的字符串长了几个字,实际上包含'字符......所以我不知道如何传递我想要的字符串。

我试图这样做:

fab -H myhost.serv.com execute:"nc -zw1 159.1.1.1 9988 | gawk '{print $7}'","nc -zw1 159.1.1.2 9988 | gawk '{print $7}'"

但是,这会吐出来:

Executing task 'execute'
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/fabric/main.py", line 743, in main
    *args, **kwargs
  File "/usr/lib/python2.7/dist-packages/fabric/tasks.py", line 368, in execute
    multiprocessing
  File "/usr/lib/python2.7/dist-packages/fabric/tasks.py", line 264, in _execute
    return task.run(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/fabric/tasks.py", line 171, in run
    return self.wrapped(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/fabric/decorators.py", line 175, in real_decorator
    @wraps(func)
  File "/usr/lib/python2.7/functools.py", line 33, in update_wrapper
    setattr(wrapper, attr, getattr(wrapped, attr))
AttributeError: 'str' object has no attribute '__module__'

这有什么办法吗?我是从python脚本中调用它的:

fabcmd = 'fab -H ' + ','.join(servlist) + ' execute:'
for cmd in commands:
    fabcmd += "\"{}\",".format(cmd)
print fabcmd
subprocess.call(fabcmd)

如果有办法将我的命令列表对象传递给Fabric,那实际上是理想的......所以我可以做一些像......

fabcmd = 'fab -H ' + ','.join(servlist) + ' execute:' + commands`

1 个答案:

答案 0 :(得分:0)

显然,这里的答案与上面发布的任何内容无关 - 我的fabfile.py中的装饰者排序错误:

<强>原始

from fabric.api import parallel, task

@parallel
@task
def execute(*args):
    print args

<强>修饰

from fabric.api import parallel, task

@task
@parallel
def execute(*args):
    print args

我不知道为什么这很重要......所以,如果有人能够解释,那就是超级。