我和织物一起工作的时候,我在用Python剪牙。看来我对Python和/或Fabric的工作方式有一个基本的误解。看看我的两个脚本
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')将前两个任务链接起来是可行的
$ fab env_dev hello
[localhost] Executing task 'hello'
[localhost] run: echo hello
[localhost] out: hello
Done.
Disconnecting from localhost... done.但是,运行最后一个任务(它的目的是配置环境并在单个任务中执行某些操作),它似乎没有配置这个环境。
$ 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 是 set,但实际上,fabric的表现并不是这样:
$ fab dev_hello
['localhost']
No hosts found. Please specify (single) host string for connection:这里发生了什么事?
发布于 2013-10-23 22:39:51
我不知道你想做什么,但是.
如果您正在丢失有关shell/environment - Fabric的信息,则需要在单独的shell语句中运行每个命令,因此您需要手动链接这些命令或使用prefix上下文管理器。
请参阅http://docs.fabfile.org/en/1.8/faq.html#my-cd-workon-export-etc-calls-don-t-seem-to-work
如果您在"python“中丢失了信息,那么它可能与我最近遇到的[ https://github.com/fabric/fabric/issues/1004 ]错误/行为有关,在那里,我输入的外壳似乎被抹掉了。
https://stackoverflow.com/questions/19553376
复制相似问题