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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 '''Checks if |policy| is supported on |platform|. | 95 '''Checks if |policy| is supported on |platform|. |
96 | 96 |
97 Args: | 97 Args: |
98 policy: The dictionary of the policy. | 98 policy: The dictionary of the policy. |
99 platform: The platform to check; one of 'win', 'mac', 'linux' or | 99 platform: The platform to check; one of 'win', 'mac', 'linux' or |
100 'chrome_os'. | 100 'chrome_os'. |
101 ''' | 101 ''' |
102 is_supported = lambda x: platform in x['platforms'] | 102 is_supported = lambda x: platform in x['platforms'] |
103 return any(filter(is_supported, policy['supported_on'])) | 103 return any(filter(is_supported, policy['supported_on'])) |
104 | 104 |
105 def _GetChromiumVersionString(self): | |
106 '''Returns the Chromium version string stored in the environment variable | |
107 version (if it is set). | |
108 | |
109 Returns: The Chromium version string or an empty string if it has not | |
Joao da Silva
2014/10/14 19:05:21
or None if it has not been set
cschuet (SLOW)
2014/10/14 21:04:54
Done.
| |
110 been set.''' | |
111 | |
112 if 'version' in self.config: | |
113 return self.config['version'] | |
114 | |
105 def _GetPoliciesForWriter(self, group): | 115 def _GetPoliciesForWriter(self, group): |
106 '''Filters the list of policies in the passed group that are supported by | 116 '''Filters the list of policies in the passed group that are supported by |
107 the writer. | 117 the writer. |
108 | 118 |
109 Args: | 119 Args: |
110 group: The dictionary of the policy group. | 120 group: The dictionary of the policy group. |
111 | 121 |
112 Returns: The list of policies of the policy group that are compatible | 122 Returns: The list of policies of the policy group that are compatible |
113 with the writer. | 123 with the writer. |
114 ''' | 124 ''' |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 | 194 |
185 def WritePolicy(self, policy): | 195 def WritePolicy(self, policy): |
186 '''Appends the template text corresponding to a policy into the | 196 '''Appends the template text corresponding to a policy into the |
187 internal buffer. | 197 internal buffer. |
188 | 198 |
189 Args: | 199 Args: |
190 policy: The policy as it is found in the JSON file. | 200 policy: The policy as it is found in the JSON file. |
191 ''' | 201 ''' |
192 raise NotImplementedError() | 202 raise NotImplementedError() |
193 | 203 |
204 def WriteComment(self, comment): | |
205 '''Appends the comment to the internal buffer. | |
206 | |
207 comment: The comment to be added. | |
208 ''' | |
209 raise NotImplementedError() | |
210 | |
194 def WriteRecommendedPolicy(self, policy): | 211 def WriteRecommendedPolicy(self, policy): |
195 '''Appends the template text corresponding to a recommended policy into the | 212 '''Appends the template text corresponding to a recommended policy into the |
196 internal buffer. | 213 internal buffer. |
197 | 214 |
198 Args: | 215 Args: |
199 policy: The recommended policy as it is found in the JSON file. | 216 policy: The recommended policy as it is found in the JSON file. |
200 ''' | 217 ''' |
201 # TODO | 218 # TODO |
202 #raise NotImplementedError() | 219 #raise NotImplementedError() |
203 pass | 220 pass |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 ''' | 310 ''' |
294 is_group = policy['type'] == 'group' | 311 is_group = policy['type'] == 'group' |
295 if is_group: | 312 if is_group: |
296 # Groups are sorted by caption. | 313 # Groups are sorted by caption. |
297 str_key = policy['caption'] | 314 str_key = policy['caption'] |
298 else: | 315 else: |
299 # Regular policies are sorted by name. | 316 # Regular policies are sorted by name. |
300 str_key = policy['name'] | 317 str_key = policy['name'] |
301 # Groups come before regular policies. | 318 # Groups come before regular policies. |
302 return (not is_group, str_key) | 319 return (not is_group, str_key) |
OLD | NEW |