Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: tools/metrics/histograms/update_policies.py

Issue 1143323006: Histograms.xml python script housekeeping (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bad_message
Patch Set: Split off the extensions permission weirdness. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Updates EnterprisePolicies enum in histograms.xml file with policy 5 """Updates EnterprisePolicies enum in histograms.xml file with policy
6 definitions read from policy_templates.json. 6 definitions read from policy_templates.json.
7 7
8 If the file was pretty-printed, the updated version is pretty-printed too. 8 If the file was pretty-printed, the updated version is pretty-printed too.
9 """ 9 """
10 10
11 import os 11 import os
12 import re 12 import re
13 import sys 13 import sys
14 14
15 from ast import literal_eval 15 from ast import literal_eval
16 from optparse import OptionParser 16 from optparse import OptionParser
17 from xml.dom import minidom 17 from xml.dom import minidom
18 18
19 import print_style 19 import print_style
20 import histograms_path
20 21
21 # Import the metrics/common module. 22 # Import the metrics/common module.
22 sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common')) 23 sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common'))
23 from diff_util import PromptUserToAcceptDiff 24 from diff_util import PromptUserToAcceptDiff
24 25
25 HISTOGRAMS_PATH = 'histograms.xml' 26 HISTOGRAMS_PATH = histograms_path.GetHistogramsFile()
26 POLICY_TEMPLATES_PATH = ( 27 POLICY_TEMPLATES_PATH = 'components/policy/resources/policy_templates.json'
27 '../../../components/policy/resources/policy_templates.json')
28 ENUM_NAME = 'EnterprisePolicies' 28 ENUM_NAME = 'EnterprisePolicies'
29 29
30 class UserError(Exception): 30 class UserError(Exception):
31 def __init__(self, message): 31 def __init__(self, message):
32 Exception.__init__(self, message) 32 Exception.__init__(self, message)
33 33
34 @property 34 @property
35 def message(self): 35 def message(self):
36 return self.args[0] 36 return self.args[0]
37 37
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 node.attributes['label'] = ParsePlaceholders(policy['caption']) 107 node.attributes['label'] = ParsePlaceholders(policy['caption'])
108 policy_enum_node.appendChild(node) 108 policy_enum_node.appendChild(node)
109 109
110 110
111 def main(): 111 def main():
112 if len(sys.argv) > 1: 112 if len(sys.argv) > 1:
113 print >>sys.stderr, 'No arguments expected!' 113 print >>sys.stderr, 'No arguments expected!'
114 sys.stderr.write(__doc__) 114 sys.stderr.write(__doc__)
115 sys.exit(1) 115 sys.exit(1)
116 116
117 with open(POLICY_TEMPLATES_PATH, 'rb') as f: 117 with open(histograms_path.GetInputFile(POLICY_TEMPLATES_PATH), 'rb') as f:
118 policy_templates = literal_eval(f.read()) 118 policy_templates = literal_eval(f.read())
119 with open(HISTOGRAMS_PATH, 'rb') as f: 119 with open(HISTOGRAMS_PATH, 'rb') as f:
120 histograms_doc = minidom.parse(f) 120 histograms_doc = minidom.parse(f)
121 f.seek(0) 121 f.seek(0)
122 xml = f.read() 122 xml = f.read()
123 123
124 UpdateHistogramDefinitions(policy_templates, histograms_doc) 124 UpdateHistogramDefinitions(policy_templates, histograms_doc)
125 new_xml = print_style.GetPrintStyle().PrettyPrintNode(histograms_doc) 125 new_xml = print_style.GetPrintStyle().PrettyPrintNode(histograms_doc)
126 if PromptUserToAcceptDiff(xml, new_xml, 'Is the updated version acceptable?'): 126 if PromptUserToAcceptDiff(xml, new_xml, 'Is the updated version acceptable?'):
127 with open(HISTOGRAMS_PATH, 'wb') as f: 127 with open(HISTOGRAMS_PATH, 'wb') as f:
128 f.write(new_xml) 128 f.write(new_xml)
129 129
130 130
131 if __name__ == '__main__': 131 if __name__ == '__main__':
132 try: 132 try:
133 main() 133 main()
134 except UserError as e: 134 except UserError as e:
135 print >>sys.stderr, e.message 135 print >>sys.stderr, e.message
136 sys.exit(1) 136 sys.exit(1)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698