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