tools/metrics/md2xml.py
def GetMetricsFromMdFile(mdfile):
  """Returns an array of metrics parsed from the markdown file. See the top of
  the file for documentation on the format of the markdown file.
  """
  with open(mdfile) as f:
    raw_md = f.read()
  metrics = []
  sections = re.split('\n---+\n', raw_md)
  tag_pattern = re.compile('^\* ([^:]*): (.*)$')
  for section in sections:
    if len(section.strip()) == 0: break
    lines = section.strip().split('\n')
    # The first line should have the header, containing the name of the metric.
    header_match = re.match('^##+ ', lines[0])
    if not header_match: continue
    metric = {}
    metric['name'] = lines[0][len(header_match.group(0)):]
    for i in range(1, len(lines)):
      if len(lines[i]) == 0:
        i += 1
        break
      match = tag_pattern.match(lines[i])
      assert match
      assert IsTagKnown(match.group(1)), 'Unknown tag: "%s".' % (match.group(1))
      assert IsTagValid(match.group(1), match.group(2)), 'Invalid value "%s" ' \
          'for tag "%s".' % (match.group(2), match.group(1))
      metric[match.group(1)] = match.group(2)
    assert i < len(lines), 'No summary found for "%s"' % metric['name']
    metric['summary'] = '\n'.join(lines[i:])
    assert 'owners' in metric, 'Must have owners for "%s"' % metric['name']
    assert 'enum' in metric or 'units' in metric, 'Metric "%s" must have ' \
        'a unit listed in "enum" or "units".' % metric['name']
    metrics.append(metric)
  return metrics
Returns an array of metrics parsed from the markdown file. See the top of
  the file for documentation on the format of the markdown file.
  
Returns an array of metrics parsed from the markdown file. See the top of
the file for documentation on the format of the markdown file.
Returns an array of metrics parsed from the markdown file . See the top of the file for documentation on the format of the markdown file .
def GetMetricsFromMdFile(mdfile):
  with open(mdfile) as f:
    raw_md = f.read()
  metrics = []
  sections = re.split('\n---+\n', raw_md)
  tag_pattern = re.compile('^\* ([^:]*): (.*)$')
  for section in sections:
    if len(section.strip()) == 0: break
    lines = section.strip().split('\n')
    header_match = re.match('^##+ ', lines[0])
    if not header_match: continue
    metric = {}
    metric['name'] = lines[0][len(header_match.group(0)):]
    for i in range(1, len(lines)):
      if len(lines[i]) == 0:
        i += 1
        break
      match = tag_pattern.match(lines[i])
      assert match
      assert IsTagKnown(match.group(1)), 'Unknown tag: "%s".' % (match.group(1))
      assert IsTagValid(match.group(1), match.group(2)), 'Invalid value "%s" ' \
          'for tag "%s".' % (match.group(2), match.group(1))
      metric[match.group(1)] = match.group(2)
    assert i < len(lines), 'No summary found for "%s"' % metric['name']
    metric['summary'] = '\n'.join(lines[i:])
    assert 'owners' in metric, 'Must have owners for "%s"' % metric['name']
    assert 'enum' in metric or 'units' in metric, 'Metric "%s" must have ' \
        'a unit listed in "enum" or "units".' % metric['name']
    metrics.append(metric)
  return metrics
def GetMetricsFromMdFile ( mdfile ) : with open ( mdfile ) as f : raw_md = f . read ( ) metrics = [ ] sections = re . split ( '\n---+\n' , raw_md ) tag_pattern = re . compile ( '^\* ([^:]*): (.*)$' ) for section in sections : if len ( section . strip ( ) ) == 0 : break lines = section . strip ( ) . split ( '\n' ) header_match = re . match ( '^##+ ' , lines [ 0 ] ) if not header_match : continue metric = { } metric [ 'name' ] = lines [ 0 ] [ len ( header_match . group ( 0 ) ) : ] for i in range ( 1 , len ( lines ) ) : if len ( lines [ i ] ) == 0 : i += 1 break match = tag_pattern . match ( lines [ i ] ) assert match assert IsTagKnown ( match . group ( 1 ) ) , 'Unknown tag: "%s".' % ( match . group ( 1 ) ) assert IsTagValid ( match . group ( 1 ) , match . group ( 2 ) ) , 'Invalid value "%s" ' 'for tag "%s".' % ( match . group ( 2 ) , match . group ( 1 ) ) metric [ match . group ( 1 ) ] = match . group ( 2 ) assert i < len ( lines ) , 'No summary found for "%s"' % metric [ 'name' ] metric [ 'summary' ] = '\n' . join ( lines [ i : ] ) assert 'owners' in metric , 'Must have owners for "%s"' % metric [ 'name' ] assert 'enum' in metric or 'units' in metric , 'Metric "%s" must have ' 'a unit listed in "enum" or "units".' % metric [ 'name' ] metrics . append ( metric ) return metrics
Returns an array of metrics parsed from the markdown file.
Returns an array of metrics parsed from the markdown file .
"""Returns an array of metrics parsed from the markdown file. See the top of
  the file for documentation on the format of the markdown file.
  """ # The first line should have the header, containing the name of the metric.
mdfile