-
-
Save peshmerge/d17d80795cde89ec01e1a1de41dace22 to your computer and use it in GitHub Desktop.
A common use case in a Fabric script is to: 1. Activate the virtualenv 2. cd to the project dir Here is a simple context manager to achieve this with a one line with statement:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A common use case in a Fabric script is to: | |
1. Activate the virtualenv | |
2. cd to the project dir | |
Here is a simple context manager to achieve this with a one line with statement: | |
""" | |
# fabconfig.py | |
def dev(): | |
env.build = 'dev' | |
env.virtualenv = '/path/to/ve/' | |
env.activate = 'source %(virtualenv)s/bin/activate' % env | |
env.code_dir = '/var/www/sap/gsa/builds/%(build)s' % env | |
# fabfile.py | |
from fabric.api import prefix | |
from contextlib import contextmanager as _contextmanager | |
@_contextmanager | |
def virtualenv(): | |
with cd(env.virtualenv), prefix(env.activate), cd(env.code_dir): | |
yield | |
def test_management_command(): | |
with virtualenv(): | |
run('./manage.py solr update_all') | |
# local shell | |
fab dev solr_update_all |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment