Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def run_command(self, demo, command=None):
"""
Run the demo.curent_command unless command is passed in, in
which case run the supplied command in the current demo
encironment.
"""
if not self.shell:
child = pexpect.spawnu('/bin/bash', env=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)
if not command:
command = demo.current_command
print(colorama.Fore.GREEN+colorama.Style.BRIGHT)
response = self.shell.run_command(command)
print(response)
print(colorama.Style.RESET_ALL)
return response
def get_shell(self):
"""Gets or creates the shell in which to run commands for the
supplied demo
"""
if self._shell == None:
# Should we use spawn or spawnu?
child = pexpect.spawnu('/bin/bash', env=self._env, 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
def _start_idl(self):
# Signal handlers are inherited by forked processes, and we can't easily
# reset it from the subprocess. Since kernelapp ignores SIGINT except in
# message handlers, we need to temporarily reset the SIGINT handler here
# so that IDL and its children are interruptible.
sig = signal.signal(signal.SIGINT, signal.SIG_DFL)
try:
self._executable = find_executable("idl")
self._child = spawn(self._executable,timeout = 300)
self.idlwrapper = replwrap.REPLWrapper(self._child,u"IDL> ",None)
except:
self._executable = find_executable("gdl")
self._child = spawn(self._executable,timeout = 300)
self.idlwrapper = replwrap.REPLWrapper(self._child,u"GDL> ",None)
finally:
signal.signal(signal.SIGINT, sig)
self.idlwrapper.run_command("!quiet=1 & defsysv,'!inline',0 & !more=0".rstrip(), timeout=None)
# Compile IDL routines/functions
dirname = os.path.dirname(os.path.abspath(__file__))
self.idlwrapper.run_command(".compile "+dirname+"/snapshot.pro",timeout=None)
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