当前位置: 首页>>代码示例>>Python>>正文


Python pexpect.ExceptionPexpect方法代码示例

本文整理汇总了Python中pexpect.ExceptionPexpect方法的典型用法代码示例。如果您正苦于以下问题:Python pexpect.ExceptionPexpect方法的具体用法?Python pexpect.ExceptionPexpect怎么用?Python pexpect.ExceptionPexpect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pexpect的用法示例。


在下文中一共展示了pexpect.ExceptionPexpect方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: shutdown

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import ExceptionPexpect [as 别名]
def shutdown(self):

        if self.launched:
            self.semaphore.acquire()

            self.child.kill(signal.SIGUSR2)

            # wait for rtkrcv to shutdown
            try:
                self.child.wait()
            except pexpect.ExceptionPexpect:
                print("Already dead!!")

            if self.child.isalive():
                r = -1
            else:
                r = 1

            self.semaphore.release()
            self.launched = False

            return r

        # already shut down
        return 2 
开发者ID:Stefal,项目名称:rtkbase,代码行数:27,代码来源:RtkController.py

示例2: close

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import ExceptionPexpect [as 别名]
def close(self):
        self.util.clear_state(self)
        if self.state == ConsoleState.DISCONNECTED:
            return
        try:
            self.pty.send("\r")
            self.pty.send('~.')
            close_rc = self.pty.expect(
                [pexpect.TIMEOUT, pexpect.EOF], timeout=10)
            log.debug("CLOSE Expect Buffer ID={}".format(hex(id(self.pty))))
            rc_child = self.pty.close()
            exitCode = signalstatus = None
            if self.pty.status != -1:  # leaving here for debug
                if os.WIFEXITED(self.pty.status):
                    exitCode = os.WEXITSTATUS(self.pty.status)
                else:
                    signalstatus = os.WTERMSIG(self.pty.status)
            self.state = ConsoleState.DISCONNECTED
        except pexpect.ExceptionPexpect as e:
            self.state = ConsoleState.DISCONNECTED
            raise "SSH Console: failed to close ssh console"
        except Exception as e:
            self.state = ConsoleState.DISCONNECTED
            pass 
开发者ID:open-power,项目名称:op-test,代码行数:26,代码来源:OpTestSSH.py

示例3: close

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import ExceptionPexpect [as 别名]
def close(self):
        self.util.clear_state(self)
        try:
            rc_child = self.pty.close()
            exitCode = signalstatus = None
            if self.pty.status != -1:  # leaving for debug
                if os.WIFEXITED(self.pty.status):
                    exitCode = os.WEXITSTATUS(self.pty.status)
                else:
                    signalstatus = os.WTERMSIG(self.pty.status)
            self.state = ConsoleState.DISCONNECTED
        except pexpect.ExceptionPexpect as e:
            self.state = ConsoleState.DISCONNECTED
            raise "Mambo Console: failed to close console"
        except Exception as e:
            self.state = ConsoleState.DISCONNECTED
            pass
        log.debug("Mambo close -> TERMINATE") 
开发者ID:open-power,项目名称:op-test,代码行数:20,代码来源:OpTestMambo.py

示例4: close

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import ExceptionPexpect [as 别名]
def close(self):
        self.util.clear_state(self)
        if self.state == SerialConsoleState.DISCONNECTED:
            return
        try:
            # Hopefully we don't need to do this....
            #self.pty.send("\r")
            #self.pty.send('~.')
            #close_rc = self.pty.expect(
            #    ['Connection to.*closed', pexpect.TIMEOUT, pexpect.EOF], timeout=10)
            #log.debug("CLOSE Expect Buffer ID={}".format(hex(id(self.pty))))
            rc_child = self.pty.close()
            self.state = SerialConsoleState.DISCONNECTED
            exitCode = signalstatus = None
            if self.pty.status != -1:  # leaving for future debug
                if os.WIFEXITED(self.pty.status):
                    exitCode = os.WEXITSTATUS(self.pty.status)
                else:
                    signalstatus = os.WTERMSIG(self.pty.status)
        except pexpect.ExceptionPexpect:
            self.state = SerialConsoleState.DISCONNECTED
            raise OpTestError("Failed to close serial console")
        except Exception as e:
            self.state = SerialConsoleState.DISCONNECTED
            pass 
开发者ID:open-power,项目名称:op-test,代码行数:27,代码来源:SerialConsole.py

