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

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

Issue 149503005: Change actions.txt to actions.xml (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comment on patch 34 Created 6 years, 9 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
« no previous file with comments | « tools/metrics/histograms/update_extension_functions.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 re 12 import re
12 import sys 13 import sys
13 14
14 from ast import literal_eval 15 from ast import literal_eval
15 from optparse import OptionParser 16 from optparse import OptionParser
16 from xml.dom import minidom 17 from xml.dom import minidom
17 18
18 from diffutil import PromptUserToAcceptDiff 19 import print_style
19 from pretty_print import PrettyPrintNode 20
21 # Import the metrics/common module.
22 sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common'))
23 from diff_util import PromptUserToAcceptDiff
20 24
21 HISTOGRAMS_PATH = 'histograms.xml' 25 HISTOGRAMS_PATH = 'histograms.xml'
22 POLICY_TEMPLATES_PATH = 26 POLICY_TEMPLATES_PATH = (
23 '../../../components/policy/resources/policy_templates.json' 27 '../../../components/policy/resources/policy_templates.json')
24 ENUM_NAME = 'EnterprisePolicies' 28 ENUM_NAME = 'EnterprisePolicies'
25 29
26 class UserError(Exception): 30 class UserError(Exception):
27 def __init__(self, message): 31 def __init__(self, message):
28 Exception.__init__(self, message) 32 Exception.__init__(self, message)
29 33
30 @property 34 @property
31 def message(self): 35 def message(self):
32 return self.args[0] 36 return self.args[0]
33 37
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 sys.exit(1) 115 sys.exit(1)
112 116
113 with open(POLICY_TEMPLATES_PATH, 'rb') as f: 117 with open(POLICY_TEMPLATES_PATH, 'rb') as f:
114 policy_templates = literal_eval(f.read()) 118 policy_templates = literal_eval(f.read())
115 with open(HISTOGRAMS_PATH, 'rb') as f: 119 with open(HISTOGRAMS_PATH, 'rb') as f:
116 histograms_doc = minidom.parse(f) 120 histograms_doc = minidom.parse(f)
117 f.seek(0) 121 f.seek(0)
118 xml = f.read() 122 xml = f.read()
119 123
120 UpdateHistogramDefinitions(policy_templates, histograms_doc) 124 UpdateHistogramDefinitions(policy_templates, histograms_doc)
121 125 new_xml = print_style.GetPrintStyle().PrettyPrintNode(histograms_doc)
122 new_xml = PrettyPrintNode(histograms_doc)
123 if PromptUserToAcceptDiff(xml, new_xml, 'Is the updated version acceptable?'): 126 if PromptUserToAcceptDiff(xml, new_xml, 'Is the updated version acceptable?'):
124 with open(HISTOGRAMS_PATH, 'wb') as f: 127 with open(HISTOGRAMS_PATH, 'wb') as f:
125 f.write(new_xml) 128 f.write(new_xml)
126 129
127 130
128 if __name__ == '__main__': 131 if __name__ == '__main__':
129 try: 132 try:
130 main() 133 main()
131 except UserError as e: 134 except UserError as e:
132 print >>sys.stderr, e.message 135 print >>sys.stderr, e.message
133 sys.exit(1) 136 sys.exit(1)
OLDNEW
« no previous file with comments | « tools/metrics/histograms/update_extension_functions.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698