Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(872)

Side by Side Diff: components/policy/tools/template_writers/writers/doc_writer.py

Issue 2653823006: Include 'external' policies in grit output (admx, adm, doc etc.) (Closed)
Patch Set: Whitespace fix Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 import re 8 import re
9 from xml.dom import minidom 9 from xml.dom import minidom
10 from writers import xml_formatted_writer 10 from writers import xml_formatted_writer
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 result = [ '%s<dict>' % indent ] 292 result = [ '%s<dict>' % indent ]
293 for key in sorted(obj.keys()): 293 for key in sorted(obj.keys()):
294 result.append('%s<key>%s</key>' % (indent + ' ', key)) 294 result.append('%s<key>%s</key>' % (indent + ' ', key))
295 result += self._PythonObjectToPlist(obj[key], indent + ' ') 295 result += self._PythonObjectToPlist(obj[key], indent + ' ')
296 result.append('%s</dict>' % indent) 296 result.append('%s</dict>' % indent)
297 return result 297 return result
298 else: 298 else:
299 raise Exception('Invalid object to convert: %s' % obj) 299 raise Exception('Invalid object to convert: %s' % obj)
300 300
301 def _AddDictionaryExampleMac(self, parent, policy): 301 def _AddDictionaryExampleMac(self, parent, policy):
302 '''Adds an example value for Mac of a 'dict' policy to a DOM node. 302 '''Adds an example value for Mac of a 'dict' or 'external' policy to a DOM
303 node.
303 304
304 Args: 305 Args:
305 parent: The DOM node for which the example will be added. 306 parent: The DOM node for which the example will be added.
306 policy: A policy of type 'dict', for which the Mac example value 307 policy: A policy of type 'dict', for which the Mac example value
307 is generated. 308 is generated.
308 ''' 309 '''
309 example_value = policy['example_value'] 310 example_value = policy['example_value']
310 self.AddElement(parent, 'dt', {}, 'Mac:') 311 self.AddElement(parent, 'dt', {}, 'Mac:')
311 mac = self._AddStyledElement(parent, 'dd', ['.monospace', '.pre']) 312 mac = self._AddStyledElement(parent, 'dd', ['.monospace', '.pre'])
312 mac_text = ['<key>%s</key>' % (policy['name'])] 313 mac_text = ['<key>%s</key>' % (policy['name'])]
313 mac_text += self._PythonObjectToPlist(example_value) 314 mac_text += self._PythonObjectToPlist(example_value)
314 self.AddText(mac, '\n'.join(mac_text)) 315 self.AddText(mac, '\n'.join(mac_text))
315 316
316 def _AddDictionaryExampleWindowsChromeOS(self, parent, policy, is_win): 317 def _AddDictionaryExampleWindowsChromeOS(self, parent, policy, is_win):
317 '''Adds an example value for Windows of a 'dict' policy to a DOM node. 318 '''Adds an example value for Windows of a 'dict' or 'external' policy to a
319 DOM node.
318 320
319 Args: 321 Args:
320 parent: The DOM node for which the example will be added. 322 parent: The DOM node for which the example will be added.
321 policy: A policy of type 'dict', for which the Windows example value 323 policy: A policy of type 'dict', for which the Windows example value
322 is generated. 324 is generated.
323 ''' 325 '''
324 os_header = self._GetLocalizedMessage('win_example_value') if is_win else \ 326 os_header = self._GetLocalizedMessage('win_example_value') if is_win else \
325 self._GetLocalizedMessage('chrome_os_example_value') 327 self._GetLocalizedMessage('chrome_os_example_value')
326 self.AddElement(parent, 'dt', {}, os_header) 328 self.AddElement(parent, 'dt', {}, os_header)
327 element = self._AddStyledElement(parent, 'dd', ['.monospace', '.pre']) 329 element = self._AddStyledElement(parent, 'dd', ['.monospace', '.pre'])
328 key_name = self._GetRegistryKeyName(policy, is_win) 330 key_name = self._GetRegistryKeyName(policy, is_win)
329 example = json.dumps(policy['example_value']) 331 example = json.dumps(policy['example_value'])
330 self.AddText(element, '%s\\%s = %s' % (key_name, policy['name'], example)) 332 self.AddText(element, '%s\\%s = %s' % (key_name, policy['name'], example))
331 333
332 def _AddDictionaryExampleAndroidLinux(self, parent, policy): 334 def _AddDictionaryExampleAndroidLinux(self, parent, policy):
333 '''Adds an example value for Android/Linux of a 'dict' policy to a DOM node. 335 '''Adds an example value for Android/Linux of a 'dict' or 'external' policy
336 to a DOM node.
334 337
335 Args: 338 Args:
336 parent: The DOM node for which the example will be added. 339 parent: The DOM node for which the example will be added.
337 policy: A policy of type 'dict', for which the Android/Linux example value 340 policy: A policy of type 'dict', for which the Android/Linux example value
338 is generated. 341 is generated.
339 ''' 342 '''
340 self.AddElement(parent, 'dt', {}, 'Android/Linux:') 343 self.AddElement(parent, 'dt', {}, 'Android/Linux:')
341 element = self._AddStyledElement(parent, 'dd', ['.monospace']) 344 element = self._AddStyledElement(parent, 'dd', ['.monospace'])
342 example = json.dumps(policy['example_value']) 345 example = json.dumps(policy['example_value'])
343 self.AddText(element, '%s: %s' % (policy['name'], example)) 346 self.AddText(element, '%s: %s' % (policy['name'], example))
344 347
345 def _AddDictionaryExample(self, parent, policy): 348 def _AddDictionaryExample(self, parent, policy):
346 '''Adds the example value of a 'dict' policy to a DOM node. Example output: 349 '''Adds the example value of a 'dict' or 'external' policy to a DOM node.
350
351 Example output:
347 <dl> 352 <dl>
348 <dt>Windows (Windows clients):</dt> 353 <dt>Windows (Windows clients):</dt>
349 <dd> 354 <dd>
350 Software\Policies\Chromium\ProxySettings = "{ 'ProxyMode': 'direct' }" 355 Software\Policies\Chromium\ProxySettings = "{ 'ProxyMode': 'direct' }"
351 </dd> 356 </dd>
352 <dt>Windows (Chromium OS clients):</dt> 357 <dt>Windows (Chromium OS clients):</dt>
353 <dd> 358 <dd>
354 Software\Policies\ChromiumOS\ProxySettings = "{ 'ProxyMode': 'direct' }" 359 Software\Policies\ChromiumOS\ProxySettings = "{ 'ProxyMode': 'direct' }"
355 </dd> 360 </dd>
356 <dt>Android/Linux:</dt> 361 <dt>Android/Linux:</dt>
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 pieces.append('%d (Linux)' % example_value) 432 pieces.append('%d (Linux)' % example_value)
428 if self.IsPolicySupportedOnPlatform(policy, 'android'): 433 if self.IsPolicySupportedOnPlatform(policy, 'android'):
429 pieces.append('%d (Android)' % example_value) 434 pieces.append('%d (Android)' % example_value)
430 if self.IsPolicySupportedOnPlatform(policy, 'mac'): 435 if self.IsPolicySupportedOnPlatform(policy, 'mac'):
431 pieces.append('%d (Mac)' % example_value) 436 pieces.append('%d (Mac)' % example_value)
432 self.AddText(parent, ', '.join(pieces)) 437 self.AddText(parent, ', '.join(pieces))
433 elif policy_type == 'string-enum': 438 elif policy_type == 'string-enum':
434 self.AddText(parent, '"%s"' % (example_value)) 439 self.AddText(parent, '"%s"' % (example_value))
435 elif policy_type in ('list', 'string-enum-list'): 440 elif policy_type in ('list', 'string-enum-list'):
436 self._AddListExample(parent, policy) 441 self._AddListExample(parent, policy)
437 elif policy_type == 'dict': 442 elif policy_type in ('dict', 'external'):
438 self._AddDictionaryExample(parent, policy) 443 self._AddDictionaryExample(parent, policy)
439 else: 444 else:
440 raise Exception('Unknown policy type: ' + policy_type) 445 raise Exception('Unknown policy type: ' + policy_type)
441 446
442 def _AddPolicyAttribute(self, dl, term_id, 447 def _AddPolicyAttribute(self, dl, term_id,
443 definition=None, definition_style=None): 448 definition=None, definition_style=None):
444 '''Adds a term-definition pair to a HTML DOM <dl> node. This method is 449 '''Adds a term-definition pair to a HTML DOM <dl> node. This method is
445 used by _AddPolicyDetails. Its result will have the form of: 450 used by _AddPolicyDetails. Its result will have the form of:
446 <dt style="...">...</dt> 451 <dt style="...">...</dt>
447 <dd style="...">...</dd> 452 <dd style="...">...</dd>
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 ''' 508 '''
504 509
505 dl = self.AddElement(parent, 'dl') 510 dl = self.AddElement(parent, 'dl')
506 data_type = [self._TYPE_MAP[policy['type']]] 511 data_type = [self._TYPE_MAP[policy['type']]]
507 qualified_types = [] 512 qualified_types = []
508 is_complex_policy = False 513 is_complex_policy = False
509 if (self.IsPolicySupportedOnPlatform(policy, 'android') and 514 if (self.IsPolicySupportedOnPlatform(policy, 'android') and
510 self._RESTRICTION_TYPE_MAP.get(policy['type'], None)): 515 self._RESTRICTION_TYPE_MAP.get(policy['type'], None)):
511 qualified_types.append('Android:%s' % 516 qualified_types.append('Android:%s' %
512 self._RESTRICTION_TYPE_MAP[policy['type']]) 517 self._RESTRICTION_TYPE_MAP[policy['type']])
513 if policy['type'] in ('dict', 'list'): 518 if policy['type'] in ('dict', 'external', 'list'):
514 is_complex_policy = True 519 is_complex_policy = True
515 if ((self.IsPolicySupportedOnPlatform(policy, 'win') or 520 if ((self.IsPolicySupportedOnPlatform(policy, 'win') or
516 self.IsPolicySupportedOnPlatform(policy, 'chrome_os')) and 521 self.IsPolicySupportedOnPlatform(policy, 'chrome_os')) and
517 self._REG_TYPE_MAP.get(policy['type'], None)): 522 self._REG_TYPE_MAP.get(policy['type'], None)):
518 qualified_types.append('Windows:%s' % self._REG_TYPE_MAP[policy['type']]) 523 qualified_types.append('Windows:%s' % self._REG_TYPE_MAP[policy['type']])
519 if policy['type'] == 'dict': 524 if policy['type'] in ('dict', 'external'):
520 is_complex_policy = True 525 is_complex_policy = True
521 if qualified_types: 526 if qualified_types:
522 data_type.append('[%s]' % ', '.join(qualified_types)) 527 data_type.append('[%s]' % ', '.join(qualified_types))
523 if is_complex_policy: 528 if is_complex_policy:
524 data_type.append('(%s)' % 529 data_type.append('(%s)' %
525 self._GetLocalizedMessage('complex_policies_on_windows')) 530 self._GetLocalizedMessage('complex_policies_on_windows'))
526 self._AddPolicyAttribute(dl, 'data_type', ' '.join(data_type)) 531 self._AddPolicyAttribute(dl, 'data_type', ' '.join(data_type))
527 if policy['type'] != 'external': 532 if self.IsPolicySupportedOnPlatform(policy, 'win'):
528 # All types except 'external' can be set through platform policy. 533 key_name = self._GetRegistryKeyName(policy, True)
529 if self.IsPolicySupportedOnPlatform(policy, 'win'): 534 self._AddPolicyAttribute(
530 key_name = self._GetRegistryKeyName(policy, True) 535 dl,
531 self._AddPolicyAttribute( 536 'win_reg_loc',
532 dl, 537 key_name + '\\' + policy['name'],
533 'win_reg_loc', 538 ['.monospace'])
534 key_name + '\\' + policy['name'], 539 if self.IsPolicySupportedOnPlatform(policy, 'chrome_os'):
535 ['.monospace']) 540 key_name = self._GetRegistryKeyName(policy, False)
536 if self.IsPolicySupportedOnPlatform(policy, 'chrome_os'): 541 self._AddPolicyAttribute(
537 key_name = self._GetRegistryKeyName(policy, False) 542 dl,
538 self._AddPolicyAttribute( 543 'chrome_os_reg_loc',
539 dl, 544 key_name + '\\' + policy['name'],
540 'chrome_os_reg_loc', 545 ['.monospace'])
541 key_name + '\\' + policy['name'], 546 if (self.IsPolicySupportedOnPlatform(policy, 'linux') or
542 ['.monospace']) 547 self.IsPolicySupportedOnPlatform(policy, 'mac')):
543 if (self.IsPolicySupportedOnPlatform(policy, 'linux') or 548 self._AddPolicyAttribute(
544 self.IsPolicySupportedOnPlatform(policy, 'mac')): 549 dl,
545 self._AddPolicyAttribute( 550 'mac_linux_pref_name',
546 dl, 551 policy['name'],
547 'mac_linux_pref_name', 552 ['.monospace'])
548 policy['name'], 553 if self.IsPolicySupportedOnPlatform(policy, 'android', 'chrome'):
549 ['.monospace']) 554 self._AddPolicyAttribute(
550 if self.IsPolicySupportedOnPlatform(policy, 'android', 'chrome'): 555 dl,
551 self._AddPolicyAttribute( 556 'android_restriction_name',
552 dl, 557 policy['name'],
553 'android_restriction_name', 558 ['.monospace'])
554 policy['name'], 559 if self.IsPolicySupportedOnPlatform(policy, 'android', 'webview'):
555 ['.monospace']) 560 restriction_prefix = self.config['android_webview_restriction_prefix']
556 if self.IsPolicySupportedOnPlatform(policy, 'android', 'webview'): 561 self._AddPolicyAttribute(
557 restriction_prefix = self.config['android_webview_restriction_prefix'] 562 dl,
558 self._AddPolicyAttribute( 563 'android_webview_restriction_name',
559 dl, 564 restriction_prefix + policy['name'],
560 'android_webview_restriction_name', 565 ['.monospace'])
561 restriction_prefix + policy['name'],
562 ['.monospace'])
563 dd = self._AddPolicyAttribute(dl, 'supported_on') 566 dd = self._AddPolicyAttribute(dl, 'supported_on')
564 self._AddSupportedOnList(dd, policy['supported_on']) 567 self._AddSupportedOnList(dd, policy['supported_on'])
565 dd = self._AddPolicyAttribute(dl, 'supported_features') 568 dd = self._AddPolicyAttribute(dl, 'supported_features')
566 self._AddFeatures(dd, policy) 569 self._AddFeatures(dd, policy)
567 dd = self._AddPolicyAttribute(dl, 'description') 570 dd = self._AddPolicyAttribute(dl, 'description')
568 self._AddDescription(dd, policy) 571 self._AddDescription(dd, policy)
569 if 'arc_support' in policy: 572 if 'arc_support' in policy:
570 dd = self._AddPolicyAttribute(dl, 'arc_support') 573 dd = self._AddPolicyAttribute(dl, 'arc_support')
571 self._AddParagraphs(dd, policy['arc_support']) 574 self._AddParagraphs(dd, policy['arc_support'])
572 if (self.IsPolicySupportedOnPlatform(policy, 'win') or 575 if (self.IsPolicySupportedOnPlatform(policy, 'win') or
573 self.IsPolicySupportedOnPlatform(policy, 'linux') or 576 self.IsPolicySupportedOnPlatform(policy, 'linux') or
574 self.IsPolicySupportedOnPlatform(policy, 'android') or 577 self.IsPolicySupportedOnPlatform(policy, 'android') or
575 self.IsPolicySupportedOnPlatform(policy, 'mac')): 578 self.IsPolicySupportedOnPlatform(policy, 'mac')):
576 # Don't add an example for ChromeOS-only policies. 579 # Don't add an example for ChromeOS-only policies.
577 if policy['type'] != 'external': 580 dd = self._AddPolicyAttribute(dl, 'example_value')
578 # All types except 'external' can be set through platform policy. 581 self._AddExample(dd, policy)
579 dd = self._AddPolicyAttribute(dl, 'example_value')
580 self._AddExample(dd, policy)
581 582
582 def _AddPolicyNote(self, parent, policy): 583 def _AddPolicyNote(self, parent, policy):
583 '''If a policy has an additional web page assigned with it, then add 584 '''If a policy has an additional web page assigned with it, then add
584 a link for that page. 585 a link for that page.
585 586
586 Args: 587 Args:
587 policy: The data structure of the policy. 588 policy: The data structure of the policy.
588 ''' 589 '''
589 if 'problem_href' not in policy: 590 if 'problem_href' not in policy:
590 return 591 return
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 'dict': 'Dictionary', 743 'dict': 'Dictionary',
743 'external': 'External data reference', 744 'external': 'External data reference',
744 } 745 }
745 self._REG_TYPE_MAP = { 746 self._REG_TYPE_MAP = {
746 'string': 'REG_SZ', 747 'string': 'REG_SZ',
747 'int': 'REG_DWORD', 748 'int': 'REG_DWORD',
748 'main': 'REG_DWORD', 749 'main': 'REG_DWORD',
749 'int-enum': 'REG_DWORD', 750 'int-enum': 'REG_DWORD',
750 'string-enum': 'REG_SZ', 751 'string-enum': 'REG_SZ',
751 'dict': 'REG_SZ', 752 'dict': 'REG_SZ',
753 'external': 'REG_SZ',
752 } 754 }
753 self._RESTRICTION_TYPE_MAP = { 755 self._RESTRICTION_TYPE_MAP = {
754 'int-enum': 'choice', 756 'int-enum': 'choice',
755 'string-enum': 'choice', 757 'string-enum': 'choice',
756 'list': 'string', 758 'list': 'string',
757 'string-enum-list': 'multi-select', 759 'string-enum-list': 'multi-select',
758 'dict': 'string', 760 'dict': 'string',
761 'external': 'string',
759 } 762 }
760 # The CSS style-sheet used for the document. It will be used in Google 763 # The CSS style-sheet used for the document. It will be used in Google
761 # Sites, which strips class attributes from HTML tags. To work around this, 764 # Sites, which strips class attributes from HTML tags. To work around this,
762 # the style-sheet is a dictionary and the style attributes will be added 765 # the style-sheet is a dictionary and the style attributes will be added
763 # "by hand" for each element. 766 # "by hand" for each element.
764 self._STYLE = { 767 self._STYLE = {
765 'table': 'border-style: none; border-collapse: collapse;', 768 'table': 'border-style: none; border-collapse: collapse;',
766 'tr': 'height: 0px;', 769 'tr': 'height: 0px;',
767 'td': 'border: 1px dotted rgb(170, 170, 170); padding: 7px; ' 770 'td': 'border: 1px dotted rgb(170, 170, 170); padding: 7px; '
768 'vertical-align: top; width: 236px; height: 15px;', 771 'vertical-align: top; width: 236px; height: 15px;',
769 'thead td': 'font-weight: bold;', 772 'thead td': 'font-weight: bold;',
770 'td.left': 'width: 200px;', 773 'td.left': 'width: 200px;',
771 'td.right': 'width: 100%;', 774 'td.right': 'width: 100%;',
772 'dt': 'font-weight: bold;', 775 'dt': 'font-weight: bold;',
773 'dd dl': 'margin-top: 0px; margin-bottom: 0px;', 776 'dd dl': 'margin-top: 0px; margin-bottom: 0px;',
774 '.monospace': 'font-family: monospace;', 777 '.monospace': 'font-family: monospace;',
775 '.pre': 'white-space: pre;', 778 '.pre': 'white-space: pre;',
776 'div.note': 'border: 2px solid black; padding: 5px; margin: 5px;', 779 'div.note': 'border: 2px solid black; padding: 5px; margin: 5px;',
777 'div.group_desc': 'margin-top: 20px; margin-bottom: 20px;', 780 'div.group_desc': 'margin-top: 20px; margin-bottom: 20px;',
778 'ul': 'padding-left: 0px; margin-left: 0px;' 781 'ul': 'padding-left: 0px; margin-left: 0px;'
779 } 782 }
780 783
781 784
782 def GetTemplateText(self): 785 def GetTemplateText(self):
783 # Return the text representation of the main <div> tag. 786 # Return the text representation of the main <div> tag.
784 return self._main_div.toxml() 787 return self._main_div.toxml()
785 # To get a complete HTML file, use the following. 788 # To get a complete HTML file, use the following.
786 # return self._doc.toxml() 789 # return self._doc.toxml()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698