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

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

Issue 6409040: New policy protobuf protocol. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address feedback; fix gyp files Created 9 years, 11 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
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..d13034aed4f71b897c8a89000f795a94df28ce90 100644
--- a/chrome/app/policy/syntax_check_policy_template_json.py
+++ b/chrome/app/policy/syntax_check_policy_template_json.py
@@ -81,7 +81,31 @@ 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, group=None):
+ '''
+ Checks a set of policy_ids to make sure it contains a continuous range
+ of entries (i.e. no holes).
Mattias Nissler (ping if slow) 2011/02/03 16:23:41 can you elaborate here please on why we don't want
Jakob Kummerow 2011/02/08 16:15:43 Done.
+ '''
+ for i in range(len(policy_ids)):
+ if (i + 1) not in policy_ids:
+ if group is not None:
+ self._Error('Missing id: %s' % (i + 1), 'policy group',
+ group.get('name'))
+ else:
+ 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 +114,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))
@@ -115,6 +139,10 @@ class PolicyTemplateChecker(object):
# If 'label' is present, it must be a string.
self._CheckContains(policy, 'label', str, True)
+ # Each policy must have a protobuf ID.
+ id = self._CheckContains(policy, 'id', int)
+ self._AddPolicyID(id, policy_ids, policy)
+
# If 'deprecated' is present, it must be a bool.
self._CheckContains(policy, 'deprecated', bool, True)
@@ -124,14 +152,18 @@ 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.
+ group_policy_ids = set()
if policies is not None:
for nested_policy in policies:
- self._CheckPolicy(nested_policy, False)
+ self._CheckPolicy(nested_policy, True, group_policy_ids)
+ self._CheckPolicyIDs(group_policy_ids, policy)
# Statistics.
self.num_groups += 1
@@ -143,7 +175,7 @@ class PolicyTemplateChecker(object):
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 +195,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 +368,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 +395,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 '

Powered by Google App Engine
This is Rietveld 408576698