简体   繁体   中英

Python Fabric - read environment variables in virtualenv's postactivate

I have a number of environment variables on my server. Currently they are in .bashrc and also in my virtualenv's postactivate file - also in my various supervisor config files.

I'm wondering if it is possible to read either one of these files and set these environment variables in Fabric before running commands.

I'm basically calling manage.py commands like this:

/path/to/virtuaenv/python /path/to/manage.py command --settings=proj.settings.prod

I learned that I can also put these files in .bash_profile, but it's just one more place I don't what to have to maintain.

Any tips on how I can do this in fabric - and possibly even consolidating them into one place?

I don't know if this is the best solution, but what I have done for now is moved my export commands for environment variables into .bash_profile.

I removed them from .bashrc & my virtualenv postactivate file and replaced them with:

source /path/to/.bash_profile

Now I have them all in one place and the environment variables are set when I log in, when I activate my virtualenv and when I use fabric.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM