Python - Fabric - 获取文件

Python - Fabric - Getting files

我正在尝试使用 fabric 编写一个简单的 python 代码,使用 get() 函数将文件从一台主机传输到另一台主机,尽管我不断收到错误消息:

MacBook-Pro-3:PythonsScripts$ fab get:'/tmp/test','/tmp/test'
[hostname] Executing task 'get'
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/fabric/main.py", line 743, in main
   *args, **kwargs
  File "/Library/Python/2.7/site-packages/fabric/tasks.py", line 387, in execute
    multiprocessing
  File "/Library/Python/2.7/site-packages/fabric/tasks.py", line 277, in _execute
    return task.run(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/fabric/tasks.py", line 174, in run
    return self.wrapped(*args, **kwargs)
  File "/Users/e0126914/Desktop/PYTHON/PythonsScripts/fabfile.py", line 128, in get
    get('/tmp/test','/tmp/test') ***This line repeats many times then last error below***
RuntimeError: maximum recursion depth exceeded

我当前的代码是:

from fabric.api import *
from getpass import getpass
from fabric.decorators import runs_once

env.hosts = ['hostname']
env.port = '22'
env.user = 'parallels'
env.password="password"


def abc(remote_path, local_path):
    abc('/tmp/test','/tmp/')

如有任何帮助,我们将不胜感激!

fabric.api.get已经是一个方法了。当您执行 from fabric.api import * 时,您正在导入 fabricget。您应该重命名 get 函数以避免冲突。

abc 函数内部,您需要调用 get

def abc(p1,p2):
    get(p1, p2)

编辑: 通过 fabric 执行函数时,参数通过命令行传递 IE。 $ fab abc:string1,string2