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 import os | |
Joao da Silva
2014/10/13 10:30:58
This isn't used
cschuet (SLOW)
2014/10/14 18:55:20
Done.
| |
6 | 7 |
7 class TemplateWriter(object): | 8 class TemplateWriter(object): |
8 '''Abstract base class for writing policy templates in various formats. | 9 '''Abstract base class for writing policy templates in various formats. |
9 The methods of this class will be called by PolicyTemplateGenerator. | 10 The methods of this class will be called by PolicyTemplateGenerator. |
10 ''' | 11 ''' |
11 | 12 |
12 def __init__(self, platforms, config): | 13 def __init__(self, platforms, config): |
13 '''Initializes a TemplateWriter object. | 14 '''Initializes a TemplateWriter object. |
14 | 15 |
15 Args: | 16 Args: |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 '''Checks if |policy| is supported on |platform|. | 96 '''Checks if |policy| is supported on |platform|. |
96 | 97 |
97 Args: | 98 Args: |
98 policy: The dictionary of the policy. | 99 policy: The dictionary of the policy. |
99 platform: The platform to check; one of 'win', 'mac', 'linux' or | 100 platform: The platform to check; one of 'win', 'mac', 'linux' or |
100 'chrome_os'. | 101 'chrome_os'. |
101 ''' | 102 ''' |
102 is_supported = lambda x: platform in x['platforms'] | 103 is_supported = lambda x: platform in x['platforms'] |
103 return any(filter(is_supported, policy['supported_on'])) | 104 return any(filter(is_supported, policy['supported_on'])) |
104 | 105 |
106 def _GetChromiumVersionString(self): | |
107 '''Returns the Chromium version string stored in the environment variable | |
108 version (if it is set). | |
109 | |
110 Returns: The Chromium version string or an empty string if it has not | |
Joao da Silva
2014/10/13 10:30:58
Note that python functions return None by default,
cschuet (SLOW)
2014/10/14 18:55:20
This was the way I originally implemented this. Bu
| |
111 been set.''' | |
112 | |
113 if 'version' in self.config: | |
114 return self.config['version'] | |
115 | |
105 def _GetPoliciesForWriter(self, group): | 116 def _GetPoliciesForWriter(self, group): |
106 '''Filters the list of policies in the passed group that are supported by | 117 '''Filters the list of policies in the passed group that are supported by |
107 the writer. | 118 the writer. |
108 | 119 |
109 Args: | 120 Args: |
110 group: The dictionary of the policy group. | 121 group: The dictionary of the policy group. |
111 | 122 |
112 Returns: The list of policies of the policy group that are compatible | 123 Returns: The list of policies of the policy group that are compatible |
113 with the writer. | 124 with the writer. |
114 ''' | 125 ''' |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 | 195 |
185 def WritePolicy(self, policy): | 196 def WritePolicy(self, policy): |
186 '''Appends the template text corresponding to a policy into the | 197 '''Appends the template text corresponding to a policy into the |
187 internal buffer. | 198 internal buffer. |
188 | 199 |
189 Args: | 200 Args: |
190 policy: The policy as it is found in the JSON file. | 201 policy: The policy as it is found in the JSON file. |
191 ''' | 202 ''' |
192 raise NotImplementedError() | 203 raise NotImplementedError() |
193 | 204 |
205 def WriteComment(self, comment): | |
206 '''Appends the comment to the internal buffer. | |
Joao da Silva
2014/10/13 10:30:58
Remove trailing whitespaces from this line.
cschuet (SLOW)
2014/10/14 18:55:20
Done.
| |
207 | |
208 comment: The comment to be added. | |
Joao da Silva
2014/10/13 10:30:58
From this one too
cschuet (SLOW)
2014/10/14 18:55:20
Done.
| |
209 ''' | |
210 raise NotImplementedError() | |
211 | |
194 def WriteRecommendedPolicy(self, policy): | 212 def WriteRecommendedPolicy(self, policy): |
195 '''Appends the template text corresponding to a recommended policy into the | 213 '''Appends the template text corresponding to a recommended policy into the |
196 internal buffer. | 214 internal buffer. |
197 | 215 |
198 Args: | 216 Args: |
199 policy: The recommended policy as it is found in the JSON file. | 217 policy: The recommended policy as it is found in the JSON file. |
200 ''' | 218 ''' |
201 # TODO | 219 # TODO |
202 #raise NotImplementedError() | 220 #raise NotImplementedError() |
203 pass | 221 pass |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 ''' | 311 ''' |
294 is_group = policy['type'] == 'group' | 312 is_group = policy['type'] == 'group' |
295 if is_group: | 313 if is_group: |
296 # Groups are sorted by caption. | 314 # Groups are sorted by caption. |
297 str_key = policy['caption'] | 315 str_key = policy['caption'] |
298 else: | 316 else: |
299 # Regular policies are sorted by name. | 317 # Regular policies are sorted by name. |
300 str_key = policy['name'] | 318 str_key = policy['name'] |
301 # Groups come before regular policies. | 319 # Groups come before regular policies. |
302 return (not is_group, str_key) | 320 return (not is_group, str_key) |
OLD | NEW |