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


Python pexpect.spawn函数代码示例

本文整理汇总了Python中pylib.pexpect.spawn函数的典型用法代码示例。如果您正苦于以下问题:Python spawn函数的具体用法?Python spawn怎么用?Python spawn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: GetSDKPlatform

def GetSDKPlatform(api_level=DEFAULT_ANDROID_API_LEVEL):
    """Update the SDK to include the platform specified.

  Args:
    api_level: the Android API level to download
  """
    android_binary = os.path.join(constants.EMULATOR_SDK_ROOT, "sdk", "tools", "android")
    pattern = re.compile(r"\s*([0-9]+)- SDK Platform Android [\.,0-9]+, API %d.*" % api_level)
    # Example:
    #   2- SDK Platform Android 4.3, API 18, revision 2
    exit_code, stdout = cmd_helper.GetCmdStatusAndOutput([android_binary, "list", "sdk"])
    if exit_code != 0:
        raise Exception("'android list sdk' command return %d" % exit_code)
    for line in stdout.split("\n"):
        match = pattern.match(line)
        if match:
            index = match.group(1)
            print "package %s corresponds to platform level %d" % (index, api_level)
            # update sdk --no-ui --filter $INDEX
            update_command = [android_binary, "update", "sdk", "--no-ui", "--filter", index]
            update_command_str = " ".join(update_command)
            logging.info("running update command: %s" % update_command_str)
            update_process = pexpect.spawn(update_command_str)
            # TODO(andrewhayden): Do we need to bug the user about this?
            if update_process.expect("Do you accept the license") != 0:
                raise Exception("License agreement check failed")
            update_process.sendline("y")
            if update_process.expect("Done. 1 package installed.") == 0:
                print "Successfully installed platform for API level %d" % api_level
                return
            else:
                raise Exception("Failed to install platform update")
    raise Exception("Could not find android-%d update for the SDK!" % api_level)
开发者ID:MitchRudominer,项目名称:engine,代码行数:33,代码来源:install_emulator_deps.py

示例2: _CreateAVD

  def _CreateAVD(self):
    """Creates an AVD with the given name.

    Return avd_name.
    """

    if self.abi == 'arm':
      abi_option = 'armeabi-v7a'
    else:
      abi_option = 'x86'

    avd_command = [
        self.android,
        '--silent',
        'create', 'avd',
        '--name', self.avd_name,
        '--abi', abi_option,
        '--target', API_TARGET,
        '--sdcard', SDCARD_SIZE,
        '--force',
    ]
    avd_cmd_str = ' '.join(avd_command)
    logging.info('Create AVD command: %s', avd_cmd_str)
    avd_process = pexpect.spawn(avd_cmd_str)

    # Instead of creating a custom profile, we overwrite config files.
    avd_process.expect('Do you wish to create a custom hardware profile')
    avd_process.sendline('no\n')
    avd_process.expect('Created AVD \'%s\'' % self.avd_name)

    # Setup test device as default Galaxy Nexus AVD
    avd_config_dir = os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'android',
                                  'avd_configs')
    avd_config_ini = os.path.join(avd_config_dir,
                                  'AVD_for_Galaxy_Nexus_by_Google_%s.avd' %
                                  self.abi, 'config.ini')

    # Replace current configuration with default Galaxy Nexus config.
    avds_dir = os.path.join(os.path.expanduser('~'), '.android', 'avd')
    ini_file = os.path.join(avds_dir, '%s.ini' % self.avd_name)
    new_config_ini = os.path.join(avds_dir, '%s.avd' % self.avd_name,
                                  'config.ini')

    # Remove config files with defaults to replace with Google's GN settings.
    os.unlink(ini_file)
    os.unlink(new_config_ini)

    # Create new configuration files with Galaxy Nexus by Google settings.
    with open(ini_file, 'w') as new_ini:
      new_ini.write('avd.ini.encoding=ISO-8859-1\n')
      new_ini.write('target=%s\n' % API_TARGET)
      new_ini.write('path=%s/%s.avd\n' % (avds_dir, self.avd_name))
      new_ini.write('path.rel=avd/%s.avd\n' % self.avd_name)

    shutil.copy(avd_config_ini, new_config_ini)
    return self.avd_name
