简体   繁体   English

Python Fabric-在virtualenv的postactivate中读取环境变量

[英]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. 目前它们位于.bashrc中,也位于我的virtualenv的postactivate文件中-也位于我的各种超级用户配置文件中。

I'm wondering if it is possible to read either one of these files and set these environment variables in Fabric before running commands. 我想知道是否可以在运行命令之前读取这些文件之一并在Fabric中设置这些环境变量。

I'm basically calling manage.py commands like this: 我基本上是这样调用manage.py命令的:

/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. 我了解到我也可以将这些文件放在.bash_profile中,但这只是我不必维护的另一个地方。

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. 我不知道这是否是最好的解决方案,但是我现在所做的是将环境变量的导出命令移至.bash_profile中。

I removed them from .bashrc & my virtualenv postactivate file and replaced them with: 我从.bashrc和我的virtualenv postactivate文件中删除了它们,并将它们替换为:

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. 现在,我将它们全部放在一个位置,并且在登录,激活virtualenv和使用结构时设置了环境变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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