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 from xml.dom import minidom | 6 from xml.dom import minidom |
7 from writers import xml_formatted_writer | 7 from writers import xml_formatted_writer |
8 import re | 8 import re |
9 | 9 |
10 | 10 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 textbox_elem = self.AddElement(presentation_elem, 'textBox', | 93 textbox_elem = self.AddElement(presentation_elem, 'textBox', |
94 {'refId': policy_name}) | 94 {'refId': policy_name}) |
95 label_elem = self.AddElement(textbox_elem, 'label') | 95 label_elem = self.AddElement(textbox_elem, 'label') |
96 label_elem.appendChild(self._doc.createTextNode(policy_label)) | 96 label_elem.appendChild(self._doc.createTextNode(policy_label)) |
97 elif policy_type == 'int': | 97 elif policy_type == 'int': |
98 textbox_elem = self.AddElement(presentation_elem, 'decimalTextBox', | 98 textbox_elem = self.AddElement(presentation_elem, 'decimalTextBox', |
99 {'refId': policy_name}) | 99 {'refId': policy_name}) |
100 textbox_elem.appendChild(self._doc.createTextNode(policy_label + ':')) | 100 textbox_elem.appendChild(self._doc.createTextNode(policy_label + ':')) |
101 elif policy_type in ('int-enum', 'string-enum'): | 101 elif policy_type in ('int-enum', 'string-enum'): |
102 for item in policy['items']: | 102 for item in policy['items']: |
103 self._AddString(item['name'], item['caption']) | 103 self._AddString(policy_name + "_" + item['name'], item['caption']) |
104 dropdownlist_elem = self.AddElement(presentation_elem, 'dropdownList', | 104 dropdownlist_elem = self.AddElement(presentation_elem, 'dropdownList', |
105 {'refId': policy_name}) | 105 {'refId': policy_name}) |
106 dropdownlist_elem.appendChild(self._doc.createTextNode(policy_label)) | 106 dropdownlist_elem.appendChild(self._doc.createTextNode(policy_label)) |
107 elif policy_type in ('list', 'string-enum-list'): | 107 elif policy_type in ('list', 'string-enum-list'): |
108 self._AddString(policy_name + 'Desc', policy_caption) | 108 self._AddString(policy_name + 'Desc', policy_caption) |
109 listbox_elem = self.AddElement(presentation_elem, 'listBox', | 109 listbox_elem = self.AddElement(presentation_elem, 'listBox', |
110 {'refId': policy_name + 'Desc'}) | 110 {'refId': policy_name + 'Desc'}) |
111 listbox_elem.appendChild(self._doc.createTextNode(policy_label)) | 111 listbox_elem.appendChild(self._doc.createTextNode(policy_label)) |
112 elif policy_type == 'group': | 112 elif policy_type == 'group': |
113 pass | 113 pass |
(...skipping 18 matching lines...) Expand all Loading... |
132 # Add ADML "string" elements to the string-table that are required by a | 132 # Add ADML "string" elements to the string-table that are required by a |
133 # Policy-Group. | 133 # Policy-Group. |
134 self._AddString(group['name'] + '_group', group['caption']) | 134 self._AddString(group['name'] + '_group', group['caption']) |
135 | 135 |
136 def _AddBaseStrings(self): | 136 def _AddBaseStrings(self): |
137 ''' Adds ADML "string" elements to the string-table that are referenced by | 137 ''' Adds ADML "string" elements to the string-table that are referenced by |
138 the ADMX file but not related to any specific Policy-Group or Policy. | 138 the ADMX file but not related to any specific Policy-Group or Policy. |
139 ''' | 139 ''' |
140 self._AddString(self.config['win_supported_os'], | 140 self._AddString(self.config['win_supported_os'], |
141 self.messages['win_supported_winxpsp2']['text']) | 141 self.messages['win_supported_winxpsp2']['text']) |
142 categories = self.config['win_mandatory_category_path'] + \ | 142 categories = self.winconfig['mandatory_category_path'] + \ |
143 self.config['win_recommended_category_path'] | 143 self.winconfig['recommended_category_path'] |
144 strings = self.config['win_category_path_strings'] | 144 strings = self.winconfig['category_path_strings'] |
145 for category in categories: | 145 for category in categories: |
146 if (category in strings): | 146 if (category in strings): |
147 # Replace {...} by localized messages. | 147 # Replace {...} by localized messages. |
148 string = re.sub(r"\{(\w+)\}", \ | 148 string = re.sub(r"\{(\w+)\}", \ |
149 lambda m: self.messages[m.group(1)]['text'], \ | 149 lambda m: self.messages[m.group(1)]['text'], \ |
150 strings[category]) | 150 strings[category]) |
151 self._AddString(category, string) | 151 self._AddString(category, string) |
152 | 152 |
153 def BeginTemplate(self): | 153 def BeginTemplate(self): |
154 dom_impl = minidom.getDOMImplementation('') | 154 dom_impl = minidom.getDOMImplementation('') |
(...skipping 11 matching lines...) Expand all Loading... |
166 resources_elem = self.AddElement(policy_definitions_resources_elem, | 166 resources_elem = self.AddElement(policy_definitions_resources_elem, |
167 'resources') | 167 'resources') |
168 self._string_table_elem = self.AddElement(resources_elem, 'stringTable') | 168 self._string_table_elem = self.AddElement(resources_elem, 'stringTable') |
169 self._AddBaseStrings() | 169 self._AddBaseStrings() |
170 self._presentation_table_elem = self.AddElement(resources_elem, | 170 self._presentation_table_elem = self.AddElement(resources_elem, |
171 'presentationTable') | 171 'presentationTable') |
172 | 172 |
173 def Init(self): | 173 def Init(self): |
174 # Map of all strings seen. | 174 # Map of all strings seen. |
175 self.strings_seen = {} | 175 self.strings_seen = {} |
| 176 # Shortcut to platform-specific ADMX/ADM specific configuration. |
| 177 assert len(self.platforms) == 1 |
| 178 self.winconfig = self.config['win_config'][self.platforms[0]] |
176 | 179 |
177 def GetTemplateText(self): | 180 def GetTemplateText(self): |
178 # Using "toprettyxml()" confuses the Windows Group Policy Editor | 181 # Using "toprettyxml()" confuses the Windows Group Policy Editor |
179 # (gpedit.msc) because it interprets whitespace characters in text between | 182 # (gpedit.msc) because it interprets whitespace characters in text between |
180 # the "string" tags. This prevents gpedit.msc from displaying the category | 183 # the "string" tags. This prevents gpedit.msc from displaying the category |
181 # names correctly. | 184 # names correctly. |
182 # TODO(markusheintz): Find a better formatting that works with gpedit. | 185 # TODO(markusheintz): Find a better formatting that works with gpedit. |
183 return self._doc.toxml() | 186 return self._doc.toxml() |
OLD | NEW |