开发者ID:cvsuser-chromium,项目名称:chromium,代码行数:56,代码来源:emulator.py

示例3: RunTestsAndListResults

    def RunTestsAndListResults(self):
        """Runs all the tests and checks for failures.

    Returns:
      A TestRunResults object.
    """
        args = ["adb", "-s", self.device, "shell", "sh", constants.TEST_EXECUTABLE_DIR + "/chrome_test_runner.sh"]
        logging.info(args)
        p = pexpect.spawn(args[0], args[1:], logfile=sys.stdout)
        return self._WatchTestOutput(p)
开发者ID:hinike,项目名称:opera,代码行数:10,代码来源:test_package_executable.py

示例4: WaitForLogMatch

  def WaitForLogMatch(self, success_re, error_re, clear=False):
    """Blocks until a matching line is logged or a timeout occurs.

    Args:
      success_re: A compiled re to search each line for.
      error_re: A compiled re which, if found, terminates the search for
          |success_re|. If None is given, no error condition will be detected.
      clear: If True the existing logcat output will be cleared, defaults to
          false.

    Raises:
      pexpect.TIMEOUT upon the timeout specified by StartMonitoringLogcat().

    Returns:
      The re match object if |success_re| is matched first or None if |error_re|
      is matched first.
    """
    logging.info('<<< Waiting for logcat:' + str(success_re.pattern))
    t0 = time.time()
    while True:
      if not self._logcat:
        self.StartMonitoringLogcat(clear)
      try:
        while True:
          # Note this will block for upto the timeout _per log line_, so we need
          # to calculate the overall timeout remaining since t0.
          time_remaining = t0 + self._logcat.timeout - time.time()
          if time_remaining < 0: raise pexpect.TIMEOUT(self._logcat)
          self._logcat.expect(PEXPECT_LINE_RE, timeout=time_remaining)
          line = self._logcat.match.group(1)
          if error_re:
            error_match = error_re.search(line)
            if error_match:
              return None
          success_match = success_re.search(line)
          if success_match:
            return success_match
          logging.info('<<< Skipped Logcat Line:' + str(line))
      except pexpect.TIMEOUT:
        raise pexpect.TIMEOUT(
            'Timeout (%ds) exceeded waiting for pattern "%s" (tip: use -vv '
            'to debug)' %
            (self._logcat.timeout, success_re.pattern))
      except pexpect.EOF:
        # It seems that sometimes logcat can end unexpectedly. This seems
        # to happen during Chrome startup after a reboot followed by a cache
        # clean. I don't understand why this happens, but this code deals with
        # getting EOF in logcat.
        logging.critical('Found EOF in adb logcat. Restarting...')
        # Rerun spawn with original arguments. Note that self._logcat.args[0] is
        # the path of adb, so we don't want it in the arguments.
        self._logcat = pexpect.spawn('adb',
                                     self._logcat.args[1:],
                                     timeout=self._logcat.timeout,
                                     logfile=self._logcat.logfile)
开发者ID:Andrel322,项目名称:gecko-dev,代码行数:55,代码来源:android_commands.py

示例5: _WatchFifo

 def _WatchFifo(self, device, timeout, logfile=None):
   for i in range(100):
     if device.FileExists(self._GetFifo()):
       logging.info('Fifo created. Slept for %f secs', i * 0.5)
       break
     time.sleep(0.5)
   else:
     raise device_errors.DeviceUnreachableError(
         'Unable to find fifo on device %s ' % self._GetFifo())
   args = ['-s', device.adb.GetDeviceSerial(), 'shell', 'cat', self._GetFifo()]
   return pexpect.spawn('adb', args, timeout=timeout, logfile=logfile)
开发者ID:naynus,项目名称:chromium,代码行数:11,代码来源:test_package_apk.py

