我在与织物一起工作时正在削减我的牙齿。看起来我对Python和/或Fabric的工作原理有一个基本的误解。我的2个脚本Python /织物误解
看看AppDeploy.py
from fabric.api import *
class AppDeploy:
# Environment configuration, all in a dictionary
environments = {
'dev' : {
'hosts' : ['localhost'],
},
}
# Fabric environment
env = None
# Take the fabric environment as a constructor argument
def __init__(self, env):
self.env = env
# Configure the fabric environment
def configure_env(self, environment):
self.env.hosts.extend(self.environments[environment]['hosts'])
fabfile.py
from fabric.api import *
from AppDeploy import AppDeploy
# Instantiate the backend class with
# all the real configuration and logic
deployer = AppDeploy(env)
# Wrapper functions to select an environment
@task
def env_dev():
deployer.configure_env('dev')
@task
def hello():
run('echo hello')
@task
def dev_hello():
deployer.configure_env('dev')
run('echo hello')
链接第2个任务作品
$ fab env_dev hello
[localhost] Executing task 'hello'
[localhost] run: echo hello
[localhost] out: hello
Done.
Disconnecting from localhost... done.
然而,运行最后的任务,whi CH旨在配置环境,做在一个任务中的东西,看来布没有配置
$ fab dev_hello
No hosts found. Please specify (single) host string for connection:
我敢虽然输了环境,因为如果我调整,像这样
@task
def dev_hello():
deployer.configure_env('dev')
print(env.hosts)
run('echo hello')
该方法
它看起来像env.hosts
是集,不过,织物表现得像是不是:
$ fab dev_hello
['localhost']
No hosts found. Please specify (single) host string for connection:
什么在这里呢?
我能够使用'@ hosts'和'@ with_settings'装饰器来解决这个问题。 – quickshiftin