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 from xml.dom import minidom | 7 from xml.dom import minidom |
8 from grit import lazy_re | 8 from grit import lazy_re |
9 from grit.format.policy_templates.writers import xml_formatted_writer | 9 from grit.format.policy_templates.writers import xml_formatted_writer |
10 | 10 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 Args: | 172 Args: |
173 parent: The DOM node for which the example will be added. | 173 parent: The DOM node for which the example will be added. |
174 policy: A policy of type 'list', for which the Windows example value | 174 policy: A policy of type 'list', for which the Windows example value |
175 is generated. | 175 is generated. |
176 ''' | 176 ''' |
177 example_value = policy['example_value'] | 177 example_value = policy['example_value'] |
178 self.AddElement(parent, 'dt', {}, 'Windows:') | 178 self.AddElement(parent, 'dt', {}, 'Windows:') |
179 win = self._AddStyledElement(parent, 'dd', ['.monospace', '.pre']) | 179 win = self._AddStyledElement(parent, 'dd', ['.monospace', '.pre']) |
180 win_text = [] | 180 win_text = [] |
181 cnt = 1 | 181 cnt = 1 |
182 key_name = self.config['win_reg_mandatory_key_name'] | 182 if self.CanBeRecommended(policy) and not self.CanBeMandatory(policy): |
| 183 key_name = self.config['win_reg_recommended_key_name'] |
| 184 else: |
| 185 key_name = self.config['win_reg_mandatory_key_name'] |
183 for item in example_value: | 186 for item in example_value: |
184 win_text.append( | 187 win_text.append( |
185 '%s\\%s\\%d = "%s"' % | 188 '%s\\%s\\%d = "%s"' % |
186 (key_name, policy['name'], cnt, item)) | 189 (key_name, policy['name'], cnt, item)) |
187 cnt = cnt + 1 | 190 cnt = cnt + 1 |
188 self.AddText(win, '\n'.join(win_text)) | 191 self.AddText(win, '\n'.join(win_text)) |
189 | 192 |
190 def _AddListExampleLinux(self, parent, policy): | 193 def _AddListExampleLinux(self, parent, policy): |
191 '''Adds an example value for Linux of a 'list' policy to a DOM node. | 194 '''Adds an example value for Linux of a 'list' policy to a DOM node. |
192 | 195 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 def _AddDictionaryExampleWindows(self, parent, policy): | 282 def _AddDictionaryExampleWindows(self, parent, policy): |
280 '''Adds an example value for Windows of a 'dict' policy to a DOM node. | 283 '''Adds an example value for Windows of a 'dict' policy to a DOM node. |
281 | 284 |
282 Args: | 285 Args: |
283 parent: The DOM node for which the example will be added. | 286 parent: The DOM node for which the example will be added. |
284 policy: A policy of type 'dict', for which the Windows example value | 287 policy: A policy of type 'dict', for which the Windows example value |
285 is generated. | 288 is generated. |
286 ''' | 289 ''' |
287 self.AddElement(parent, 'dt', {}, 'Windows:') | 290 self.AddElement(parent, 'dt', {}, 'Windows:') |
288 win = self._AddStyledElement(parent, 'dd', ['.monospace', '.pre']) | 291 win = self._AddStyledElement(parent, 'dd', ['.monospace', '.pre']) |
289 key_name = self.config['win_reg_mandatory_key_name'] | 292 if self.CanBeRecommended(policy) and not self.CanBeMandatory(policy): |
| 293 key_name = self.config['win_reg_recommended_key_name'] |
| 294 else: |
| 295 key_name = self.config['win_reg_mandatory_key_name'] |
290 example = str(policy['example_value']) | 296 example = str(policy['example_value']) |
291 self.AddText(win, '%s\\%s = "%s"' % (key_name, policy['name'], example)) | 297 self.AddText(win, '%s\\%s = "%s"' % (key_name, policy['name'], example)) |
292 | 298 |
293 def _AddDictionaryExampleLinux(self, parent, policy): | 299 def _AddDictionaryExampleLinux(self, parent, policy): |
294 '''Adds an example value for Linux of a 'dict' policy to a DOM node. | 300 '''Adds an example value for Linux of a 'dict' policy to a DOM node. |
295 | 301 |
296 Args: | 302 Args: |
297 parent: The DOM node for which the example will be added. | 303 parent: The DOM node for which the example will be added. |
298 policy: A policy of type 'dict', for which the Linux example value | 304 policy: A policy of type 'dict', for which the Linux example value |
299 is generated. | 305 is generated. |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 | 457 |
452 dl = self.AddElement(parent, 'dl') | 458 dl = self.AddElement(parent, 'dl') |
453 data_type = self._TYPE_MAP[policy['type']] | 459 data_type = self._TYPE_MAP[policy['type']] |
454 if (self.IsPolicySupportedOnPlatform(policy, 'win') and | 460 if (self.IsPolicySupportedOnPlatform(policy, 'win') and |
455 self._REG_TYPE_MAP.get(policy['type'], None)): | 461 self._REG_TYPE_MAP.get(policy['type'], None)): |
456 data_type += ' (%s)' % self._REG_TYPE_MAP[policy['type']] | 462 data_type += ' (%s)' % self._REG_TYPE_MAP[policy['type']] |
457 self._AddPolicyAttribute(dl, 'data_type', data_type) | 463 self._AddPolicyAttribute(dl, 'data_type', data_type) |
458 if policy['type'] != 'external': | 464 if policy['type'] != 'external': |
459 # All types except 'external' can be set through platform policy. | 465 # All types except 'external' can be set through platform policy. |
460 if self.IsPolicySupportedOnPlatform(policy, 'win'): | 466 if self.IsPolicySupportedOnPlatform(policy, 'win'): |
| 467 if self.CanBeRecommended(policy) and not self.CanBeMandatory(policy): |
| 468 key_name = self.config['win_reg_recommended_key_name'] |
| 469 else: |
| 470 key_name = self.config['win_reg_mandatory_key_name'] |
461 self._AddPolicyAttribute( | 471 self._AddPolicyAttribute( |
462 dl, | 472 dl, |
463 'win_reg_loc', | 473 'win_reg_loc', |
464 self.config['win_reg_mandatory_key_name'] + '\\' + policy['name'], | 474 key_name + '\\' + policy['name'], |
465 ['.monospace']) | 475 ['.monospace']) |
466 if (self.IsPolicySupportedOnPlatform(policy, 'linux') or | 476 if (self.IsPolicySupportedOnPlatform(policy, 'linux') or |
467 self.IsPolicySupportedOnPlatform(policy, 'mac')): | 477 self.IsPolicySupportedOnPlatform(policy, 'mac')): |
468 self._AddPolicyAttribute( | 478 self._AddPolicyAttribute( |
469 dl, | 479 dl, |
470 'mac_linux_pref_name', | 480 'mac_linux_pref_name', |
471 policy['name'], | 481 policy['name'], |
472 ['.monospace']) | 482 ['.monospace']) |
473 dd = self._AddPolicyAttribute(dl, 'supported_on') | 483 dd = self._AddPolicyAttribute(dl, 'supported_on') |
474 self._AddSupportedOnList(dd, policy['supported_on']) | 484 self._AddSupportedOnList(dd, policy['supported_on']) |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 } | 684 } |
675 | 685 |
676 # A simple regexp to search for URLs. It is enough for now. | 686 # A simple regexp to search for URLs. It is enough for now. |
677 self._url_matcher = lazy_re.compile('(http://[^\\s]*[^\\s\\.])') | 687 self._url_matcher = lazy_re.compile('(http://[^\\s]*[^\\s\\.])') |
678 | 688 |
679 def GetTemplateText(self): | 689 def GetTemplateText(self): |
680 # Return the text representation of the main <div> tag. | 690 # Return the text representation of the main <div> tag. |
681 return self._main_div.toxml() | 691 return self._main_div.toxml() |
682 # To get a complete HTML file, use the following. | 692 # To get a complete HTML file, use the following. |
683 # return self._doc.toxml() | 693 # return self._doc.toxml() |
OLD | NEW |