示例6: _WatchFifo

 def _WatchFifo(self, timeout, logfile=None):
   for i in range(10):
     if self.adb.FileExistsOnDevice(self._GetFifo()):
       print 'Fifo created...'
       break
     time.sleep(i)
   else:
     raise Exception('Unable to find fifo on device %s ' % self._GetFifo())
   args = shlex.split(self.adb.Adb()._target_arg)
   args += ['shell', 'cat', self._GetFifo()]
   return pexpect.spawn('adb', args, timeout=timeout, logfile=logfile)
开发者ID:Andrel322,项目名称:gecko-dev,代码行数:11,代码来源:test_package_apk.py

示例7: _WatchFifo

 def _WatchFifo(self, timeout, logfile=None):
     for i in range(10):
         if self.adb.FileExistsOnDevice(self._GetFifo()):
             print "Fifo created..."
             break
         time.sleep(i)
     else:
         raise errors.DeviceUnresponsiveError("Unable to find fifo on device %s " % self._GetFifo())
     args = shlex.split(self.adb.Adb()._target_arg)
     args += ["shell", "cat", self._GetFifo()]
     return pexpect.spawn("adb", args, timeout=timeout, logfile=logfile)
开发者ID:badwtg1111,项目名称:webrtc_voe_arm_pass,代码行数:11,代码来源:test_package_apk.py

示例8: _WatchFifo

 def _WatchFifo(self, device, timeout, logfile=None):
   for i in range(10):
     if device.FileExists(self._GetFifo()):
       logging.info('Fifo created.')
       break
     time.sleep(i)
   else:
     raise device_errors.DeviceUnreachableError(
         'Unable to find fifo on device %s ' % self._GetFifo())
   args = shlex.split(device.old_interface.Adb()._target_arg)
   args += ['shell', 'cat', self._GetFifo()]
   return pexpect.spawn('adb', args, timeout=timeout, logfile=logfile)
开发者ID:eth-srl,项目名称:ChromeER,代码行数:12,代码来源:test_package_apk.py

示例9: StartupQuicServer

 def StartupQuicServer(self, device):
   self._process = pexpect.spawn(QUIC_SERVER,
                                 ['--quic_in_memory_cache_dir=%s' %
                                     self._quic_server_doc_root,
                                  '--port=%d' % QUIC_PORT])
   assert self._process != None
   # Wait for quic_server to start serving.
   waited_s = 0
   while subprocess.call([QUIC_CLIENT,
                          '--host=%s' % GetServersHost(device),
                          '--port=%d' % QUIC_PORT,
                          'http://%s:%d/%s' % (GetServersHost(device),
                                               QUIC_PORT, SMALL_RESOURCE)],
                         stdout=open(os.devnull, 'w')) != 0:
     sleep(0.1)
     waited_s += 0.1
     assert waited_s < 5, "quic_server failed to start after %fs" % waited_s
开发者ID:mtucker6784,项目名称:chromium,代码行数:17,代码来源:run.py

示例10: UpdateSDK

def UpdateSDK(api_level, package_name, package_pattern, timeout):
  """This function update SDK with a filter index.

  Args:
    api_level: the Android API level to download for.
    package_name: logging name of package that is being updated.
    package_pattern: the pattern to match the filter index from.
    timeout: the amount of time wait for update command.
  """
  android_binary = os.path.join(constants.ANDROID_SDK_ROOT, 'tools', 'android')

  list_sdk_repo_command = [android_binary, 'list', 'sdk', '--all']

  exit_code, stdout = cmd_helper.GetCmdStatusAndOutput(list_sdk_repo_command)

  if exit_code != 0:
    raise Exception('\'android list sdk --all\' command return %d' % exit_code)

  for line in stdout.split('\n'):
    match = package_pattern.match(line)
    if match:
      index = match.group(1)
      logging.info('package %s corresponds to %s with api level %d',
                   index, package_name, api_level)
      update_command = [android_binary, 'update', 'sdk', '--no-ui', '--all',
                         '--filter', index]
      update_command_str = ' '.join(update_command)
      logging.info('running update command: %s', update_command_str)
      update_process = pexpect.spawn(update_command_str)

      if update_process.expect('Do you accept the license') != 0:
        raise Exception('License agreement check failed')
      update_process.sendline('y')
      if update_process.expect(
        'Done. 1 package installed.', timeout=timeout) == 0:
        logging.info('Successfully installed %s for API level %d',
                      package_name, api_level)
        return
      else:
        raise Exception('Failed to install platform update')
  raise Exception('Could not find android-%d update for the SDK!' % api_level)
