English 中文(简体)
在分处理阶段之间保持环境状态。 开放指挥?
原标题:Maintaining environment state between subprocess.Popen commands?

我为我们的系统撰写一个部署引擎,每个项目都具体说明他的习惯部署指示。

这些节点在EC2上。

其中一个项目取决于第三人申请的来源版本。

具体地说:

cd /tmp
wget s3://.../tools/x264_20_12_2010.zip
unzip x264_20_12_2010.zip
cd x264_20_12_2010
./configure
make
checkinstall --pkgname=x264 --pkgversion "2:0.HEAD" --backup=no --deldoc=yes --fstrans=no --default

目前,Im用同位素壳体做这项工作(使用分处理)。 在内部开放,这样看:

def deploy():
        ShellCommand("apt-get remove ffmpeg x264 libx264-dev")
        ShellCommand("apt-get update")
        ShellCommand("apt-get install -y build-essential checkinstall yasm texi2html libfuse-dev fuse-utils libcurl4-openssl-dev libxml2-dev mime-support libfaac-dev libjack-jackd2-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev libvorbis-dev libvpx-dev libx11-dev libxfixes-dev libxvidcore-dev zlib1g-dev")

        ShellCommand("cd /tmp")
        s3cmd_sync("s3://.../tools/x264_20_12_2010.zip", "/tmp/x264_20_12_2010.zip")
        ShellCommand("unzip x264_20_12_2010.zip")
        ShellCommand("cd x264_20_12_2010")
        ShellCommand("./configure")
        ShellCommand("make")
        ShellCommand(r checkinstall --pkgname=x264 --pkgversion "2:0.HEAD" --backup=no --deldoc=yes --fstrans=no --default )

可悲的是,这失败了,因为cd /tmp 适用于分处理,这意味着一旦我回到父亲的程序中,签发第二个壳牌照,则从父亲继承,而父亲们认为,我需要一些弹道执行框架,在同一个分处理过程中,在无漏洞的情况下适用所有指挥。

如何建议解决这一问题? 请注意,执行指挥线的伐木非常重要(你怎么能够不做ug事),这就是为什么我喜欢壳牌公司......(如果有兴趣的话,请参看博托伐木)。

Thank you,
Maxim.

最佳回答

我就此结束发言。

def shell_script(appname, *commands):
        workspace = tempfile.mkdtemp(prefix=appname +  - )
        installer = open(workspace + "/installer.sh",  w )

        installer.write("#!/bin/bash
")
        installer.write("cd " + workspace + "
")
        for line in commands:
                installer.write(line + "
")
        ShellCommand("chmod u+x " + installer.name)
        installer.close()
        ShellCommand(installer.name)
问题回答
  1. 2. 不要开(“d DIRECTORY”)

  2. Maybe it s best here not to execute a new shell for each command: Just write one multi-line shell skript

deploy_commands = """apt-get foo apt-get bar cd baz ; boo bat"""

最终通过P open(deploy_commands, Shell=True)执行。

但是,请阅读开放文件中关于不放弃不信任参数的安全警告。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签