| OLD | NEW |
| 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 | 5 |
| 6 import itertools | 6 import itertools |
| 7 | 7 |
| 8 | 8 |
| 9 class TemplateWriter(object): | 9 class TemplateWriter(object): |
| 10 '''Abstract base class for writing policy templates in various formats. | 10 '''Abstract base class for writing policy templates in various formats. |
| 11 The methods of this class will be called by PolicyTemplateGenerator. | 11 The methods of this class will be called by PolicyTemplateGenerator. |
| 12 ''' | 12 ''' |
| 13 | 13 |
| 14 def __init__(self, platforms, config, messages): | 14 def __init__(self, platforms, config): |
| 15 '''Initializes a TemplateWriter object. | 15 '''Initializes a TemplateWriter object. |
| 16 | 16 |
| 17 Args: | 17 Args: |
| 18 platforms: List of platforms for which this writer can write policies. | 18 platforms: List of platforms for which this writer can write policies. |
| 19 config: A dictionary of information required to generate the template. | 19 config: A dictionary of information required to generate the template. |
| 20 It contains some key-value pairs, including the following examples: | 20 It contains some key-value pairs, including the following examples: |
| 21 'build': 'chrome' or 'chromium' | 21 'build': 'chrome' or 'chromium' |
| 22 'branding': 'Google Chrome' or 'Chromium' | 22 'branding': 'Google Chrome' or 'Chromium' |
| 23 'mac_bundle_id': The Mac bundle id of Chrome. (Only set when building | 23 'mac_bundle_id': The Mac bundle id of Chrome. (Only set when building |
| 24 for Mac.) | 24 for Mac.) |
| 25 messages: List of all the message strings from the grd file. Most of them | 25 messages: List of all the message strings from the grd file. Most of them |
| 26 are also present in the policy data structures that are passed to | 26 are also present in the policy data structures that are passed to |
| 27 methods. That is the preferred way of accessing them, this should only | 27 methods. That is the preferred way of accessing them, this should only |
| 28 be used in exceptional cases. An example for its use is the | 28 be used in exceptional cases. An example for its use is the |
| 29 IDS_POLICY_WIN_SUPPORTED_WINXPSP2 message in ADM files, because that | 29 IDS_POLICY_WIN_SUPPORTED_WINXPSP2 message in ADM files, because that |
| 30 cannot be associated with any policy or group. | 30 cannot be associated with any policy or group. |
| 31 ''' | 31 ''' |
| 32 self.platforms = platforms | 32 self.platforms = platforms |
| 33 self.config = config | 33 self.config = config |
| 34 self.messages = messages | |
| 35 | 34 |
| 36 def IsDeprecatedPolicySupported(self, policy): | 35 def IsDeprecatedPolicySupported(self, policy): |
| 37 '''Checks if the given deprecated policy is supported by the writer. | 36 '''Checks if the given deprecated policy is supported by the writer. |
| 38 | 37 |
| 39 Args: | 38 Args: |
| 40 policy: The dictionary of the policy. | 39 policy: The dictionary of the policy. |
| 41 | 40 |
| 42 Returns: | 41 Returns: |
| 43 True if the writer chooses to include the deprecated 'policy' in its | 42 True if the writer chooses to include the deprecated 'policy' in its |
| 44 output. | 43 output. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 96 |
| 98 def WriteTemplate(self, template): | 97 def WriteTemplate(self, template): |
| 99 '''Writes the given template definition. | 98 '''Writes the given template definition. |
| 100 | 99 |
| 101 Args: | 100 Args: |
| 102 template: Template definition to write. | 101 template: Template definition to write. |
| 103 | 102 |
| 104 Returns: | 103 Returns: |
| 105 Generated output for the passed template definition. | 104 Generated output for the passed template definition. |
| 106 ''' | 105 ''' |
| 106 self.messages = template['messages'] |
| 107 self.Init() | 107 self.Init() |
| 108 template = self.PreprocessPolicies(template) | 108 template['policy_definitions'] = \ |
| 109 self.PreprocessPolicies(template['policy_definitions']) |
| 109 self.BeginTemplate() | 110 self.BeginTemplate() |
| 110 for policy in template: | 111 for policy in template['policy_definitions']: |
| 111 if policy['type'] == 'group': | 112 if policy['type'] == 'group': |
| 112 child_policies = self._GetPoliciesForWriter(policy) | 113 child_policies = self._GetPoliciesForWriter(policy) |
| 113 if child_policies: | 114 if child_policies: |
| 114 # Only write nonempty groups. | 115 # Only write nonempty groups. |
| 115 self.BeginPolicyGroup(policy) | 116 self.BeginPolicyGroup(policy) |
| 116 for child_policy in child_policies: | 117 for child_policy in child_policies: |
| 117 # Nesting of groups is currently not supported. | 118 # Nesting of groups is currently not supported. |
| 118 self.WritePolicy(child_policy) | 119 self.WritePolicy(child_policy) |
| 119 self.EndPolicyGroup() | 120 self.EndPolicyGroup() |
| 120 elif self.IsPolicySupported(policy): | 121 elif self.IsPolicySupported(policy): |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 # Groups are sorted by caption. | 227 # Groups are sorted by caption. |
| 227 str_key = policy['caption'] | 228 str_key = policy['caption'] |
| 228 else: | 229 else: |
| 229 # Regular policies are sorted by name. | 230 # Regular policies are sorted by name. |
| 230 str_key = policy['name'] | 231 str_key = policy['name'] |
| 231 # Groups come before regular policies. | 232 # Groups come before regular policies. |
| 232 return (not is_group, str_key) | 233 return (not is_group, str_key) |
| 233 | 234 |
| 234 | 235 |
| 235 | 236 |
| OLD | NEW |