开发者ID:bearmingo,项目名称:build-tool,代码行数:41,代码来源:install_emulator_deps.py

示例11: StartupQuicServer

 def StartupQuicServer(self, device):
   self._process = pexpect.spawn(QUIC_SERVER,
                                 ['--quic_in_memory_cache_dir=%s' %
                                     self._quic_server_doc_root,
                                  '--certificate_file=%s' % QUIC_CERT,
                                  '--key_file=%s' % QUIC_KEY,
                                  '--port=%d' % QUIC_PORT])
   assert self._process != None
   # Wait for quic_server to start serving.
   waited_s = 0
   while subprocess.call(['lsof', '-i', 'udp:%d' % QUIC_PORT, '-p',
                          '%d' % self._process.pid],
                         stdout=open(os.devnull, 'w')) != 0:
     sleep(0.1)
     waited_s += 0.1
     assert waited_s < 5, "quic_server failed to start after %fs" % waited_s
   # Push certificate to device.
   cert = open(QUIC_CERT, 'r').read()
   device_cert_path = os.path.join(device.GetExternalStoragePath(), CERT_PATH)
   device.RunShellCommand('mkdir -p %s' % device_cert_path)
   device.WriteFile(os.path.join(device_cert_path, QUIC_CERT_FILENAME), cert)
开发者ID:Samsung,项目名称:ChromiumGStreamerBackend,代码行数:21,代码来源:run.py

示例12: StartupHttpServer

  def StartupHttpServer(self):
    """Starts up a http server with specified document root and port."""
    # If we want a specific port, make sure no one else is listening on it.
    if self.fixed_port:
      self._KillProcessListeningOnPort(self.fixed_port)
    while True:
      if self.base_config_path:
        # Read the config
        with codecs.open(self.base_config_path, 'r', 'utf-8') as f:
          config_contents = f.read()
      else:
        config_contents = self._GetDefaultBaseConfig()
      if self.extra_config_contents:
        config_contents += self.extra_config_contents
      # Write out the config, filling in placeholders from the members of |self|
      with codecs.open(self.config_path, 'w', 'utf-8') as f:
        f.write(config_contents % self.__dict__)
      if (not os.path.exists(self.lighttpd_path) or
          not os.access(self.lighttpd_path, os.X_OK)):
        raise EnvironmentError(
            'Could not find lighttpd at %s.\n'
            'It may need to be installed (e.g. sudo apt-get install lighttpd)'
            % self.lighttpd_path)
      # pylint: disable=no-member
      self.process = pexpect.spawn(self.lighttpd_path,
                                   ['-D', '-f', self.config_path,
                                    '-m', self.lighttpd_module_path],
                                   cwd=self.temp_dir)
      client_error, server_error = self._TestServerConnection()
      if not client_error:
        assert int(open(self.pid_file, 'r').read()) == self.process.pid
        break
      self.process.close()

      if self.fixed_port or 'in use' not in server_error:
        print 'Client error:', client_error
        print 'Server error:', server_error
        return False
      self.port = self._GetRandomPort()
    return True
开发者ID:jankeromnes,项目名称:chromium,代码行数:40,代码来源:lighttpd_server.py

