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

Side by Side Diff: grit/format/policy_templates/writers/plist_writer.py

Issue 550163002: Add optional mandatory policy setting for template generation (Closed) Base URL: http://grit-i18n.googlecode.com/svn/trunk/
Patch Set: Created 6 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 | Annotate | Revision Log
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 from xml.dom import minidom 7 from xml.dom import minidom
8 from grit.format.policy_templates.writers import plist_helper 8 from grit.format.policy_templates.writers import plist_helper
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 value element contains a string. The name of the value element will be 60 value element contains a string. The name of the value element will be
61 <string>. 61 <string>.
62 62
63 Args: 63 Args:
64 key_string: The content of the key tag. 64 key_string: The content of the key tag.
65 value_string: The content of the value tag. 65 value_string: The content of the value tag.
66 ''' 66 '''
67 self.AddElement(parent, 'key', {}, key_string) 67 self.AddElement(parent, 'key', {}, key_string)
68 self.AddElement(parent, 'string', {}, value_string) 68 self.AddElement(parent, 'string', {}, value_string)
69 69
70 def _AddTargets(self, parent): 70 def _AddTargets(self, parent, policy):
71 '''Adds the following XML snippet to an XML element: 71 '''Adds the following XML snippet to an XML element:
72 <key>pfm_targets</key> 72 <key>pfm_targets</key>
73 <array> 73 <array>
74 <string>user-managed</string> 74 <string>user-managed</string>
75 </array> 75 </array>
76 76
77 Args: 77 Args:
78 parent: The parent XML element where the snippet will be added. 78 parent: The parent XML element where the snippet will be added.
79 ''' 79 '''
80 array = self._AddKeyValuePair(parent, 'pfm_targets', 'array') 80 array = self._AddKeyValuePair(parent, 'pfm_targets', 'array')
81 self.AddElement(array, 'string', {}, 'user-managed') 81 if self.CanBeRecommended(policy):
82 self.AddElement(array, 'string', {}, 'user')
83 if self.CanBeMandatory(policy):
84 self.AddElement(array, 'string', {}, 'user-managed')
82 85
83 def PreprocessPolicies(self, policy_list): 86 def PreprocessPolicies(self, policy_list):
84 return self.FlattenGroupsAndSortPolicies(policy_list) 87 return self.FlattenGroupsAndSortPolicies(policy_list)
85 88
86 def WritePolicy(self, policy): 89 def WritePolicy(self, policy):
87 policy_name = policy['name'] 90 policy_name = policy['name']
88 policy_type = policy['type'] 91 policy_type = policy['type']
89 if policy_type == 'external': 92 if policy_type == 'external':
90 # This type can only be set through cloud policy. 93 # This type can only be set through cloud policy.
91 return 94 return
92 95
93 dict = self.AddElement(self._array, 'dict') 96 dict = self.AddElement(self._array, 'dict')
94 self._AddStringKeyValuePair(dict, 'pfm_name', policy_name) 97 self._AddStringKeyValuePair(dict, 'pfm_name', policy_name)
95 # Set empty strings for title and description. They will be taken by the 98 # Set empty strings for title and description. They will be taken by the
96 # OSX Workgroup Manager from the string table in a Localizable.strings file. 99 # OSX Workgroup Manager from the string table in a Localizable.strings file.
97 # Those files are generated by plist_strings_writer. 100 # Those files are generated by plist_strings_writer.
98 self._AddStringKeyValuePair(dict, 'pfm_description', '') 101 self._AddStringKeyValuePair(dict, 'pfm_description', '')
99 self._AddStringKeyValuePair(dict, 'pfm_title', '') 102 self._AddStringKeyValuePair(dict, 'pfm_title', '')
100 self._AddTargets(dict) 103 self._AddTargets(dict, policy)
101 self._AddStringKeyValuePair(dict, 'pfm_type', 104 self._AddStringKeyValuePair(dict, 'pfm_type',
102 self.TYPE_TO_INPUT[policy_type]) 105 self.TYPE_TO_INPUT[policy_type])
103 if policy_type in ('int-enum', 'string-enum'): 106 if policy_type in ('int-enum', 'string-enum'):
104 range_list = self._AddKeyValuePair(dict, 'pfm_range_list', 'array') 107 range_list = self._AddKeyValuePair(dict, 'pfm_range_list', 'array')
105 for item in policy['items']: 108 for item in policy['items']:
106 if policy_type == 'int-enum': 109 if policy_type == 'int-enum':
107 element_type = 'integer' 110 element_type = 'integer'
108 else: 111 else:
109 element_type = 'string' 112 element_type = 'string'
110 self.AddElement(range_list, element_type, {}, str(item['value'])) 113 self.AddElement(range_list, element_type, {}, str(item['value']))
(...skipping 24 matching lines...) Expand all
135 '-//Apple//DTD PLIST 1.0//EN', 138 '-//Apple//DTD PLIST 1.0//EN',
136 'http://www.apple.com/DTDs/PropertyList-1.0.dtd') 139 'http://www.apple.com/DTDs/PropertyList-1.0.dtd')
137 return dom_impl.createDocument(None, 'plist', doctype) 140 return dom_impl.createDocument(None, 'plist', doctype)
138 141
139 def Init(self): 142 def Init(self):
140 self._doc = self.CreatePlistDocument() 143 self._doc = self.CreatePlistDocument()
141 self._plist = self._doc.documentElement 144 self._plist = self._doc.documentElement
142 145
143 def GetTemplateText(self): 146 def GetTemplateText(self):
144 return self.ToPrettyXml(self._doc) 147 return self.ToPrettyXml(self._doc)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698