如何在特定环境下运行fabric命令
我在模块中定义了不同的环境:
中的 __init__.py
def localdev():
"""
Work on local dev environment
"""
env.db_credentials = {'user':'username', 'pass':'passs','name':'mydb'}
env.uwsgi_command = 'uwsgi'
env.settings = 'local_dev'
env.hosts = ['dev@localhost']
dev production():
pass
deploy.py
from __future__ import with_statement
import os
from fabric.api import *
from fabric.decorators import task
@task
def flush_cache(environment, ):
"""
Clear memcached cache
"""
sudo('/etc/init.d/memcached restart', pty=True)
fabfile.py
from mymodule import *
我现在应该如何在 localdev 环境中运行代码?
fab localdev deploy.flush_cache
Fatal error: Command(s) not found:
localdev
Aborting.
谢谢!
I defined different environments in my module :
__init__.py
def localdev():
"""
Work on local dev environment
"""
env.db_credentials = {'user':'username', 'pass':'passs','name':'mydb'}
env.uwsgi_command = 'uwsgi'
env.settings = 'local_dev'
env.hosts = ['dev@localhost']
dev production():
pass
in deploy.py
from __future__ import with_statement
import os
from fabric.api import *
from fabric.decorators import task
@task
def flush_cache(environment, ):
"""
Clear memcached cache
"""
sudo('/etc/init.d/memcached restart', pty=True)
fabfile.py
from mymodule import *
How should I run my code in my localdev environment now ?
fab localdev deploy.flush_cache
Fatal error: Command(s) not found:
localdev
Aborting.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
需要在fabfile.py中导入init.py。传递给 Fabric 的参数用作 fabfile.py 中的函数名称。由于您不导入模块,因此该函数不存在,因此您会收到命令未找到错误。
You need to import init.py in fabfile.py. Arguments passed to fabric are used as function names in fabfile.py. As you don't import the module the function doesn't exist and so you get the command not found error.