import re


def _GetIteChipidReStr(command):
  """Get a regexp for matching get_ite_chipid Servo console command output.

  Args:
    command: str - The actual console command that will be run.  This should
        either be 'get_ite_chipid' itself or another command with identical
        output.

  Returns:
    str - A regexp that will match either the expected output, or the usage
        output, because the latter is typically printed after any error message.
        Match group 1 will contain the output either way.  If it starts with
        'Usage:' then an error occurred.

  This returns str instead of re.compile() because that is what the
  pty_driver.ptyDriver._issue_cmd_get_results() interface accepts.
  """
  return (
      # Match the beginning of a line.
      r'[\r\n\f]('
      # Match the expected output.
      r'ITE EC info:[^\r\n\f]*'
      # Alternatively, match the usage output, because it is typically printed
      # after any error message.  This avoids waiting for the Servod pexpect
      # timeout after typical errors.
      r'|Usage: %s(?:[ \t\v]+[^\r\n\f]*)?'
      # Match the end of a line.
      r')[\r\n\f]' % (re.escape(command),))