scripts/update_configuration_doc.py
def ParseProtoFile(proto_file):
  """Computes the list of Message objects of the option messages in a file."""
  line_iter = iter(proto_file)

  # We ignore the license header and search for the 'package' line.
  for line in line_iter:
    line = line.strip()
    if line.startswith('package'):
      assert line[-1] == ';'
      package = line[7:-1].strip()
      break
    else:
      assert '}' not in line

  message_list = []
  while True:
    # Search for the next options message and capture preceding comments.
    message_comments = []
    for line in line_iter:
      line = line.strip()
      if '}' in line:
        # The preceding comments were for a different message it seems.
        message_comments = []
      elif line.startswith('//'):
        # We keep comments preceding an options message.
        comment = line[2:].strip()
        if not comment.startswith('NEXT ID:'):
          message_comments.append(comment)
      elif line.startswith('message') and line.endswith('Options {'):
        message_name = package + '.' + line[7:-1].strip()
        break
    else:
      # We reached the end of file.
      break
    print(" Found '%s'." % message_name)
    message = Message(message_name, package, message_comments)
    message_list.append(message)

    # We capture the contents of this message.
    option_comments = []
    multiline = ''
    for line in line_iter:
      line = line.strip()
      if '}' in line:
        # We reached the end of this message.
        message.AddTrailingComments(option_comments)
        break
      elif line.startswith('//'):
        comment = line[2:].strip()
        if not comment.startswith('NEXT ID:'):
          option_comments.append(comment)
      else:
        assert not line.startswith('required')
        multiline += ' ' + line
        if not multiline.endswith(';'):
          continue
        assert len(multiline) < 200
        option = multiline[:-1].strip().rstrip('0123456789').strip()
        assert option.endswith('=')
        if option.startswith('repeated'):
          option = option[8:]
        option_type, option_name = option[:-1].strip().split();
        print("  Option '%s'." % option_name)
        multiline = ''
        message.AddOption(option_type, option_name, option_comments)
        option_comments = []

  return message_list
Computes the list of Message objects of the option messages in a file.
Computes the list of Message objects of the option messages in a file.
Computes the list of Message objects of the option messages in a file .
def ParseProtoFile(proto_file):
  line_iter = iter(proto_file)
  for line in line_iter:
    line = line.strip()
    if line.startswith('package'):
      assert line[-1] == ';'
      package = line[7:-1].strip()
      break
    else:
      assert '}' not in line
  message_list = []
  while True:
    message_comments = []
    for line in line_iter:
      line = line.strip()
      if '}' in line:
        message_comments = []
      elif line.startswith('//'):
        comment = line[2:].strip()
        if not comment.startswith('NEXT ID:'):
          message_comments.append(comment)
      elif line.startswith('message') and line.endswith('Options {'):
        message_name = package + '.' + line[7:-1].strip()
        break
    else:
      break
    print(" Found '%s'." % message_name)
    message = Message(message_name, package, message_comments)
    message_list.append(message)
    option_comments = []
    multiline = ''
    for line in line_iter:
      line = line.strip()
      if '}' in line:
        message.AddTrailingComments(option_comments)
        break
      elif line.startswith('//'):
        comment = line[2:].strip()
        if not comment.startswith('NEXT ID:'):
          option_comments.append(comment)
      else:
        assert not line.startswith('required')
        multiline += ' ' + line
        if not multiline.endswith(';'):
          continue
        assert len(multiline) < 200
        option = multiline[:-1].strip().rstrip('0123456789').strip()
        assert option.endswith('=')
        if option.startswith('repeated'):
          option = option[8:]
        option_type, option_name = option[:-1].strip().split();
        print("  Option '%s'." % option_name)
        multiline = ''
        message.AddOption(option_type, option_name, option_comments)
        option_comments = []
  return message_list
def ParseProtoFile ( proto_file ) : line_iter = iter ( proto_file ) for line in line_iter : line = line . strip ( ) if line . startswith ( 'package' ) : assert line [ - 1 ] == ';' package = line [ 7 : - 1 ] . strip ( ) break else : assert '}' not in line message_list = [ ] while True : message_comments = [ ] for line in line_iter : line = line . strip ( ) if '}' in line : message_comments = [ ] elif line . startswith ( '//' ) : comment = line [ 2 : ] . strip ( ) if not comment . startswith ( 'NEXT ID:' ) : message_comments . append ( comment ) elif line . startswith ( 'message' ) and line . endswith ( 'Options {' ) : message_name = package + '.' + line [ 7 : - 1 ] . strip ( ) break else : break print ( " Found '%s'." % message_name ) message = Message ( message_name , package , message_comments ) message_list . append ( message ) option_comments = [ ] multiline = '' for line in line_iter : line = line . strip ( ) if '}' in line : message . AddTrailingComments ( option_comments ) break elif line . startswith ( '//' ) : comment = line [ 2 : ] . strip ( ) if not comment . startswith ( 'NEXT ID:' ) : option_comments . append ( comment ) else : assert not line . startswith ( 'required' ) multiline += ' ' + line if not multiline . endswith ( ';' ) : continue assert len ( multiline ) < 200 option = multiline [ : - 1 ] . strip ( ) . rstrip ( '0123456789' ) . strip ( ) assert option . endswith ( '=' ) if option . startswith ( 'repeated' ) : option = option [ 8 : ] option_type , option_name = option [ : - 1 ] . strip ( ) . split ( ) ; print ( "  Option '%s'." % option_name ) multiline = '' message . AddOption ( option_type , option_name , option_comments ) option_comments = [ ] return message_list
Computes the list of Message objects of the option messages in a file.
Computes the list of Message objects of the option messages in a file .
"""Computes the list of Message objects of the option messages in a file.""" # We ignore the license header and search for the 'package' line. # Search for the next options message and capture preceding comments. # The preceding comments were for a different message it seems. # We keep comments preceding an options message. # We reached the end of file. # We capture the contents of this message. # We reached the end of this message.
proto_file