示例13: StartupQuicServer

 def StartupQuicServer(self, adb):
     self._process = pexpect.spawn(
         QUIC_SERVER, ["--quic_in_memory_cache_dir=%s" % self._quic_server_doc_root, "--port=%d" % QUIC_PORT]
     )
     assert self._process != None
     # Wait for quic_server to start serving.
     waited_s = 0
     while (
         subprocess.call(
             [
                 QUIC_CLIENT,
                 "--host=%s" % GetServersHost(adb),
                 "--port=%d" % QUIC_PORT,
                 "http://%s:%d/%s" % (GetServersHost(adb), QUIC_PORT, SMALL_RESOURCE),
             ],
             stdout=open(os.devnull, "w"),
         )
         != 0
     ):
         sleep(0.1)
         waited_s += 0.1
         assert waited_s < 5, "quic_server failed to start after %fs" % waited_s
开发者ID:heberthbraga,项目名称:webrtc,代码行数:22,代码来源:run.py

示例14: GetSDKPlatform

def GetSDKPlatform(api_level=DEFAULT_ANDROID_API_LEVEL):
  """Update the SDK to include the platform specified.

  Args:
    api_level: the Android API level to download
  """
  android_binary = os.path.join(constants.EMULATOR_SDK_ROOT,
                                'sdk', 'tools', 'android')
  pattern = re.compile('\s*([0-9]+)- SDK Platform Android [\.,0-9]+, API %d.*' %
                       api_level)
  # Example:
  #   2- SDK Platform Android 4.3, API 18, revision 2
  exit_code, stdout = cmd_helper.GetCmdStatusAndOutput(
      [android_binary, 'list', 'sdk'])
  if exit_code != 0:
    raise Exception('\'android list sdk\' command return %d' % exit_code)
  for line in stdout.split('\n'):
    match = pattern.match(line)
    if match:
      index = match.group(1)
      print('package %s corresponds to platform level %d' % (index, api_level))
      # update sdk --no-ui --filter $INDEX
      update_command = [android_binary,
                        'update', 'sdk', '--no-ui', '--filter', index]
      update_command_str = ' '.join(update_command)
      logging.info('running update command: %s' % update_command_str)
      update_process = pexpect.spawn(update_command_str)
      # TODO(andrewhayden): Do we need to bug the user about this?
      if update_process.expect('Do you accept the license') != 0:
        raise Exception('License agreement check failed')
      update_process.sendline('y')
      if update_process.expect('Done. 1 package installed.') == 0:
        print('Successfully installed platform for API level %d' % api_level)
        return
      else:
        raise Exception('Failed to install platform update')
  raise Exception('Could not find android-%d update for the SDK!' % api_level)
开发者ID:Bogon,项目名称:chromium,代码行数:37,代码来源:install_emulator_deps.py

示例15: StartMonitoringLogcat

  def StartMonitoringLogcat(self, clear=True, timeout=10, logfile=None,
                            filters=None):
    """Starts monitoring the output of logcat, for use with WaitForLogMatch.

    Args:
      clear: If True the existing logcat output will be cleared, to avoiding
             matching historical output lurking in the log.
      timeout: How long WaitForLogMatch will wait for the given match
      filters: A list of logcat filters to be used.
    """
    if clear:
      self.RunShellCommand('logcat -c')
    args = []
    if self._adb._target_arg:
      args += shlex.split(self._adb._target_arg)
    args += ['logcat', '-v', 'threadtime']
    if filters:
      args.extend(filters)
    else:
      args.append('*:v')

    if logfile:
      logfile = NewLineNormalizer(logfile)

    # Spawn logcat and syncronize with it.
    for _ in range(4):
      self._logcat = pexpect.spawn('adb', args, timeout=timeout,
                                   logfile=logfile)
      self.RunShellCommand('log startup_sync')
      if self._logcat.expect(['startup_sync', pexpect.EOF,
                              pexpect.TIMEOUT]) == 0:
        break
      self._logcat.close(force=True)
    else:
      logging.critical('Error reading from logcat: ' + str(self._logcat.match))
      sys.exit(1)
开发者ID:Andrel322,项目名称:gecko-dev,代码行数:36,代码来源:android_commands.py


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