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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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): | 90 def CanBeMandatory(self, policy): |
91 '''Checks if the given policy can be mandatory.''' | 91 '''Checks if the given policy can be mandatory.''' |
92 return policy.get('features', {}).get('can_be_mandatory', True) | 92 return policy.get('features', {}).get('can_be_mandatory', True) |
93 | 93 |
94 def IsPolicySupportedOnPlatform(self, policy, platform): | 94 def IsPolicySupportedOnPlatform(self, policy, platform, product=None): |
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 |
Nico
2015/11/02 16:41:10
This returns a bool…
| |
103 def is_supported(supported_on): | |
104 if not platform in supported_on['platforms']: | |
Nico
2015/11/02 16:41:10
nit: `platform not in` instead of `not platform in
dgn
2015/11/02 18:19:50
Acknowledged.
| |
105 return None | |
106 if product and not product in supported_on['product']: | |
Nico
2015/11/02 16:41:10
same nit
dgn
2015/11/02 18:19:50
Acknowledged.
| |
107 return None | |
108 return supported_on | |
Nico
2015/11/02 16:41:10
…but this returns an object. Since it's used with
dgn
2015/11/02 18:19:50
Done.
| |
109 | |
103 return any(filter(is_supported, policy['supported_on'])) | 110 return any(filter(is_supported, policy['supported_on'])) |
104 | 111 |
105 def _GetChromiumVersionString(self): | 112 def _GetChromiumVersionString(self): |
106 '''Returns the Chromium version string stored in the environment variable | 113 '''Returns the Chromium version string stored in the environment variable |
107 version (if it is set). | 114 version (if it is set). |
108 | 115 |
109 Returns: The Chromium version string or None if it has not been set.''' | 116 Returns: The Chromium version string or None if it has not been set.''' |
110 | 117 |
111 if 'version' in self.config: | 118 if 'version' in self.config: |
112 return self.config['version'] | 119 return self.config['version'] |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 ''' | 316 ''' |
310 is_group = policy['type'] == 'group' | 317 is_group = policy['type'] == 'group' |
311 if is_group: | 318 if is_group: |
312 # Groups are sorted by caption. | 319 # Groups are sorted by caption. |
313 str_key = policy['caption'] | 320 str_key = policy['caption'] |
314 else: | 321 else: |
315 # Regular policies are sorted by name. | 322 # Regular policies are sorted by name. |
316 str_key = policy['name'] | 323 str_key = policy['name'] |
317 # Groups come before regular policies. | 324 # Groups come before regular policies. |
318 return (not is_group, str_key) | 325 return (not is_group, str_key) |
OLD | NEW |