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

Unified Diff: chrome/app/policy/syntax_check_policy_template_json.py

Issue 6523058: New policy protobuf protocol. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/app/policy/policy_templates.json ('k') | chrome/browser/policy/asynchronous_policy_provider.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/app/policy/syntax_check_policy_template_json.py
diff --git a/chrome/app/policy/syntax_check_policy_template_json.py b/chrome/app/policy/syntax_check_policy_template_json.py
index d33225437dd336306fe79f7e5f1d648717c65979..3cc36cb4a47d4102c71b24f95cf140372e7eb0fa 100644
--- a/chrome/app/policy/syntax_check_policy_template_json.py
+++ b/chrome/app/policy/syntax_check_policy_template_json.py
@@ -81,7 +81,29 @@ class PolicyTemplateChecker(object):
container_name, identifier, value)
return value
- def _CheckPolicy(self, policy, may_contain_groups):
+ def _AddPolicyID(self, id, policy_ids, policy):
+ '''
+ Adds |id| to |policy_ids|. Generates an error message if the
+ |id| exists already; |policy| is needed for this message.
+ '''
+ if id in policy_ids:
+ self._Error('Duplicate id', 'policy', policy.get('name'),
+ id)
+ else:
+ policy_ids.add(id)
+
+ def _CheckPolicyIDs(self, policy_ids):
+ '''
+ Checks a set of policy_ids to make sure it contains a continuous range
+ of entries (i.e. no holes).
+ Holes would not be a technical problem, but we want to ensure that nobody
+ accidentally omits IDs.
+ '''
+ for i in range(len(policy_ids)):
+ if (i + 1) not in policy_ids:
+ self._Error('No policy with id: %s' % (i + 1))
+
+ def _CheckPolicy(self, policy, is_in_group, policy_ids):
if not isinstance(policy, dict):
self._Error('Each policy must be a dictionary.', 'policy', None, policy)
return
@@ -90,7 +112,7 @@ class PolicyTemplateChecker(object):
for key in policy:
if key not in ('name', 'type', 'caption', 'desc', 'supported_on',
'label', 'policies', 'items', 'example_value', 'features',
- 'deprecated', 'future'):
+ 'deprecated', 'future', 'id'):
self.warning_count += 1
print ('In policy %s: Warning: Unknown key: %s' %
(policy.get('name'), key))
@@ -124,26 +146,37 @@ class PolicyTemplateChecker(object):
if policy_type == 'group':
# Groups must not be nested.
- if not may_contain_groups:
+ if is_in_group:
self._Error('Policy groups must not be nested.', 'policy', policy)
# Each policy group must have a list of policies.
policies = self._CheckContains(policy, 'policies', list)
+
+ # Check sub-policies.
if policies is not None:
for nested_policy in policies:
- self._CheckPolicy(nested_policy, False)
+ self._CheckPolicy(nested_policy, True, policy_ids)
+
+ # Groups must not have an |id|.
+ if 'id' in policy:
+ self._Error('Policies of type "group" must not have an "id" field.',
+ 'policy', policy)
# Statistics.
self.num_groups += 1
else: # policy_type != group
+ # Each policy must have a protobuf ID.
+ id = self._CheckContains(policy, 'id', int)
+ self._AddPolicyID(id, policy_ids, policy)
+
# Each policy must have a supported_on list.
supported_on = self._CheckContains(policy, 'supported_on', list)
if supported_on is not None:
for s in supported_on:
if not isinstance(s, str):
self._Error('Entries in "supported_on" must be strings.', 'policy',
- policy, supported_on)
+ policy, supported_on)
# Each policy must have a 'features' dict.
self._CheckContains(policy, 'features', dict)
@@ -163,7 +196,7 @@ class PolicyTemplateChecker(object):
# Statistics.
self.num_policies += 1
- if not may_contain_groups:
+ if is_in_group:
self.num_policies_in_groups += 1
if policy_type in ('int-enum', 'string-enum'):
@@ -336,8 +369,10 @@ class PolicyTemplateChecker(object):
container_name='The root element',
offending=None)
if policy_definitions is not None:
+ policy_ids = set()
for policy in policy_definitions:
- self._CheckPolicy(policy, True)
+ self._CheckPolicy(policy, False, policy_ids)
+ self._CheckPolicyIDs(policy_ids)
# Check (non-policy-specific) message definitions.
messages = self._CheckContains(data, 'messages', dict,
@@ -361,8 +396,8 @@ class PolicyTemplateChecker(object):
self._CheckFormat(filename)
# Third part: summary and exit.
- print ('Finished. %d errors, %d warnings.' %
- (self.error_count, self.warning_count))
+ print ('Finished checking %s. %d errors, %d warnings.' %
+ (filename, self.error_count, self.warning_count))
if self.options.stats:
if self.num_groups > 0:
print ('%d policies, %d of those in %d groups (containing on '
« no previous file with comments | « chrome/app/policy/policy_templates.json ('k') | chrome/browser/policy/asynchronous_policy_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698