本文整理汇总了Python中os.spawnvpe方法的典型用法代码示例。如果您正苦于以下问题:Python os.spawnvpe方法的具体用法?Python os.spawnvpe怎么用?Python os.spawnvpe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.spawnvpe方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: winexe
# 需要导入模块: import os [as 别名]
# 或者: from os import spawnvpe [as 别名]
def winexe(cmd):
check_tool('winexe')
creds = '%s/%s%%%s' % (CONF['smb_domain'], CONF['smb_user'], CONF['smb_pass'])
run = []
run.append(TOOLS['winexe'])
if CONF['system']:
run.append('--system')
run.append('--uninstall')
run.append('--interactive=0')
run.append('-U')
run.append(creds)
run.append('//'+ CONF['smb_ip'])
run.append(cmd)
if not cmd.lower().startswith('cmd'):
process = subprocess.Popen(run, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT)
ret = process.stdout.read()
ret = ret.replace('\x00', '')
return ret.strip()
# For an interactive command line, don't use popen
os.spawnvpe(os.P_WAIT, run[0], run, os.environ)
return ''
示例2: open_text_editor
# 需要导入模块: import os [as 别名]
# 或者: from os import spawnvpe [as 别名]
def open_text_editor(data):
if data is None:
data = ""
fd, path = tempfile.mkstemp()
os.close(fd)
with open(path, 'w') as output:
output.write(data)
# Get modified time before calling editor.
orig_mtime = os.path.getmtime(path)
editor = os.environ.get("EDITOR", "vim")
os.spawnvpe(os.P_WAIT, editor, [editor, path], os.environ)
with open(path, 'r') as source:
data = source.read()
# Check if the file has been modified, and if it has, send the update.
new_mtime = os.path.getmtime(path)
if new_mtime == orig_mtime:
data = None
os.remove(path)
return data
示例3: open_yaml_editor
# 需要导入模块: import os [as 别名]
# 或者: from os import spawnvpe [as 别名]
def open_yaml_editor(data, description):
if data is None:
data = {}
fd, path = tempfile.mkstemp()
os.close(fd)
with open(path, 'w') as output:
if len(data) > 0:
output.write(yaml.safe_dump(data, default_flow_style=False))
output.write("\n")
output.write("# You are editing the configuration for the {}.\n".format(description))
output.write("# Blank lines and lines starting with '#' will be ignored.\n")
output.write("# Save and exit to apply changes; exit without saving to discard.\n")
# Get modified time before calling editor.
orig_mtime = os.path.getmtime(path)
editor = os.environ.get("EDITOR", "vim")
os.spawnvpe(os.P_WAIT, editor, [editor, path], os.environ)
with open(path, 'r') as source:
data = source.read()
new_data = yaml.safe_load(data)
# If result is null, convert to an empty dict before sending to router.
if new_data is None:
new_data = {}
# Check if the file has been modified.
new_mtime = os.path.getmtime(path)
changed = (new_mtime != orig_mtime)
os.remove(path)
return new_data, changed
示例4: shell
# 需要导入模块: import os [as 别名]
# 或者: from os import spawnvpe [as 别名]
def shell(ctx):
"""
Open a shell inside a chute.
This requires you to have enabled SSH access to the device and installed
bash inside your chute.
"""
cmd = ["ssh", "-t", "paradrop@{}".format(ctx.obj['address']), "sudo", "docker",
"exec", "-it", ctx.obj['chute'], "/bin/bash"]
os.spawnvpe(os.P_WAIT, "ssh", cmd, os.environ)
示例5: edit
# 需要导入模块: import os [as 别名]
# 或者: from os import spawnvpe [as 别名]
def edit(ctx):
"""
Interactively edit the host configuration.
"""
url = ctx.obj['base_url'] + "/config/hostconfig"
req = router_request("GET", url, dump=False)
config = req.json()
fd, path = tempfile.mkstemp()
os.close(fd)
with open(path, 'w') as output:
output.write(yaml.safe_dump(config, default_flow_style=False))
# Get modified time before calling editor.
orig_mtime = os.path.getmtime(path)
editor = os.environ.get("EDITOR", "vim")
os.spawnvpe(os.P_WAIT, editor, [editor, path], os.environ)
with open(path, 'r') as source:
data = source.read()
config = yaml.safe_load(data)
# Check if the file has been modified, and if it has, send the update.
new_mtime = os.path.getmtime(path)
if new_mtime != orig_mtime:
data = {
'config': config
}
res = router_request("PUT", url, json=data)
result = res.json()
ctx.invoke(watch, change_id=result['change_id'])
os.remove(path)
示例6: test_spawnvpe_invalid_env
# 需要导入模块: import os [as 别名]
# 或者: from os import spawnvpe [as 别名]
def test_spawnvpe_invalid_env(self):
self._test_invalid_env(os.spawnvpe)
示例7: exec_spawnvpe
# 需要导入模块: import os [as 别名]
# 或者: from os import spawnvpe [as 别名]
def exec_spawnvpe(l, env):
stat = os.spawnvpe(os.P_WAIT, l[0], l, env)
# os.spawnvpe() returns the actual exit code, not the encoding
# returned by os.waitpid() or os.system().
return stat
示例8: create_spawnve
# 需要导入模块: import os [as 别名]
# 或者: from os import spawnvpe [as 别名]
def create_spawnve(original_name):
"""
os.spawnve(mode, path, args, env)
os.spawnvpe(mode, file, args, env)
"""
def new_spawnve(mode, path, args, env):
if _get_apply_arg_patching():
args = patch_args(args)
send_process_created_message()
return getattr(os, original_name)(mode, path, args, env)
return new_spawnve
示例9: patch_new_process_functions_with_warning
# 需要导入模块: import os [as 别名]
# 或者: from os import spawnvpe [as 别名]
def patch_new_process_functions_with_warning():
monkey_patch_os('execl', create_warn_multiproc)
monkey_patch_os('execle', create_warn_multiproc)
monkey_patch_os('execlp', create_warn_multiproc)
monkey_patch_os('execlpe', create_warn_multiproc)
monkey_patch_os('execv', create_warn_multiproc)
monkey_patch_os('execve', create_warn_multiproc)
monkey_patch_os('execvp', create_warn_multiproc)
monkey_patch_os('execvpe', create_warn_multiproc)
monkey_patch_os('spawnl', create_warn_multiproc)
monkey_patch_os('spawnle', create_warn_multiproc)
monkey_patch_os('spawnlp', create_warn_multiproc)
monkey_patch_os('spawnlpe', create_warn_multiproc)
monkey_patch_os('spawnv', create_warn_multiproc)
monkey_patch_os('spawnve', create_warn_multiproc)
monkey_patch_os('spawnvp', create_warn_multiproc)
monkey_patch_os('spawnvpe', create_warn_multiproc)
monkey_patch_os('posix_spawn', create_warn_multiproc)
if not IS_JYTHON:
if not IS_WINDOWS:
monkey_patch_os('fork', create_warn_multiproc)
try:
import _posixsubprocess
monkey_patch_module(_posixsubprocess, 'fork_exec', create_warn_fork_exec)
except ImportError:
pass
else:
# Windows
try:
import _subprocess
except ImportError:
import _winapi as _subprocess
monkey_patch_module(_subprocess, 'CreateProcess', create_CreateProcessWarnMultiproc)
示例10: execve_from
# 需要导入模块: import os [as 别名]
# 或者: from os import spawnvpe [as 别名]
def execve_from(self, conf, cmd, env):
""" this code is commonly run in a child process // returns exit-code"""
runs = conf.get("Service", "Type", "simple").lower()
logg.debug("%s process for %s", runs, conf.filename())
inp = open("/dev/zero")
out = self.open_journal_log(conf)
os.dup2(inp.fileno(), sys.stdin.fileno())
os.dup2(out.fileno(), sys.stdout.fileno())
os.dup2(out.fileno(), sys.stderr.fileno())
runuser = self.expand_special(conf.get("Service", "User", ""), conf)
rungroup = self.expand_special(conf.get("Service", "Group", ""), conf)
envs = shutil_setuid(runuser, rungroup)
badpath = self.chdir_workingdir(conf) # some dirs need setuid before
if badpath:
logg.error("(%s): bad workingdir: '%s'", shell_cmd(cmd), badpath)
sys.exit(1)
env = self.extend_exec_env(env)
env.update(envs) # set $HOME to ~$USER
try:
if "spawn" in COVERAGE:
os.spawnvpe(os.P_WAIT, cmd[0], cmd, env)
sys.exit(0)
else: # pragma: nocover
os.execve(cmd[0], cmd, env)
except Exception as e:
logg.error("(%s): %s", shell_cmd(cmd), e)
sys.exit(1)
示例11: execute_command
# 需要导入模块: import os [as 别名]
# 或者: from os import spawnvpe [as 别名]
def execute_command(self, parts, dry_run):
"""
Execute a command.
Parameters
----------
parts : list
Sequence of strings constituting a command.
dry_run : bool
Whether to just log the command instead of executing it.
Returns
-------
status : int
Status code of the executed command or 0 if `dry_run` is `True`.
"""
if dry_run:
self.logger.info("dry-run command '%s'", " ".join(map(str, parts)))
return 0
else: # pragma: no cover
self.logger.debug("executing command '%s'", " ".join(map(str, parts)))
status_code = os.spawnvpe(os.P_WAIT, parts[0], parts, os.environ)
if status_code:
self.logger.warning("command '%s' returned status code %d",
" ".join(map(str, parts)), status_code)
return status_code
示例12: test_spawnvpe_invalid_env
# 需要导入模块: import os [as 别名]
# 或者: from os import spawnvpe [as 别名]
def test_spawnvpe_invalid_env(self):
self._test_invalid_env(os.spawnvpe)
# The introduction of this TestCase caused at least two different errors on
# *nix buildbots. Temporarily skip this to let the buildbots move along.
示例13: create_spawnve
# 需要导入模块: import os [as 别名]
# 或者: from os import spawnvpe [as 别名]
def create_spawnve(original_name):
"""
os.spawnve(mode, path, args, env)
os.spawnvpe(mode, file, args, env)
"""
def new_spawnve(mode, path, args, env):
import os
return getattr(os, original_name)(mode, path, patch_args(args), env)
return new_spawnve
示例14: patch_new_process_functions_with_warning
# 需要导入模块: import os [as 别名]
# 或者: from os import spawnvpe [as 别名]
def patch_new_process_functions_with_warning():
monkey_patch_os('execl', create_warn_multiproc)
monkey_patch_os('execle', create_warn_multiproc)
monkey_patch_os('execlp', create_warn_multiproc)
monkey_patch_os('execlpe', create_warn_multiproc)
monkey_patch_os('execv', create_warn_multiproc)
monkey_patch_os('execve', create_warn_multiproc)
monkey_patch_os('execvp', create_warn_multiproc)
monkey_patch_os('execvpe', create_warn_multiproc)
monkey_patch_os('spawnl', create_warn_multiproc)
monkey_patch_os('spawnle', create_warn_multiproc)
monkey_patch_os('spawnlp', create_warn_multiproc)
monkey_patch_os('spawnlpe', create_warn_multiproc)
monkey_patch_os('spawnv', create_warn_multiproc)
monkey_patch_os('spawnve', create_warn_multiproc)
monkey_patch_os('spawnvp', create_warn_multiproc)
monkey_patch_os('spawnvpe', create_warn_multiproc)
if sys.platform != 'win32':
monkey_patch_os('fork', create_warn_multiproc)
try:
import _posixsubprocess
monkey_patch_module(_posixsubprocess, 'fork_exec', create_warn_fork_exec)
except ImportError:
pass
else:
# Windows
try:
import _subprocess
except ImportError:
import _winapi as _subprocess
monkey_patch_module(_subprocess, 'CreateProcess', create_CreateProcessWarnMultiproc)
示例15: edit_environment
# 需要导入模块: import os [as 别名]
# 或者: from os import spawnvpe [as 别名]
def edit_environment(ctx):
"""
Interactively edit the chute environment vairables.
"""
req = router_request("GET", ctx.obj['chute_url'], dump=False)
info = req.json()
old_environ = info.get('environment', None)
if old_environ is None:
old_environ = {}
fd, path = tempfile.mkstemp()
os.close(fd)
with open(path, 'w') as output:
if len(old_environ) > 0:
output.write(yaml.safe_dump(old_environ, default_flow_style=False))
output.write("\n")
output.write("# You are editing the environment variables for the chute {}.\n"
.format(ctx.obj['chute']))
output.write("# Blank lines and lines starting with '#' will be ignored.\n")
output.write("# Put each variable on a line with a colon separator, e.g. 'VARIABLE: VALUE'\n")
output.write("# Save and exit to apply changes; exit without saving to discard.\n")
# Get modified time before calling editor.
orig_mtime = os.path.getmtime(path)
editor = os.environ.get("EDITOR", "vim")
os.spawnvpe(os.P_WAIT, editor, [editor, path], os.environ)
with open(path, 'r') as source:
data = source.read()
new_environ = yaml.safe_load(data)
# If result is null, convert to an empty dict before sending to router.
if new_environ is None:
new_environ = {}
# Check if the file has been modified, and if it has, send the update.
new_mtime = os.path.getmtime(path)
if new_mtime != orig_mtime:
data = {
'environment': new_environ
}
url = ctx.obj['chute_url'] + "/restart"
res = router_request("POST", url, json=data)
data = res.json()
ctx.invoke(watch, change_id=data['change_id'])
os.remove(path)