本文整理汇总了Python中os.execvp方法的典型用法代码示例。如果您正苦于以下问题:Python os.execvp方法的具体用法?Python os.execvp怎么用?Python os.execvp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.execvp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: scp
# 需要导入模块: import os [as 别名]
# 或者: from os import execvp [as 别名]
def scp(args):
"""
Transfer files to or from EC2 instance.
"""
scp_opts, host_opts = extract_passthrough_opts(args, "scp"), []
user_or_hostname_chars = string.ascii_letters + string.digits
ssm_init_complete = False
for i, arg in enumerate(args.scp_args):
if arg[0] in user_or_hostname_chars and ":" in arg:
hostname, colon, path = arg.partition(":")
username, at, hostname = hostname.rpartition("@")
if args.use_ssm and not ssm_init_complete:
scp_opts += init_ssm(get_instance(hostname).id)
ssm_init_complete = True
host_opts, hostname = prepare_ssh_host_opts(username=username, hostname=hostname,
bless_config_filename=args.bless_config,
use_kms_auth=args.use_kms_auth, use_ssm=args.use_ssm)
args.scp_args[i] = hostname + colon + path
os.execvp("scp", ["scp"] + scp_opts + host_opts + args.scp_args)
示例2: test
# 需要导入模块: import os [as 别名]
# 或者: from os import execvp [as 别名]
def test(coverage=False):
"""Run the unit tests."""
if coverage and not os.environ.get('FLASK_COVERAGE'):
import sys
os.environ['FLASK_COVERAGE'] = '1'
os.execvp(sys.executable, [sys.executable] + sys.argv)
import unittest
import xmlrunner
tests = unittest.TestLoader().discover('tests')
# run tests with unittest-xml-reporting and output to $CIRCLE_TEST_REPORTS on CircleCI or test-reports locally
xmlrunner.XMLTestRunner(output=os.environ.get('CIRCLE_TEST_REPORTS','test-reports')).run(tests)
if COV:
COV.stop()
COV.save()
print('Coverage Summary:')
COV.report()
basedir = os.path.abspath(os.path.dirname(__file__))
covdir = os.path.join(basedir, 'tmp/coverage')
COV.html_report(directory=covdir)
print('HTML version: file://%s/index.html' % covdir)
COV.erase()
示例3: prompt
# 需要导入模块: import os [as 别名]
# 或者: from os import execvp [as 别名]
def prompt(default=None):
editor = 'nano'
with tempfile.NamedTemporaryFile(mode='r+') as tmpfile:
if default:
tmpfile.write(default)
tmpfile.flush()
child_pid = os.fork()
is_child = child_pid == 0
if is_child:
os.execvp(editor, [editor, tmpfile.name])
else:
os.waitpid(child_pid, 0)
tmpfile.seek(0)
return tmpfile.read().strip()
示例4: _spawn_posix
# 需要导入模块: import os [as 别名]
# 或者: from os import execvp [as 别名]
def _spawn_posix(cmd, search_path=1, verbose=0, dry_run=0):
log.info(' '.join(cmd))
if dry_run:
return
exec_fn = search_path and os.execvp or os.execv
pid = os.fork()
if pid == 0: # in the child
try:
exec_fn(cmd[0], cmd)
except OSError, e:
sys.stderr.write("unable to execute %s: %s\n" %
(cmd[0], e.strerror))
os._exit(1)
sys.stderr.write("unable to execute %s for unknown reasons" % cmd[0])
os._exit(1)
示例5: __init__
# 需要导入模块: import os [as 别名]
# 或者: from os import execvp [as 别名]
def __init__(self, args, close_stderr=False):
pid, fd = pty.fork()
if pid == 0:
# We're the child. Transfer control to command.
if close_stderr:
dev_null = os.open('/dev/null', 0)
os.dup2(dev_null, 2)
os.execvp(args[0], args)
else:
# Disable echoing.
attr = termios.tcgetattr(fd)
attr[3] = attr[3] & ~termios.ECHO
termios.tcsetattr(fd, termios.TCSANOW, attr)
# Set up a file()-like interface to the child process
self.r = os.fdopen(fd, 'r', 1)
self.w = os.fdopen(os.dup(fd), 'w', 1)
示例6: call
# 需要导入模块: import os [as 别名]
# 或者: from os import execvp [as 别名]
def call(fn, *, log_relpath, args=None, kwargs=None, mpi_proc_per_machine=1, mpi_machines=1, **__):
local_eval_dir = os.path.join(LOCAL_LOG_PATH, log_relpath)
if os.path.exists(local_eval_dir):
print(colorize(
'Directory %s exists. Removing existing data (this is the default behavior for backend=local)' % local_eval_dir,
color='red', highlight=True))
shutil.rmtree(local_eval_dir)
os.makedirs(local_eval_dir, exist_ok=True)
args = args or []
kwargs = kwargs or {}
write_metadata(local_eval_dir, args=args, kwargs=kwargs)
def thunk():
return fn(*args, **kwargs)
mpi_procs = mpi_proc_per_machine * mpi_machines
if mpi_procs > 1:
cmd = make_command(thunk, local_eval_dir, mpi_procs, mpi_hosts_path=None)
return os.execvp(cmd[0], cmd)
else:
return run_with_logger(thunk, local_eval_dir)
示例7: contain
# 需要导入模块: import os [as 别名]
# 或者: from os import execvp [as 别名]
def contain(command, image_name, image_dir, container_id, container_dir):
linux.sethostname(container_id) # change hostname to container_id
linux.mount(None, '/', None, linux.MS_PRIVATE | linux.MS_REC, None)
new_root = create_container_root(
image_name, image_dir, container_id, container_dir)
print('Created a new root fs for our container: {}'.format(new_root))
_create_mounts(new_root)
old_root = os.path.join(new_root, 'old_root')
os.makedirs(old_root)
linux.pivot_root(new_root, old_root)
os.chdir('/')
linux.umount2('/old_root', linux.MNT_DETACH) # umount old root
os.rmdir('/old_root') # rmdir the old_root dir
os.execvp(command[0], command)
示例8: contain
# 需要导入模块: import os [as 别名]
# 或者: from os import execvp [as 别名]
def contain(command, image_name, image_dir, container_id, container_dir):
linux.unshare(linux.CLONE_NEWNS) # create a new mount namespace
linux.unshare(linux.CLONE_NEWUTS) # switch to a new UTS namespace
linux.sethostname(container_id) # change hostname to container_id
linux.mount(None, '/', None, linux.MS_PRIVATE | linux.MS_REC, None)
new_root = create_container_root(
image_name, image_dir, container_id, container_dir)
print('Created a new root fs for our container: {}'.format(new_root))
_create_mounts(new_root)
old_root = os.path.join(new_root, 'old_root')
os.makedirs(old_root)
linux.pivot_root(new_root, old_root)
os.chdir('/')
linux.umount2('/old_root', linux.MNT_DETACH) # umount old root
os.rmdir('/old_root') # rmdir the old_root dir
os.execvp(command[0], command)
示例9: contain
# 需要导入模块: import os [as 别名]
# 或者: from os import execvp [as 别名]
def contain(command, image_name, image_dir, container_id, container_dir):
linux.unshare(linux.CLONE_NEWNS) # create a new mount namespace
linux.mount(None, '/', None, linux.MS_PRIVATE | linux.MS_REC, None)
new_root = create_container_root(
image_name, image_dir, container_id, container_dir)
print('Created a new root fs for our container: {}'.format(new_root))
_create_mounts(new_root)
old_root = os.path.join(new_root, 'old_root')
os.makedirs(old_root)
linux.pivot_root(new_root, old_root)
os.chdir('/')
linux.umount2('/old_root', linux.MNT_DETACH) # umount old root
os.rmdir('/old_root') # rmdir the old_root dir
os.execvp(command[0], command)
示例10: test
# 需要导入模块: import os [as 别名]
# 或者: from os import execvp [as 别名]
def test(coverage=False):
"""Run the unit tests."""
if coverage and not os.environ.get('FLASK_COVERAGE'):
os.environ['FLASK_COVERAGE'] = '1'
os.execvp(sys.executable, [sys.executable] + sys.argv)
testresult = TextTestRunner(verbosity=2).run(TestLoader().discover('tests'))
if cov:
cov.stop()
cov.save()
print('Coverage Summary:')
cov.report()
covdir = app.config.get('COVERAGE_DIRECTORY', '')
if covdir:
covdir = os.path.join(covdir, datetime.utcnow().strftime('%Y-%m-%d-%H-%M-%S'))
if not os.path.exists(covdir):
os.makedirs(covdir)
cov.html_report(directory=covdir)
print('Coverage HTML version: file://{}/index.html'.format(covdir))
cov.erase()
if len(testresult.failures) + len(testresult.errors) > 0:
sys.exit(1)
示例11: connect_to_instance
# 需要导入模块: import os [as 别名]
# 或者: from os import execvp [as 别名]
def connect_to_instance(self, instance):
# type: (Dict[str, Any]) -> None
ssh_address = 'ec2-user@{}'.format(instance['PublicDnsName'])
ssh_args = ['ssh', '-X', '-i', self.pem_key, '-t', ssh_address]
if self.com:
conn_com = "bash -lc '{}'".format(' '.join(self.com).replace("'", r"\'"))
else:
conn_com = "bash -lc '~/ithemal/aws/aws_utils/tmux_attach.sh || /home/ithemal/ithemal/aws/aws_utils/tmux_attach.sh'"
if self.host:
ssh_args.append(conn_com)
else:
if self.root:
user = 'root'
else:
user = 'ithemal'
ssh_args.append('sudo docker exec -u {} -it ithemal {}'.format(user, conn_com))
os.execvp('ssh', ssh_args)
sys.exit(1)
示例12: maybe_restart_mirroring_script
# 需要导入模块: import os [as 别名]
# 或者: from os import execvp [as 别名]
def maybe_restart_mirroring_script() -> None:
if os.stat(os.path.join(options.stamp_path, "stamps", "restart_stamp")).st_mtime > start_time or (
(options.user == "tabbott" or options.user == "tabbott/extra")
and os.stat(os.path.join(options.stamp_path, "stamps", "tabbott_stamp")).st_mtime > start_time
):
logger.warning("")
logger.warning("zephyr mirroring script has been updated; restarting...")
maybe_kill_child()
try:
zephyr._z.cancelSubs()
except OSError:
# We don't care whether we failed to cancel subs properly, but we should log it
logger.exception("")
while True:
try:
os.execvp(os.path.abspath(__file__), sys.argv)
except Exception:
logger.exception("Error restarting mirroring script; trying again... Traceback:")
time.sleep(1)
示例13: __init__
# 需要导入模块: import os [as 别名]
# 或者: from os import execvp [as 别名]
def __init__(self, cmd, bufsize=-1):
p2cread, p2cwrite = os.pipe()
c2pread, c2pwrite = os.pipe()
self.pid = os.fork()
if self.pid == 0:
# Child
os.dup2(p2cread, 0)
os.dup2(c2pwrite, 1)
os.dup2(c2pwrite, 2)
for i in range(3, popen2.MAXFD):
try:
os.close(i)
except: pass
try:
os.execvp(cmd[0], cmd)
finally:
os._exit(1)
# Shouldn't come here, I guess
os._exit(1)
os.close(p2cread)
self.tochild = os.fdopen(p2cwrite, 'w', bufsize)
os.close(c2pwrite)
self.fromchild = os.fdopen(c2pread, 'r', bufsize)
popen2._active.append(self)
示例14: main
# 需要导入模块: import os [as 别名]
# 或者: from os import execvp [as 别名]
def main(args):
term = blessings.Terminal()
# There's a security bug in Mavericks wrt. urllib2:
# http://bugs.python.org/issue20585
if platform.system() == "Darwin":
os.environ["no_proxy"] = "*"
task = MASTER.task(args.task)
cmd = [
"ssh",
"-t",
task.slave["hostname"],
"cd {0} && bash".format(task.directory)
]
if task.directory == "":
print(term.red + "warning: the task no longer exists on the " +
"target slave. Will not enter sandbox" + term.white + "\n\n")
cmd = cmd[:-1]
log.fn(os.execvp, "ssh", cmd)
示例15: test
# 需要导入模块: import os [as 别名]
# 或者: from os import execvp [as 别名]
def test(coverage=False):
"""Run the unit tests."""
import sys
if coverage and not os.environ.get('FLASK_COVERAGE'):
os.environ['FLASK_COVERAGE'] = '1'
os.execvp(sys.executable, [sys.executable] + sys.argv)
import unittest
import xmlrunner
tests = unittest.TestLoader().discover('tests')
results = xmlrunner.XMLTestRunner(output='test-reports').run(tests)
if COV:
COV.stop()
COV.save()
print('Coverage Summary:')
COV.report()
basedir = os.path.abspath(os.path.dirname(__file__))
covdir = os.path.join(basedir, 'test-reports/coverage')
COV.html_report(directory=covdir)
print('HTML version: file://%s/index.html' % covdir)
COV.erase()
if (len(results.failures) > 0 or len(results.errors) > 0):
sys.exit(1)