OLD | NEW |
1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2010 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 IsPolicySupported(self, policy): | 35 def IsPolicySupported(self, policy): |
37 '''Checks if the given policy is supported by the writer. | 36 '''Checks if the given policy is supported by the writer. |
38 In other words, the set of platforms supported by the writer | 37 In other words, the set of platforms supported by the writer |
39 has a common subset with the set of platforms that support | 38 has a common subset with the set of platforms that support |
40 the policy. | 39 the policy. |
41 | 40 |
42 Args: | 41 Args: |
43 policy: The dictionary of the policy. | 42 policy: The dictionary of the policy. |
44 | 43 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 80 |
82 def WriteTemplate(self, template): | 81 def WriteTemplate(self, template): |
83 '''Writes the given template definition. | 82 '''Writes the given template definition. |
84 | 83 |
85 Args: | 84 Args: |
86 template: Template definition to write. | 85 template: Template definition to write. |
87 | 86 |
88 Returns: | 87 Returns: |
89 Generated output for the passed template definition. | 88 Generated output for the passed template definition. |
90 ''' | 89 ''' |
| 90 self.messages = template['messages'] |
91 self.Init() | 91 self.Init() |
92 self.BeginTemplate() | 92 self.BeginTemplate() |
93 for policy in template: | 93 for policy in template['policy_definitions']: |
94 if policy['type'] == 'group': | 94 if policy['type'] == 'group': |
95 child_policies = self._GetPoliciesForWriter(policy) | 95 child_policies = self._GetPoliciesForWriter(policy) |
96 if child_policies: | 96 if child_policies: |
97 # Only write nonempty groups. | 97 # Only write nonempty groups. |
98 self.BeginPolicyGroup(policy) | 98 self.BeginPolicyGroup(policy) |
99 for child_policy in child_policies: | 99 for child_policy in child_policies: |
100 # Nesting of groups is currently not supported. | 100 # Nesting of groups is currently not supported. |
101 self.WritePolicy(child_policy) | 101 self.WritePolicy(child_policy) |
102 self.EndPolicyGroup() | 102 self.EndPolicyGroup() |
103 elif self.IsPolicySupported(policy): | 103 elif self.IsPolicySupported(policy): |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 ''' | 141 ''' |
142 pass | 142 pass |
143 | 143 |
144 def GetTemplateText(self): | 144 def GetTemplateText(self): |
145 '''Gets the content of the internal template buffer. | 145 '''Gets the content of the internal template buffer. |
146 | 146 |
147 Returns: | 147 Returns: |
148 The generated template from the the internal buffer as a string. | 148 The generated template from the the internal buffer as a string. |
149 ''' | 149 ''' |
150 raise NotImplementedError() | 150 raise NotImplementedError() |
OLD | NEW |