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

Side by Side Diff: components/policy/resources/PRESUBMIT.py

Issue 108513011: Move chrome/app/policy into components/policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « components/policy/resources/OWNERS ('k') | components/policy/resources/policy_templates.grd » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 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 # If this presubmit check fails or misbehaves, please complain to 5 # If this presubmit check fails or misbehaves, please complain to
6 # mnissler@chromium.org, pastarmovj@chromium.org or joaodasilva@chromium.org. 6 # mnissler@chromium.org, pastarmovj@chromium.org or joaodasilva@chromium.org.
7 7
8 import itertools 8 import itertools
9 import sys 9 import sys
10 import xml.dom.minidom 10 import xml.dom.minidom
11 11
12 def _GetPolicyTemplates(template_path): 12 def _GetPolicyTemplates(template_path):
13 # Read list of policies in the template. eval() is used instead of a JSON 13 # Read list of policies in the template. eval() is used instead of a JSON
14 # parser because policy_templates.json is not quite JSON, and uses some 14 # parser because policy_templates.json is not quite JSON, and uses some
15 # python features such as #-comments and '''strings'''. policy_templates.json 15 # python features such as #-comments and '''strings'''. policy_templates.json
16 # is actually maintained as a python dictionary. 16 # is actually maintained as a python dictionary.
17 with open(template_path) as f: 17 with open(template_path) as f:
18 template_data = eval(f.read(), {}) 18 template_data = eval(f.read(), {})
19 policies = ( policy 19 policies = ( policy
20 for policy in template_data['policy_definitions'] 20 for policy in template_data['policy_definitions']
21 if policy['type'] != 'group' ) 21 if policy['type'] != 'group' )
22 groups = ( policy['policies'] 22 groups = ( policy['policies']
23 for policy in template_data['policy_definitions'] 23 for policy in template_data['policy_definitions']
24 if policy['type'] == 'group' ) 24 if policy['type'] == 'group' )
25 subpolicies = ( policy for group in groups for policy in group ) 25 subpolicies = ( policy for group in groups for policy in group )
26 return list(itertools.chain(policies, subpolicies)) 26 return list(itertools.chain(policies, subpolicies))
27 27
28 def _CheckPolicyTemplatesSyntax(input_api, output_api): 28 def _CheckPolicyTemplatesSyntax(input_api, output_api):
29 filepath = input_api.os_path.join(input_api.PresubmitLocalPath(), 29 local_path = input_api.PresubmitLocalPath()
30 'policy_templates.json') 30 filepath = input_api.os_path.join(local_path, 'policy_templates.json')
31 if any(f.AbsoluteLocalPath() == filepath 31 if any(f.AbsoluteLocalPath() == filepath
32 for f in input_api.AffectedFiles()): 32 for f in input_api.AffectedFiles()):
33 old_sys_path = sys.path 33 old_sys_path = sys.path
34 try: 34 try:
35 sys.path = [input_api.PresubmitLocalPath()] + sys.path 35 tools_path = input_api.os_path.normpath(
36 input_api.os_path.join(local_path, input_api.os_path.pardir, 'tools'))
37 sys.path = [ tools_path ] + sys.path
36 # Optimization: only load this when it's needed. 38 # Optimization: only load this when it's needed.
37 import syntax_check_policy_template_json 39 import syntax_check_policy_template_json
38 checker = syntax_check_policy_template_json.PolicyTemplateChecker() 40 checker = syntax_check_policy_template_json.PolicyTemplateChecker()
39 if checker.Run([], filepath) > 0: 41 if checker.Run([], filepath) > 0:
40 return [output_api.PresubmitError('Syntax error(s) in file:', 42 return [output_api.PresubmitError('Syntax error(s) in file:',
41 [filepath])] 43 [filepath])]
42 finally: 44 finally:
43 sys.path = old_sys_path 45 sys.path = old_sys_path
44 return [] 46 return []
45 47
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 111
110 return results 112 return results
111 113
112 114
113 def CheckChangeOnUpload(input_api, output_api): 115 def CheckChangeOnUpload(input_api, output_api):
114 return _CommonChecks(input_api, output_api) 116 return _CommonChecks(input_api, output_api)
115 117
116 118
117 def CheckChangeOnCommit(input_api, output_api): 119 def CheckChangeOnCommit(input_api, output_api):
118 return _CommonChecks(input_api, output_api) 120 return _CommonChecks(input_api, output_api)
OLDNEW
« no previous file with comments | « components/policy/resources/OWNERS ('k') | components/policy/resources/policy_templates.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698