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 class TemplateWriter(object): | 7 class TemplateWriter(object): |
8 '''Abstract base class for writing policy templates in various formats. | 8 '''Abstract base class for writing policy templates in various formats. |
9 The methods of this class will be called by PolicyTemplateGenerator. | 9 The methods of this class will be called by PolicyTemplateGenerator. |
10 ''' | 10 ''' |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 for supported_on in policy['supported_on']: | 80 for supported_on in policy['supported_on']: |
81 for supported_on_platform in supported_on['platforms']: | 81 for supported_on_platform in supported_on['platforms']: |
82 if supported_on_platform in self.platforms: | 82 if supported_on_platform in self.platforms: |
83 return True | 83 return True |
84 return False | 84 return False |
85 | 85 |
86 def CanBeRecommended(self, policy): | 86 def CanBeRecommended(self, policy): |
87 '''Checks if the given policy can be recommended.''' | 87 '''Checks if the given policy can be recommended.''' |
88 return policy.get('features', {}).get('can_be_recommended', False) | 88 return policy.get('features', {}).get('can_be_recommended', False) |
89 | 89 |
90 def CanBeMandatory(self, policy): | |
91 '''Checks if the given policy can be mandatory.''' | |
92 return policy.get('features', {}).get('can_be_mandatory', True) | |
Joao da Silva
2014/09/05 14:55:04
The default dict for 'features' must contain 'can_
| |
93 | |
90 def IsPolicySupportedOnPlatform(self, policy, platform): | 94 def IsPolicySupportedOnPlatform(self, policy, platform): |
91 '''Checks if |policy| is supported on |platform|. | 95 '''Checks if |policy| is supported on |platform|. |
92 | 96 |
93 Args: | 97 Args: |
94 policy: The dictionary of the policy. | 98 policy: The dictionary of the policy. |
95 platform: The platform to check; one of 'win', 'mac', 'linux' or | 99 platform: The platform to check; one of 'win', 'mac', 'linux' or |
96 'chrome_os'. | 100 'chrome_os'. |
97 ''' | 101 ''' |
98 is_supported = lambda x: platform in x['platforms'] | 102 is_supported = lambda x: platform in x['platforms'] |
99 return any(filter(is_supported, policy['supported_on'])) | 103 return any(filter(is_supported, policy['supported_on'])) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 for child_policy in child_policies: | 152 for child_policy in child_policies: |
149 # Nesting of groups is currently not supported. | 153 # Nesting of groups is currently not supported. |
150 self.WritePolicy(child_policy) | 154 self.WritePolicy(child_policy) |
151 self.EndPolicyGroup() | 155 self.EndPolicyGroup() |
152 if child_recommended_policies: | 156 if child_recommended_policies: |
153 self.BeginRecommendedPolicyGroup(policy) | 157 self.BeginRecommendedPolicyGroup(policy) |
154 for child_policy in child_recommended_policies: | 158 for child_policy in child_recommended_policies: |
155 self.WriteRecommendedPolicy(child_policy) | 159 self.WriteRecommendedPolicy(child_policy) |
156 self.EndRecommendedPolicyGroup() | 160 self.EndRecommendedPolicyGroup() |
157 elif self.IsPolicySupported(policy): | 161 elif self.IsPolicySupported(policy): |
158 self.WritePolicy(policy) | 162 if self.CanBeMandatory(policy): |
163 self.WritePolicy(policy) | |
159 if self.CanBeRecommended(policy): | 164 if self.CanBeRecommended(policy): |
160 self.WriteRecommendedPolicy(policy) | 165 self.WriteRecommendedPolicy(policy) |
161 self.EndTemplate() | 166 self.EndTemplate() |
162 | 167 |
163 return self.GetTemplateText() | 168 return self.GetTemplateText() |
164 | 169 |
165 def PreprocessPolicies(self, policy_list): | 170 def PreprocessPolicies(self, policy_list): |
166 '''Preprocesses a list of policies according to a given writer's needs. | 171 '''Preprocesses a list of policies according to a given writer's needs. |
167 Preprocessing steps include sorting policies and stripping unneeded | 172 Preprocessing steps include sorting policies and stripping unneeded |
168 information such as groups (for writers that ignore them). | 173 information such as groups (for writers that ignore them). |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 ''' | 294 ''' |
290 is_group = policy['type'] == 'group' | 295 is_group = policy['type'] == 'group' |
291 if is_group: | 296 if is_group: |
292 # Groups are sorted by caption. | 297 # Groups are sorted by caption. |
293 str_key = policy['caption'] | 298 str_key = policy['caption'] |
294 else: | 299 else: |
295 # Regular policies are sorted by name. | 300 # Regular policies are sorted by name. |
296 str_key = policy['name'] | 301 str_key = policy['name'] |
297 # Groups come before regular policies. | 302 # Groups come before regular policies. |
298 return (not is_group, str_key) | 303 return (not is_group, str_key) |
OLD | NEW |