示例5: close

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import ExceptionPexpect [as 别名]
def close(self):
        self.util.clear_state(self)
        try:
            rc_child = self.pty.close()
            exitCode = signalstatus = None
            if self.pty.status != -1:  # leaving for debug
                if os.WIFEXITED(self.pty.status):
                    exitCode = os.WEXITSTATUS(self.pty.status)
                else:
                    signalstatus = os.WTERMSIG(self.pty.status)
            self.state = ConsoleState.DISCONNECTED
        except pexpect.ExceptionPexpect as e:
            self.state = ConsoleState.DISCONNECTED
            raise "Qemu Console: failed to close console"
        except Exception as e:
            self.state = ConsoleState.DISCONNECTED
            pass
        log.debug("Qemu close -> TERMINATE") 
开发者ID:open-power,项目名称:op-test,代码行数:20,代码来源:OpTestQemu.py

示例6: close

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import ExceptionPexpect [as 别名]
def close(self):
        self.util.clear_state(self)
        try:
            self.pty.close()
            if self.pty.status != -1:  # leaving for debug
                if os.WIFEXITED(self.pty.status):
                    os.WEXITSTATUS(self.pty.status)
                else:
                    os.WTERMSIG(self.pty.status)
            self.state = ConsoleState.DISCONNECTED
        except pexpect.ExceptionPexpect:
            self.state = ConsoleState.DISCONNECTED
            raise "HMC Console: failed to close console"
        except Exception:
            self.state = ConsoleState.DISCONNECTED
        log.debug("HMC close -> TERMINATE") 
开发者ID:open-power,项目名称:op-test,代码行数:18,代码来源:OpTestHMC.py

示例7: stop

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import ExceptionPexpect [as 别名]
def stop(self):
        # terminate the stream

        if self.started:
            self.child.kill(signal.SIGUSR2)
            try:
                self.child.wait()
            except pexpect.ExceptionPexpect:
                print("Str2str already down")

            self.started = False
            return 1

        # str2str already stopped
        return 2 
开发者ID:Stefal,项目名称:rtkbase,代码行数:17,代码来源:Str2StrController.py

示例8: kill

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import ExceptionPexpect [as 别名]
def kill(self, signo):
        """Send a signal to the child (not available on Windows)."""
        raise ExceptionPexpect, 'Signals are not availalbe on Windows' 
开发者ID:c-amr,项目名称:camr,代码行数:5,代码来源:winpexpect.py

示例9: __init__

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import ExceptionPexpect [as 别名]
def __init__ (self, fd, args=[], timeout=30, maxread=2000, searchwindowsize=None, logfile=None):

        '''This takes a file descriptor (an int) or an object that support the
        fileno() method (returning an int). All Python file-like objects
        support fileno(). '''

        ### TODO: Add better handling of trying to use fdspawn in place of spawn
        ### TODO: (overload to allow fdspawn to also handle commands as spawn does.

        if type(fd) != type(0) and hasattr(fd, 'fileno'):
            fd = fd.fileno()

        if type(fd) != type(0):
            raise ExceptionPexpect('The fd argument is not an int. If this is a command string then maybe you want to use pexpect.spawn.')

        try: # make sure fd is a valid file descriptor
            os.fstat(fd)
        except OSError:
            raise ExceptionPexpect('The fd argument is not a valid file descriptor.')

        self.args = None
        self.command = None
        spawn.__init__(self, None, args, timeout, maxread, searchwindowsize, logfile)
        self.child_fd = fd
        self.own_fd = False
        self.closed = False
        self.name = '<file descriptor %d>' % fd 
开发者ID:c-amr,项目名称:camr,代码行数:29,代码来源:fdpexpect.py

示例10: terminate

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import ExceptionPexpect [as 别名]
def terminate (self, force=False):  # pragma: no cover
        raise ExceptionPexpect('This method is not valid for file descriptors.') 
开发者ID:c-amr,项目名称:camr,代码行数:4,代码来源:fdpexpect.py

示例11: start_and_run

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import ExceptionPexpect [as 别名]
def start_and_run(self, cmdline, env, cwd, shutdown_requested_event, ready_string,  # pylint: disable=too-many-arguments
                      status_updated_fct, log_fct):
        """
        thread function
        """
        status_updated_fct(ApplicationStatus.STARTING)
        try:
            process = self.start_process(cmdline, log_fct, env=env, cwd=cwd)
            self.run(process, shutdown_requested_event, ready_string, status_updated_fct, log_fct)
        except (KeyError, pexpect.ExceptionPexpect) as e:
            self._log_fct("Error while starting process: {}".format(e))
            status_updated_fct(ApplicationStatus.ERROR) 
