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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 <string>Shockwave Flash</string> | 220 <string>Shockwave Flash</string> |
221 </array> | 221 </array> |
222 </dd> | 222 </dd> |
223 </dl> | 223 </dl> |
224 | 224 |
225 Args: | 225 Args: |
226 parent: The DOM node for which the example will be added. | 226 parent: The DOM node for which the example will be added. |
227 policy: The data structure of a policy. | 227 policy: The data structure of a policy. |
228 ''' | 228 ''' |
229 examples = self._AddStyledElement(parent, 'dl', ['dd dl']) | 229 examples = self._AddStyledElement(parent, 'dl', ['dd dl']) |
230 self._AddListExampleWindows(examples, policy) | 230 if self.IsPolicySupportedOnPlatform(policy, 'win'): |
231 self._AddListExampleLinux(examples, policy) | 231 self._AddListExampleWindows(examples, policy) |
232 self._AddListExampleMac(examples, policy) | 232 if self.IsPolicySupportedOnPlatform(policy, 'linux'): |
| 233 self._AddListExampleLinux(examples, policy) |
| 234 if self.IsPolicySupportedOnPlatform(policy, 'mac'): |
| 235 self._AddListExampleMac(examples, policy) |
233 | 236 |
234 def _PythonDictionaryToMacDictionary(self, dictionary, indent=''): | 237 def _PythonDictionaryToMacDictionary(self, dictionary, indent=''): |
235 '''Converts a python dictionary to an equivalent XML plist. | 238 '''Converts a python dictionary to an equivalent XML plist. |
236 | 239 |
237 Returns a list of lines, with one dictionary entry per line.''' | 240 Returns a list of lines, with one dictionary entry per line.''' |
238 result = [indent + '<dict>'] | 241 result = [indent + '<dict>'] |
239 indent += ' ' | 242 indent += ' ' |
240 for k in sorted(dictionary.keys()): | 243 for k in sorted(dictionary.keys()): |
241 v = dictionary[k] | 244 v = dictionary[k] |
242 result.append('%s<key>%s</key>' % (indent, k)) | 245 result.append('%s<key>%s</key>' % (indent, k)) |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 <string>direct</string> | 332 <string>direct</string> |
330 </dict> | 333 </dict> |
331 </dd> | 334 </dd> |
332 </dl> | 335 </dl> |
333 | 336 |
334 Args: | 337 Args: |
335 parent: The DOM node for which the example will be added. | 338 parent: The DOM node for which the example will be added. |
336 policy: The data structure of a policy. | 339 policy: The data structure of a policy. |
337 ''' | 340 ''' |
338 examples = self._AddStyledElement(parent, 'dl', ['dd dl']) | 341 examples = self._AddStyledElement(parent, 'dl', ['dd dl']) |
339 self._AddDictionaryExampleWindows(examples, policy) | 342 if self.IsPolicySupportedOnPlatform(policy, 'win'): |
340 self._AddDictionaryExampleLinux(examples, policy) | 343 self._AddDictionaryExampleWindows(examples, policy) |
341 self._AddDictionaryExampleMac(examples, policy) | 344 if self.IsPolicySupportedOnPlatform(policy, 'linux'): |
| 345 self._AddDictionaryExampleLinux(examples, policy) |
| 346 if self.IsPolicySupportedOnPlatform(policy, 'mac'): |
| 347 self._AddDictionaryExampleMac(examples, policy) |
342 | 348 |
343 def _AddExample(self, parent, policy): | 349 def _AddExample(self, parent, policy): |
344 '''Adds the HTML DOM representation of the example value of a policy to | 350 '''Adds the HTML DOM representation of the example value of a policy to |
345 a DOM node. It is simple text for boolean policies, like | 351 a DOM node. It is simple text for boolean policies, like |
346 '0x00000001 (Windows), true (Linux), <true /> (Mac)' in case of boolean | 352 '0x00000001 (Windows), true (Linux), <true /> (Mac)' in case of boolean |
347 policies, but it may also contain other HTML elements. (See method | 353 policies, but it may also contain other HTML elements. (See method |
348 _AddListExample.) | 354 _AddListExample.) |
349 | 355 |
350 Args: | 356 Args: |
351 parent: The DOM node for which the example will be added. | 357 parent: The DOM node for which the example will be added. |
352 policy: The data structure of a policy. | 358 policy: The data structure of a policy. |
353 | 359 |
354 Raises: | 360 Raises: |
355 Exception: If the type of the policy is unknown or the example value | 361 Exception: If the type of the policy is unknown or the example value |
356 of the policy is out of its expected range. | 362 of the policy is out of its expected range. |
357 ''' | 363 ''' |
358 example_value = policy['example_value'] | 364 example_value = policy['example_value'] |
359 policy_type = policy['type'] | 365 policy_type = policy['type'] |
360 if policy_type == 'main': | 366 if policy_type == 'main': |
361 if example_value == True: | 367 pieces = [] |
362 self.AddText( | 368 if self.IsPolicySupportedOnPlatform(policy, 'win'): |
363 parent, '0x00000001 (Windows), true (Linux), <true /> (Mac)') | 369 value = '0x00000001' if example_value else '0x00000000' |
364 elif example_value == False: | 370 pieces.append(value + ' (Windows)') |
365 self.AddText( | 371 if self.IsPolicySupportedOnPlatform(policy, 'linux'): |
366 parent, '0x00000000 (Windows), false (Linux), <false /> (Mac)') | 372 value = 'true' if example_value else 'false' |
367 else: | 373 pieces.append(value + ' (Linux)') |
368 raise Exception('Expected boolean value.') | 374 if self.IsPolicySupportedOnPlatform(policy, 'mac'): |
| 375 value = '<true />' if example_value else '<false />' |
| 376 pieces.append(value + ' (Mac)') |
| 377 self.AddText(parent, ', '.join(pieces)) |
369 elif policy_type == 'string': | 378 elif policy_type == 'string': |
370 self.AddText(parent, '"%s"' % example_value) | 379 self.AddText(parent, '"%s"' % example_value) |
371 elif policy_type in ('int', 'int-enum'): | 380 elif policy_type in ('int', 'int-enum'): |
372 self.AddText( | 381 pieces = [] |
373 parent, | 382 if self.IsPolicySupportedOnPlatform(policy, 'win'): |
374 '0x%08x (Windows), %d (Linux/Mac)' % (example_value, example_value)) | 383 pieces.append('0x%08x (Windows)' % example_value) |
| 384 if self.IsPolicySupportedOnPlatform(policy, 'linux'): |
| 385 pieces.append('%d (Linux)' % example_value) |
| 386 if self.IsPolicySupportedOnPlatform(policy, 'mac'): |
| 387 pieces.append('%d (Mac)' % example_value) |
| 388 self.AddText(parent, ', '.join(pieces)) |
375 elif policy_type == 'string-enum': | 389 elif policy_type == 'string-enum': |
376 self.AddText(parent, '"%s"' % (example_value)) | 390 self.AddText(parent, '"%s"' % (example_value)) |
377 elif policy_type == 'list': | 391 elif policy_type == 'list': |
378 self._AddListExample(parent, policy) | 392 self._AddListExample(parent, policy) |
379 elif policy_type == 'dict': | 393 elif policy_type == 'dict': |
380 self._AddDictionaryExample(parent, policy) | 394 self._AddDictionaryExample(parent, policy) |
381 else: | 395 else: |
382 raise Exception('Unknown policy type: ' + policy_type) | 396 raise Exception('Unknown policy type: ' + policy_type) |
383 | 397 |
384 def _AddPolicyAttribute(self, dl, term_id, | 398 def _AddPolicyAttribute(self, dl, term_id, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 <dt>Attribute:</dt><dd>Description</dd> | 452 <dt>Attribute:</dt><dd>Description</dd> |
439 ... | 453 ... |
440 </dl> | 454 </dl> |
441 | 455 |
442 Args: | 456 Args: |
443 parent: A DOM element for which the list will be added. | 457 parent: A DOM element for which the list will be added. |
444 policy: The data structure of the policy. | 458 policy: The data structure of the policy. |
445 ''' | 459 ''' |
446 | 460 |
447 dl = self.AddElement(parent, 'dl') | 461 dl = self.AddElement(parent, 'dl') |
448 self._AddPolicyAttribute( | 462 data_type = self._TYPE_MAP[policy['type']] |
449 dl, | 463 if (self.IsPolicySupportedOnPlatform(policy, 'win') and |
450 'data_type', | 464 self._REG_TYPE_MAP.get(policy['type'], None)): |
451 self._TYPE_MAP[policy['type']]) | 465 data_type += ' (%s)' % self._REG_TYPE_MAP[policy['type']] |
452 self._AddPolicyAttribute( | 466 self._AddPolicyAttribute(dl, 'data_type', data_type) |
453 dl, | 467 if self.IsPolicySupportedOnPlatform(policy, 'win'): |
454 'win_reg_loc', | 468 self._AddPolicyAttribute( |
455 self.config['win_reg_mandatory_key_name'] + '\\' + policy['name'], | 469 dl, |
456 ['.monospace']) | 470 'win_reg_loc', |
457 self._AddPolicyAttribute( | 471 self.config['win_reg_mandatory_key_name'] + '\\' + policy['name'], |
458 dl, | 472 ['.monospace']) |
459 'mac_linux_pref_name', | 473 if (self.IsPolicySupportedOnPlatform(policy, 'linux') or |
460 policy['name'], | 474 self.IsPolicySupportedOnPlatform(policy, 'mac')): |
461 ['.monospace']) | 475 self._AddPolicyAttribute( |
| 476 dl, |
| 477 'mac_linux_pref_name', |
| 478 policy['name'], |
| 479 ['.monospace']) |
462 dd = self._AddPolicyAttribute(dl, 'supported_on') | 480 dd = self._AddPolicyAttribute(dl, 'supported_on') |
463 self._AddSupportedOnList(dd, policy['supported_on']) | 481 self._AddSupportedOnList(dd, policy['supported_on']) |
464 dd = self._AddPolicyAttribute(dl, 'supported_features') | 482 dd = self._AddPolicyAttribute(dl, 'supported_features') |
465 self._AddFeatures(dd, policy) | 483 self._AddFeatures(dd, policy) |
466 dd = self._AddPolicyAttribute(dl, 'description') | 484 dd = self._AddPolicyAttribute(dl, 'description') |
467 self._AddDescription(dd, policy) | 485 self._AddDescription(dd, policy) |
468 dd = self._AddPolicyAttribute(dl, 'example_value') | 486 if (self.IsPolicySupportedOnPlatform(policy, 'win') or |
469 self._AddExample(dd, policy) | 487 self.IsPolicySupportedOnPlatform(policy, 'linux') or |
| 488 self.IsPolicySupportedOnPlatform(policy, 'mac')): |
| 489 # Don't add an example for ChromeOS-only policies. |
| 490 dd = self._AddPolicyAttribute(dl, 'example_value') |
| 491 self._AddExample(dd, policy) |
470 | 492 |
471 def _AddPolicyNote(self, parent, policy): | 493 def _AddPolicyNote(self, parent, policy): |
472 '''If a policy has an additional web page assigned with it, then add | 494 '''If a policy has an additional web page assigned with it, then add |
473 a link for that page. | 495 a link for that page. |
474 | 496 |
475 Args: | 497 Args: |
476 policy: The data structure of the policy. | 498 policy: The data structure of the policy. |
477 ''' | 499 ''' |
478 if 'problem_href' not in policy: | 500 if 'problem_href' not in policy: |
479 return | 501 return |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 'chrome_os': self.config['os_name'], | 630 'chrome_os': self.config['os_name'], |
609 } | 631 } |
610 # Human-readable names of supported features. Each supported feature has | 632 # Human-readable names of supported features. Each supported feature has |
611 # a 'doc_feature_X' entry in |self.messages|. | 633 # a 'doc_feature_X' entry in |self.messages|. |
612 self._FEATURE_MAP = {} | 634 self._FEATURE_MAP = {} |
613 for message in self.messages: | 635 for message in self.messages: |
614 if message.startswith('doc_feature_'): | 636 if message.startswith('doc_feature_'): |
615 self._FEATURE_MAP[message[12:]] = self.messages[message]['text'] | 637 self._FEATURE_MAP[message[12:]] = self.messages[message]['text'] |
616 # Human-readable names of types. | 638 # Human-readable names of types. |
617 self._TYPE_MAP = { | 639 self._TYPE_MAP = { |
618 'string': 'String (REG_SZ)', | 640 'string': 'String', |
619 'int': 'Integer (REG_DWORD)', | 641 'int': 'Integer', |
620 'main': 'Boolean (REG_DWORD)', | 642 'main': 'Boolean', |
621 'int-enum': 'Integer (REG_DWORD)', | 643 'int-enum': 'Integer', |
622 'string-enum': 'String (REG_SZ)', | 644 'string-enum': 'String', |
623 'list': 'List of strings', | 645 'list': 'List of strings', |
624 'dict': 'Dictionary (REG_SZ, encoded as a JSON string)', | 646 'dict': 'Dictionary', |
| 647 } |
| 648 self._REG_TYPE_MAP = { |
| 649 'string': 'REG_SZ', |
| 650 'int': 'REG_DWORD', |
| 651 'main': 'REG_DWORD', |
| 652 'int-enum': 'REG_DWORD', |
| 653 'string-enum': 'REG_SZ', |
| 654 'dict': 'REG_SZ, encoded as a JSON string', |
625 } | 655 } |
626 # The CSS style-sheet used for the document. It will be used in Google | 656 # The CSS style-sheet used for the document. It will be used in Google |
627 # Sites, which strips class attributes from HTML tags. To work around this, | 657 # Sites, which strips class attributes from HTML tags. To work around this, |
628 # the style-sheet is a dictionary and the style attributes will be added | 658 # the style-sheet is a dictionary and the style attributes will be added |
629 # "by hand" for each element. | 659 # "by hand" for each element. |
630 self._STYLE = { | 660 self._STYLE = { |
631 'table': 'border-style: none; border-collapse: collapse;', | 661 'table': 'border-style: none; border-collapse: collapse;', |
632 'tr': 'height: 0px;', | 662 'tr': 'height: 0px;', |
633 'td': 'border: 1px dotted rgb(170, 170, 170); padding: 7px; ' | 663 'td': 'border: 1px dotted rgb(170, 170, 170); padding: 7px; ' |
634 'vertical-align: top; width: 236px; height: 15px;', | 664 'vertical-align: top; width: 236px; height: 15px;', |
(...skipping 10 matching lines...) Expand all Loading... |
645 } | 675 } |
646 | 676 |
647 # A simple regexp to search for URLs. It is enough for now. | 677 # A simple regexp to search for URLs. It is enough for now. |
648 self._url_matcher = lazy_re.compile('(http://[^\\s]*[^\\s\\.])') | 678 self._url_matcher = lazy_re.compile('(http://[^\\s]*[^\\s\\.])') |
649 | 679 |
650 def GetTemplateText(self): | 680 def GetTemplateText(self): |
651 # Return the text representation of the main <div> tag. | 681 # Return the text representation of the main <div> tag. |
652 return self._main_div.toxml() | 682 return self._main_div.toxml() |
653 # To get a complete HTML file, use the following. | 683 # To get a complete HTML file, use the following. |
654 # return self._doc.toxml() | 684 # return self._doc.toxml() |
OLD | NEW |