@classmethod
  def shell(cls, command, is_verbose, num_retries=DEFAULT_NUM_RETRIES,
    stdin=None):
    """Executes a command on this machine, retrying it up to five times if it
    initially fails.

    Args:
      command: A str representing the command to execute.
      is_verbose: A bool that indicates if we should print the command we are
        executing to stdout.
      num_retries: The number of times we should try to execute the given
        command before aborting.
      stdin: A str that is passes as standard input to the process
    Returns:
      A str with both the standard output and standard error produced when the
      command executes.
    Raises:
      ShellException: If, after five attempts, executing the named command
      failed.
    """
    tries_left = num_retries
    try:
      while tries_left:
        AppScaleLogger.verbose("shell> {0}".format(command), is_verbose)
        the_temp_file = tempfile.NamedTemporaryFile()
        if stdin is not None:
          stdin_strio = tempfile.TemporaryFile()
          stdin_strio.write(stdin)
          stdin_strio.seek(0)
          AppScaleLogger.verbose("       stdin str: {0}"\
            .format(stdin), is_verbose)
          result = subprocess.Popen(command, shell=True, stdout=the_temp_file,
            stdin=stdin_strio, stderr=subprocess.STDOUT)
        else:
          result = subprocess.Popen(command, shell=True, stdout=the_temp_file,
            stderr=subprocess.STDOUT)
        AppScaleLogger.verbose("       stdout buffer: {0}"\
          .format(the_temp_file.name), is_verbose)
        result.wait()
        if stdin is not None:
          stdin_strio.close()
        if result.returncode == 0:
          the_temp_file.seek(0)
          output = the_temp_file.read()
          the_temp_file.close()
          return output
        tries_left -= 1
        if tries_left:
          the_temp_file.close()
          AppScaleLogger.verbose("Command failed. Trying again momentarily." \
            .format(command), is_verbose)
        else:
          the_temp_file.seek(0)
          output = the_temp_file.read()
          the_temp_file.close()
          if stdin:
            raise ShellException("Executing command '{0} {1}' failed:\n{2}"\
                    .format(command, stdin, output))
          else:
            raise ShellException("Executing command '{0}' failed:\n{1}"\
                    .format(command, output))
        time.sleep(1)
    except __HOLE__ as os_error:
      if stdin:
        raise ShellException("Error executing command: '{0} {1}':{2}"\
                .format(command, stdin, os_error))
      else:
        raise ShellException("Error executing command: '{0}':{1}"\
                .format(command, os_error))
dataset/ETHPy150Open AppScale/appscale-tools/lib/local_state.py/LocalState.shell