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
9 If the file was pretty-printed, the updated version is pretty-printed too.
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 POSITIVE_ERROR_REGEX
= re
.compile(r
'^NET_ERROR\(([\w]+), -([0-9]+)\)')
22 NEGATIVE_ERROR_REGEX
= re
.compile(r
'^NET_ERROR\(([\w]+), (-[0-9]+)\)')
24 def ReadNetErrorCodes(filename
, error_regex
):
25 """Reads in values from net_error_list.h, returning a dictionary mapping
26 error code to error name.
28 # Read the file as a list of lines
29 with
open(filename
) as f
:
30 content
= f
.readlines()
32 # Parse out lines that are net errors.
35 m
= error_regex
.match(line
)
37 errors
[int(m
.group(2))] = m
.group(1)
42 print >>sys
.stderr
, 'No arguments expected!'
43 sys
.stderr
.write(__doc__
)
46 UpdateHistogramFromDict(
48 ReadNetErrorCodes(NET_ERROR_LIST_PATH
, POSITIVE_ERROR_REGEX
),
51 UpdateHistogramFromDict(
52 'CombinedHttpResponseAndNetErrorCode',
53 ReadNetErrorCodes(NET_ERROR_LIST_PATH
, NEGATIVE_ERROR_REGEX
),
56 if __name__
== '__main__':