面料 - 项目路径环境
问题描述:
让我们考虑这个fabfile面料 - 项目路径环境
def syncdb():
print(green("Database Synchronization ..."))
with cd('/var/www/project'):
sudo('python manage.py syncdb', user='www-data')
def colstat():
print(green("Collecting Static Files..."))
with cd('/var/www/project'):
sudo('python manage.py collectstatic --noinput', user='www-data')
def httpdrst():
print(green("Restarting Apache..."))
sudo('apachectl restart')
def srefresh():
colstat()
syncdb()
httpdrst()
的srefresh
指令要求所有的人,其中某些with cd(...)
什么是有这样的“CD路径”的最佳途径在一个变量?
def colstat():
with cd(env.remote['path']):
def srefresh():
env.remote['path'] = '/var/www/project'
colstat()
syncdb()
httpdrst()
这样的事情?
答
我只是将该变量作为参数传递给函数。
def syncdb(path):
print(green("Database Synchronization ..."))
with cd(path):
sudo('python manage.py syncdb', user='www-data')
def colstat(path):
print(green("Collecting Static Files..."))
with cd(path):
sudo('python manage.py collectstatic --noinput', user='www-data')
def httpdrst():
print(green("Restarting Apache..."))
sudo('apachectl restart')
def srefresh():
path = '/var/www/project'
colstat(path)
syncdb(path)
httpdrst()
答
不知道这是一个很好的做法,但它似乎做与
env.remote_path = '/var/www/project'
def colstat():
with cd(env.remote_path):
#...
def srefresh():
env.remote_path = '/var/www/other_project'
pushpull()
colstat()
#...
作业可能无法适用于织物,但... – enderskill 2012-03-29 15:13:20
这应该工作在织物上就好了。如果您仍然想用'fab command'调用它们而不需要指定参数,只需给它们一个默认值即可。 – Wilduck 2012-03-29 15:59:13
工作,但问题是我不能独立调用'syncdb','colstat' – 2012-03-30 11:26:01