Search code examples
pythonfabric

Can I use Fabric to workon a virtualenv and run a Python application?


I have virtualenvwrapper and virtualenv installed on an Ubuntu 11.10 machine. I currently use a shell script to workon a virtualenv, and then run a Python application. Something like this:

workon $1
export PYTHONPATH=/media/work/application-$2/src
cd $PYTHONPATH/core
python startapp.py -option1 $3 -option2 $4 --loglevel=INFO

I'd like to switch to Fabric rather than bash (with an eventual goal of making this invocation cross-platform). Can I use Fabric, which is itself a Python application, to make these kinds of calls on the local system? (workon, export, python)


Solution

  • Yup, you can even look at the section in the FAQ related to this very question.

    -- Update --

    With newer versions of Fabric you can now use the prefix() context manager see here