Revert "Always activate MojoApplicationHost"
[chromium-blink-merge.git] / tools / metrics / histograms / update_net_error_codes.py
blobbfb3bcf9523784614c3e4eb4383c12fa595e384e
1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Updates NetErrorCodes enum in histograms.xml file with values read
7 from net_error_list.h.
9 If the file was pretty-printed, the updated version is pretty-printed too.
10 """
12 import os.path
13 import re
14 import sys
16 sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common'))
17 from update_histogram_enum import UpdateHistogramFromDict
19 NET_ERROR_LIST_PATH = '../../../net/base/net_error_list.h'
21 def ReadNetErrorCodes(filename):
22 """Reads in values from net_error_list.h, returning a dictionary mapping
23 error code to error name.
24 """
25 # Read the file as a list of lines
26 with open(filename) as f:
27 content = f.readlines()
29 ERROR_REGEX = re.compile(r'^NET_ERROR\(([\w]+), -([0-9]+)\)')
31 # Parse out lines that are net errors.
32 errors = {}
33 for line in content:
34 m = ERROR_REGEX.match(line)
35 if m:
36 errors[int(m.group(2))] = m.group(1)
37 return errors
39 def main():
40 if len(sys.argv) > 1:
41 print >>sys.stderr, 'No arguments expected!'
42 sys.stderr.write(__doc__)
43 sys.exit(1)
45 UpdateHistogramFromDict(
46 'NetErrorCodes', ReadNetErrorCodes(NET_ERROR_LIST_PATH),
47 NET_ERROR_LIST_PATH)
49 if __name__ == '__main__':
50 main()