OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 ''' | 6 ''' |
7 Checks a policy_templates.json file for conformity to its syntax specification. | 7 Checks a policy_templates.json file for conformity to its syntax specification. |
8 ''' | 8 ''' |
9 | 9 |
10 import json | 10 import json |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 if not isinstance(policy, dict): | 178 if not isinstance(policy, dict): |
179 self._Error('Each policy must be a dictionary.', 'policy', None, policy) | 179 self._Error('Each policy must be a dictionary.', 'policy', None, policy) |
180 return | 180 return |
181 | 181 |
182 # There should not be any unknown keys in |policy|. | 182 # There should not be any unknown keys in |policy|. |
183 for key in policy: | 183 for key in policy: |
184 if key not in ('name', 'type', 'caption', 'desc', 'device_only', | 184 if key not in ('name', 'type', 'caption', 'desc', 'device_only', |
185 'supported_on', 'label', 'policies', 'items', | 185 'supported_on', 'label', 'policies', 'items', |
186 'example_value', 'features', 'deprecated', 'future', | 186 'example_value', 'features', 'deprecated', 'future', |
187 'id', 'schema', 'max_size', 'tags', | 187 'id', 'schema', 'max_size', 'tags', |
188 'default_for_enterprise_users'): | 188 'default_for_enterprise_users', 'arc_support'): |
189 self.warning_count += 1 | 189 self.warning_count += 1 |
190 print ('In policy %s: Warning: Unknown key: %s' % | 190 print ('In policy %s: Warning: Unknown key: %s' % |
191 (policy.get('name'), key)) | 191 (policy.get('name'), key)) |
192 | 192 |
193 # Each policy must have a name. | 193 # Each policy must have a name. |
194 self._CheckContains(policy, 'name', str, regexp_check=NO_WHITESPACE) | 194 self._CheckContains(policy, 'name', str, regexp_check=NO_WHITESPACE) |
195 | 195 |
196 # Each policy must have a type. | 196 # Each policy must have a type. |
197 policy_types = ('group', 'main', 'string', 'int', 'list', 'int-enum', | 197 policy_types = ('group', 'main', 'string', 'int', 'list', 'int-enum', |
198 'string-enum', 'string-enum-list', 'dict', 'external') | 198 'string-enum', 'string-enum-list', 'dict', 'external') |
(...skipping 11 matching lines...) Expand all Loading... |
210 | 210 |
211 # If 'label' is present, it must be a string. | 211 # If 'label' is present, it must be a string. |
212 self._CheckContains(policy, 'label', str, True) | 212 self._CheckContains(policy, 'label', str, True) |
213 | 213 |
214 # If 'deprecated' is present, it must be a bool. | 214 # If 'deprecated' is present, it must be a bool. |
215 self._CheckContains(policy, 'deprecated', bool, True) | 215 self._CheckContains(policy, 'deprecated', bool, True) |
216 | 216 |
217 # If 'future' is present, it must be a bool. | 217 # If 'future' is present, it must be a bool. |
218 self._CheckContains(policy, 'future', bool, True) | 218 self._CheckContains(policy, 'future', bool, True) |
219 | 219 |
| 220 # If 'arc_support' is present, it must be a string. |
| 221 self._CheckContains(policy, 'arc_support', str, True) |
| 222 |
220 if policy_type == 'group': | 223 if policy_type == 'group': |
221 # Groups must not be nested. | 224 # Groups must not be nested. |
222 if is_in_group: | 225 if is_in_group: |
223 self._Error('Policy groups must not be nested.', 'policy', policy) | 226 self._Error('Policy groups must not be nested.', 'policy', policy) |
224 | 227 |
225 # Each policy group must have a list of policies. | 228 # Each policy group must have a list of policies. |
226 policies = self._CheckContains(policy, 'policies', list) | 229 policies = self._CheckContains(policy, 'policies', list) |
227 | 230 |
228 # Check sub-policies. | 231 # Check sub-policies. |
229 if policies is not None: | 232 if policies is not None: |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 if filename is None: | 512 if filename is None: |
510 if len(args) != 2: | 513 if len(args) != 2: |
511 parser.print_help() | 514 parser.print_help() |
512 sys.exit(1) | 515 sys.exit(1) |
513 filename = args[1] | 516 filename = args[1] |
514 return self.Main(filename, options) | 517 return self.Main(filename, options) |
515 | 518 |
516 | 519 |
517 if __name__ == '__main__': | 520 if __name__ == '__main__': |
518 sys.exit(PolicyTemplateChecker().Run(sys.argv)) | 521 sys.exit(PolicyTemplateChecker().Run(sys.argv)) |
OLD | NEW |