本文整理汇总了Python中pexpect.spawnu方法的典型用法代码示例。如果您正苦于以下问题:Python pexpect.spawnu方法的具体用法?Python pexpect.spawnu怎么用?Python pexpect.spawnu使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pexpect
的用法示例。
在下文中一共展示了pexpect.spawnu方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: launch_process
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import spawnu [as 别名]
def launch_process(self, command):
# type: (Union[bytes,text_type])->None
"""* What you can do
- It starts process and keep it.
"""
if not self.option is None:
command_plus_option = self.command + " " + self.option
else:
command_plus_option = self.command
if six.PY3:
if shutil.which(command) is None:
raise Exception("No command at {}".format(command))
else:
self.process_analyzer = pexpect.spawnu(command_plus_option)
self.process_id = self.process_analyzer.pid
else:
doc_command_string = "echo '' | {}".format(command)
command_check = os.system(doc_command_string)
if not command_check == 0:
raise Exception("No command at {}".format(command))
else:
self.process_analyzer = pexpect.spawnu(command_plus_option)
self.process_id = self.process_analyzer.pid
示例2: recv_ClientInit
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import spawnu [as 别名]
def recv_ClientInit(self, block):
# start reward proxy.
self._log_info('Starting reward proxy server')
self.reward_proxy = pexpect.spawnu(self.factory.reward_proxy_bin,
logfile=sys.stdout,
timeout=None)
# wait on reward proxy to be up.
self._log_info('Waiting for reward proxy server')
self.reward_proxy.expect('\[RewardProxyServer\]')
self.reward_proxy_thread = threading.Thread(target=lambda: self.reward_proxy.expect(pexpect.EOF))
self.reward_proxy_thread.start()
self._log_info('Reward proxy server is up %s', self.reward_proxy.before)
super(DualProxyServer, self).recv_ClientInit(block)
self.logfile_dir = self.log_manager.logfile_dir
示例3: __init__
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import spawnu [as 别名]
def __init__(self, cmd_or_spawn, orig_prompt, prompt_change,
new_prompt=PEXPECT_PROMPT,
continuation_prompt=PEXPECT_CONTINUATION_PROMPT):
if isinstance(cmd_or_spawn, str):
self.child = pexpect.spawnu(cmd_or_spawn, echo=False)
else:
self.child = cmd_or_spawn
if self.child.echo:
# Existing spawn instance has echo enabled, disable it
# to prevent our input from being repeated to output.
self.child.setecho(False)
self.child.waitnoecho()
if prompt_change is None:
self.prompt = orig_prompt
else:
self.set_prompt(orig_prompt,
prompt_change.format(new_prompt, continuation_prompt))
self.prompt = new_prompt
self.continuation_prompt = continuation_prompt
self._expect_prompt()
示例4: attach
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import spawnu [as 别名]
def attach(self, *args, **kwargs):
"""
Attach to a running container.
:param kwargs:
:return: None
"""
if not args:
return ['Container name or ID is required.']
container = args[0]
def on_after():
self.is_refresh_containers = True
self.is_refresh_running = True
return ['\rDetached from {0}.'.format(container)]
self.after = on_after
command = format_command_line('attach', False, args, kwargs)
process = pexpect.spawnu(command)
process.interact()
示例5: shell
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import spawnu [as 别名]
def shell(self, *args, **_):
"""
Get the shell into a running container. A shortcut for
docker exec -it /usr/bin/env bash.
:param kwargs:
:return: None
"""
if not args:
return ['Container name or ID is required.']
container = args[0]
shellcmd = 'bash'
if len(args) > 1:
shellcmd = ' '.join(args[1:])
self.after = lambda: ['\rShell to {0} is closed.'.format(container)]
command = 'docker exec -it {0} {1}'.format(container, shellcmd)
process = pexpect.spawnu(command)
process.interact()
示例6: step_start_cycli
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import spawnu [as 别名]
def step_start_cycli(context):
context.cli = pexpect.spawnu("cycli -u neo4j -p password")
示例7: step_start_cycli_read_only
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import spawnu [as 别名]
def step_start_cycli_read_only(context):
context.cli = pexpect.spawnu("cycli -u neo4j -p password -r")
示例8: run_cli
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import spawnu [as 别名]
def run_cli(context, run_args=None, prompt_check=True, currentdb=None):
"""Run the process using pexpect."""
run_args = run_args or []
cli_cmd = context.conf.get("cli_command")
cmd_parts = [cli_cmd] + run_args
cmd = " ".join(cmd_parts)
context.cli = pexpect.spawnu(cmd, cwd=context.package_root)
context.logfile = StringIO()
context.cli.logfile = context.logfile
context.exit_sent = False
context.currentdb = currentdb or context.conf["dbname"]
context.cli.sendline("\pset pager always")
if prompt_check:
wait_prompt(context)
示例9: restart_process
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import spawnu [as 别名]
def restart_process(self):
# type: ()->None
if not self.option is None:
command_plus_option = self.command + " " + self.option
else:
command_plus_option = self.command
self.process_analyzer.kill(sig=9)
self.process_analyzer = pexpect.spawnu(command_plus_option)
self.process_id = self.process_analyzer.pid
示例10: get_shell
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import spawnu [as 别名]
def get_shell(self):
"""Gets or creates the shell in which to run commands for the
supplied demo
"""
if self._shell == None:
child = pexpect.spawnu('/bin/bash', env=self.demo.env.get(), echo=False, timeout=None)
ps1 = PEXPECT_PROMPT[:5] + u'\[\]' + PEXPECT_PROMPT[5:]
ps2 = PEXPECT_CONTINUATION_PROMPT[:5] + u'\[\]' + PEXPECT_CONTINUATION_PROMPT[5:]
prompt_change = u"PS1='{0}' PS2='{1}' PROMPT_COMMAND=''".format(ps1, ps2)
self._shell = pexpect.replwrap.REPLWrapper(child, u'\$', prompt_change)
return self._shell
示例11: step_run_cli
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import spawnu [as 别名]
def step_run_cli(self):
self.cli = pexpect.spawnu('kube-shell')
示例12: run_cli
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import spawnu [as 别名]
def run_cli(context, run_args=None):
"""Run the process using pexpect."""
run_args = run_args or []
cli_cmd = context.conf.get('cli_command')
cmd_parts = [cli_cmd] + run_args
cmd = ' '.join(cmd_parts)
context.cli = pexpect.spawnu(cmd, cwd=context.package_root)
context.exit_sent = False
context.currentdb = context.conf['dbname']
示例13: login
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import spawnu [as 别名]
def login(self, *args, **kwargs):
"""
Register or log in to a Docker registry server.
:param kwargs:
:return: None
"""
self.after = lambda: ['\r']
command = format_command_line('login', False, args, kwargs)
process = pexpect.spawnu(command)
process.interact()
示例14: push
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import spawnu [as 别名]
def push(self, *args, **kwargs):
"""
Push an image into repository. Equivalent of docker push.
:param kwargs:
:return: interactive.
"""
if not args or len(args) < 1:
return ['Image name (tagged) is required.']
tag_valid, tag_message = self._is_repo_tag_valid(args[0])
if not tag_valid:
return [tag_message]
self.after = lambda: ['\r']
# TODO: this command didn't have to use pexpect.
# But it was easier to call the official CLI than try and figure out
# why requests throw this error:
# File "venv/wharfee/lib/python2.7/site-packages/requests/packages/
# urllib3/response.py", line 267, in read
# raise ReadTimeoutError(self._pool, None, 'Read timed out.')
# requests.packages.urllib3.exceptions.ReadTimeoutError:
# HTTPSConnectionPool(host='192.168.59.103', port=2376): Read timed out.
command = format_command_line('push', False, args, kwargs)
process = pexpect.spawnu(command)
process.interact()
示例15: call_external_cli
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import spawnu [as 别名]
def call_external_cli(self, cmd, *args, **kwargs):
"""
Call the "official" CLI if needed.
:param args:
:param kwargs:
:return:
"""
called = False
is_force = kwargs.pop('force', False)
is_interactive = kwargs.get('interactive', None)
is_tty = kwargs.get('tty', None)
is_attach = kwargs.get('attach', None)
is_attach_bool = is_attach in [True, False]
def execute_external():
"""
Call the official cli
"""
command = format_command_line(cmd, False, args, kwargs)
process = pexpect.spawnu(command)
process.interact()
def on_after_interactive():
# \r is to make sure when there is some error output,
# prompt is back to beginning of line
self.is_refresh_containers = True
self.is_refresh_running = True
return ['\rInteractive terminal is closed.']
def on_after_attach():
self.is_refresh_containers = True
self.is_refresh_running = True
return ['Container exited.\r']
if is_force or is_interactive or is_tty or (is_attach and not is_attach_bool):
self.after = on_after_attach if is_attach or (not is_interactive and not is_tty) else on_after_interactive
called = True
execute_external()
return called, args, kwargs