Reputation: 46158
Let's consider this 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()
The srefresh
directive calls all the others, certain of which with cd(...)
What would be the best way to have this 'cd path' in a variable ?
def colstat():
with cd(env.remote['path']):
def srefresh():
env.remote['path'] = '/var/www/project'
colstat()
syncdb()
httpdrst()
Something like that ?
Upvotes: 0
Views: 520
Reputation: 46158
Not sure it's a good practice but it seems to do the job with that
env.remote_path = '/var/www/project'
def colstat():
with cd(env.remote_path):
#...
def srefresh():
env.remote_path = '/var/www/other_project'
pushpull()
colstat()
#...
Upvotes: 0
Reputation: 7674
I would just pass the variable to the functions as an argument.
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()
Upvotes: 2