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 from grit.format.policy_templates.writers import template_writer | 6 from grit.format.policy_templates.writers import template_writer |
7 | 7 |
8 | 8 |
9 def GetWriter(config): | 9 def GetWriter(config): |
10 '''Factory method for creating AdmWriter objects. | 10 '''Factory method for creating AdmWriter objects. |
(...skipping 13 matching lines...) Expand all Loading... | |
24 'int': 'NUMERIC', | 24 'int': 'NUMERIC', |
25 'string-enum': 'DROPDOWNLIST', | 25 'string-enum': 'DROPDOWNLIST', |
26 'int-enum': 'DROPDOWNLIST', | 26 'int-enum': 'DROPDOWNLIST', |
27 'list': 'LISTBOX'} | 27 'list': 'LISTBOX'} |
28 NEWLINE = '\r\n' | 28 NEWLINE = '\r\n' |
29 | 29 |
30 def _AddGuiString(self, name, value): | 30 def _AddGuiString(self, name, value): |
31 # Escape newlines in the value. | 31 # Escape newlines in the value. |
32 value = value.replace('\n', '\\n') | 32 value = value.replace('\n', '\\n') |
33 line = '%s="%s"' % (name, value) | 33 line = '%s="%s"' % (name, value) |
34 self.str_list.append(line) | 34 self.strings.append(line) |
35 | 35 |
36 def _PrintLine(self, string='', indent_diff=0): | 36 def _PrintLine(self, string='', indent_diff=0): |
37 '''Prints a string with indents and a linebreak to the output. | 37 '''Prints a string with indents and a linebreak to the output. |
Jakob Kummerow
2011/01/24 16:52:28
More accurate would be: "Appends a string with ind
| |
38 | 38 |
39 Args: | 39 Args: |
40 string: The string to print. | 40 string: The string to print. |
41 indent_diff: the difference of indentation of the printed line, | 41 indent_diff: the difference of indentation of the printed line, |
42 compared to the next/previous printed line. Increment occurs | 42 compared to the next/previous printed line. Increment occurs |
43 after printing the line, while decrement occurs before that. | 43 after printing the line, while decrement occurs before that. |
44 ''' | 44 ''' |
45 indent_diff *= 2 | 45 indent_diff *= 2 |
46 if indent_diff < 0: | 46 if indent_diff < 0: |
47 self.indent = self.indent[(-indent_diff):] | 47 self.indent = self.indent[(-indent_diff):] |
48 if string != '': | 48 if string != '': |
49 self.policy_list.append(self.indent + string) | 49 self.lines.append(self.indent + string) |
50 else: | 50 else: |
51 self.policy_list.append('') | 51 self.lines.append('') |
52 if indent_diff > 0: | 52 if indent_diff > 0: |
53 self.indent += ''.ljust(indent_diff) | 53 self.indent += ''.ljust(indent_diff) |
54 | 54 |
55 def _WriteSupported(self): | 55 def _WriteSupported(self): |
56 self._PrintLine('#if version >= 4', 1) | 56 self._PrintLine('#if version >= 4', 1) |
57 self._PrintLine('SUPPORTED !!SUPPORTED_WINXPSP2') | 57 self._PrintLine('SUPPORTED !!SUPPORTED_WINXPSP2') |
58 self._PrintLine('#endif', -1) | 58 self._PrintLine('#endif', -1) |
59 | 59 |
60 def _WritePart(self, policy): | 60 def _WritePart(self, policy): |
61 '''Writes the PART ... END PART section of a policy. | 61 '''Writes the PART ... END PART section of a policy. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 # Open a category for the policies if there is more than one in the | 114 # Open a category for the policies if there is more than one in the |
115 # group. | 115 # group. |
116 if self._open_category: | 116 if self._open_category: |
117 category_name = group['name'] + '_Category' | 117 category_name = group['name'] + '_Category' |
118 self._AddGuiString(category_name, group['caption']) | 118 self._AddGuiString(category_name, group['caption']) |
119 self._PrintLine('CATEGORY !!' + category_name, 1) | 119 self._PrintLine('CATEGORY !!' + category_name, 1) |
120 | 120 |
121 def EndPolicyGroup(self): | 121 def EndPolicyGroup(self): |
122 if self._open_category: | 122 if self._open_category: |
123 self._PrintLine('END CATEGORY', -1) | 123 self._PrintLine('END CATEGORY', -1) |
124 self._PrintLine('') | |
124 | 125 |
125 def BeginTemplate(self): | 126 def _WriteTemplateForClass(self, policy_class, policies): |
127 '''Writes the whole ADM template except for the [strings] section. | |
128 The output is self.lines. | |
129 | |
130 Args: | |
131 policy_class: USER or MACHINE | |
132 policies: ADM code for all the policies in the form of list of | |
133 strings. | |
134 ''' | |
126 category_path = self.config['win_category_path'] | 135 category_path = self.config['win_category_path'] |
127 self._AddGuiString(self.config['win_supported_os'], | 136 |
128 self.messages['win_supported_winxpsp2']['text']) | 137 self._PrintLine('CLASS ' + policy_class, 1) |
129 self._PrintLine( | |
130 'CLASS ' + self.config['win_group_policy_class'].upper(), | |
131 1) | |
132 if self.config['build'] == 'chrome': | 138 if self.config['build'] == 'chrome': |
133 self._AddGuiString(category_path[0], 'Google') | |
134 self._AddGuiString(category_path[1], self.config['app_name']) | |
135 self._PrintLine('CATEGORY !!' + category_path[0], 1) | 139 self._PrintLine('CATEGORY !!' + category_path[0], 1) |
136 self._PrintLine('CATEGORY !!' + category_path[1], 1) | 140 self._PrintLine('CATEGORY !!' + category_path[1], 1) |
137 elif self.config['build'] == 'chromium': | 141 elif self.config['build'] == 'chromium': |
138 self._AddGuiString(category_path[0], self.config['app_name']) | |
139 self._PrintLine('CATEGORY !!' + category_path[0], 1) | 142 self._PrintLine('CATEGORY !!' + category_path[0], 1) |
140 self._PrintLine('KEYNAME "%s"' % self.config['win_reg_key_name']) | 143 self._PrintLine('KEYNAME "%s"' % self.config['win_reg_key_name']) |
141 self._PrintLine() | 144 self._PrintLine() |
142 | 145 |
143 def EndTemplate(self): | 146 self.lines += policies |
147 | |
144 if self.config['build'] == 'chrome': | 148 if self.config['build'] == 'chrome': |
145 self._PrintLine('END CATEGORY', -1) | 149 self._PrintLine('END CATEGORY', -1) |
146 self._PrintLine('END CATEGORY', -1) | 150 self._PrintLine('END CATEGORY', -1) |
147 self._PrintLine('', -1) | 151 self._PrintLine('', -1) |
148 elif self.config['build'] == 'chromium': | 152 elif self.config['build'] == 'chromium': |
149 self._PrintLine('END CATEGORY', -1) | 153 self._PrintLine('END CATEGORY', -1) |
150 self._PrintLine('', -1) | 154 self._PrintLine('', -1) |
151 | 155 |
156 def BeginTemplate(self): | |
157 category_path = self.config['win_category_path'] | |
158 self._AddGuiString(self.config['win_supported_os'], | |
159 self.messages['win_supported_winxpsp2']['text']) | |
160 if self.config['build'] == 'chrome': | |
161 self._AddGuiString(category_path[0], 'Google') | |
162 self._AddGuiString(category_path[1], self.config['app_name']) | |
163 self.indent = ' ' | |
164 elif self.config['build'] == 'chromium': | |
165 self._AddGuiString(category_path[0], self.config['app_name']) | |
166 self.indent = ' ' | |
167 # After this, all the policies will be written into self.lines. The header | |
168 # and footer of the template will be added in self.EndTemplates(). | |
Jakob Kummerow
2011/01/24 16:52:28
nit: self.EndTemplate()
gfeher
2011/01/25 10:42:21
Done.
| |
169 | |
170 def EndTemplate(self): | |
171 # Save the list of policies. | |
172 policies = self.lines | |
173 self.lines = [] | |
174 self.indent = '' | |
175 policy_class = self.config['win_group_policy_class'].upper() | |
176 if policy_class in ('BOTH', 'MACHINE'): | |
177 self._WriteTemplateForClass('MACHINE', policies) | |
178 if policy_class in ('BOTH', 'USER'): | |
179 self._WriteTemplateForClass('USER', policies) | |
180 | |
152 def Init(self): | 181 def Init(self): |
153 self.policy_list = [] | 182 self.lines = [] |
154 self.str_list = ['[Strings]'] | 183 self.strings = ['[Strings]'] |
155 self.indent = '' | 184 self.indent = '' |
156 | 185 |
157 def GetTemplateText(self): | 186 def GetTemplateText(self): |
158 lines = self.policy_list + self.str_list | 187 lines = self.lines + self.strings |
159 return self.NEWLINE.join(lines) | 188 return self.NEWLINE.join(lines) |
OLD | NEW |