开发者ID:carla-simulator,项目名称:ros-bridge,代码行数:14,代码来源:application_runner.py

示例12: test_keys_mnemonics

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import ExceptionPexpect [as 别名]
def test_keys_mnemonics():
    with open('testHmyReferences/sdkMnemonics.json') as f:
        sdk_mnemonics = json.load(f)
        if not sdk_mnemonics:
            log("Could not load reference data.")
            return False

    passed = True
    for test in sdk_mnemonics["data"]:
        index = test["index"]
        if index != 0:  # CLI currently uses a hardcoded index of 0.
            continue

        mnemonic = test["phrase"]
        correct_address = test["addr"]
        address_name = f'testHmyAcc_{random.randint(0,1e9)}'
        while address_name in ADDRESSES:
            address_name = f'testHmyAcc_{random.randint(0,1e9)}'

        try:
            hmy = pexpect.spawn('./hmy', ['keys', 'add', address_name, '--recover', '--passphrase'], env=ENVIRONMENT)
            hmy.expect("Enter passphrase\r\n")
            hmy.sendline("")
            hmy.expect("Repeat the passphrase:\r\n")
            hmy.sendline("")
            hmy.expect("Enter mnemonic to recover keys from\r\n")
            hmy.sendline(mnemonic)
            hmy.wait()
            hmy.expect(pexpect.EOF)
        except pexpect.ExceptionPexpect as e:
            log(f"Exception occurred when adding a key with mnemonic."
                f"\nException: {e}")
            passed = False

        hmy_address = get_address_from_name(address_name)
        if hmy_address != correct_address or hmy_address is None:
            log(f"Address does not match sdk's address. \n"
                f"\tMnemonic: {mnemonic}\n"
                f"\tCorrect address: {correct_address}\n"
                f"\tCLI address: {hmy_address}")
            passed = False
        else:
            KEYS_ADDED.add(address_name)
    log("Passed", error=False) if passed else log("FAILED", error=False)
    return passed 
开发者ID:harmony-one,项目名称:harmony-ops,代码行数:47,代码来源:testHmy.py

示例13: _DeleteFile

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import ExceptionPexpect [as 别名]
def _DeleteFile(self, file_name):
    """Delete a file.

    Args:
      file_name: A string, the file name.

    Raises:
      DeleteFileError, if the deletion failed.
    """
    try:
      self._connection.child.send('\r')
      self._connection.child.expect('\r\n', timeout=self.timeout_act_user)
      self._connection.child.expect(self._connection.re_prompt,
                                    timeout=self.timeout_act_user,
                                    searchwindowsize=128)
      self._connection.child.send('delete %s\r' % file_name)
    except pexpect.ExceptionPexpect:
      raise DeleteFileError('DeleteFile operation failed. %s' %
                            self._connection.child)

    try:
      pindex = self._connection.child.expect(
          [r'Delete filename \[.*\]\?',
           r'%.*Error.*'],
          timeout=self.timeout_act_user)
      if pindex == 0:
        self._connection.child.send('\r')
        logging.debug('DeleteFile: answering first confirmation.')
        self._connection.child.expect([r'Delete .*\[confirm\]'],
                                      timeout=self.timeout_act_user)
        logging.debug('DeleteFile: answering second confirmation.')
        self._connection.child.send('\r')
      elif pindex == 1:
        raise DeleteFileError('DeleteFile operation failed. %s' %
                              self._connection.child.match)

      pindex = self._connection.child.expect([self._connection.re_prompt,
                                              r'%.*Error.*'],
                                             timeout=self.timeout_act_user)
      if pindex == 1:
        raise DeleteFileError('DeleteFile operation failed. %s' %
                              self._connection.child.match)
      logging.debug('DeleteFile: success.')
    except pexpect.ExceptionPexpect:
      raise DeleteFileError('DeleteFile operation failed. %s' %
                            self._connection.child) 
开发者ID:google,项目名称:ldpush,代码行数:48,代码来源:ios.py


注:本文中的pexpect.ExceptionPexpect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。