我想用Python编写一些Python包安装脚本到virtualenv中。我写一个函数来安装的virtualenv如何在Python中运行上下文感知命令?
def prepareRadioenv():
if not os.path.exists('radioenv'):
print 'Create radioenv'
system('easy_install virtualenv')
system('virtualenv --no-site-package radioenv')
print 'Activate radioenv'
system('source radioenv/bin/activate')
我尝试使用“源radioenv /斌/激活”来激活虚拟环境中,不幸的是,使用os.system创建一个子做的命令。激活所做的环境更改会随着子流程而消失,但不会影响Python进程。问题在于,我如何在Python中执行一些上下文感知命令序列?
又如:
system("cd foo")
system("./bar")
在这里,CD好好尝试影响下面的系统( “条”)。如何让这些环境生活在不同的命令中?
有没有类似上下文感知的shell?所以我可以这样写一些Python代码:
shell = ShellContext()
shell.system("cd bar")
shell.system("./configure")
shell.system("make install")
if os.path.exists('bar'):
shell.system("remove")
谢谢。