summaryrefslogtreecommitdiffstats
path: root/tools/grit
diff options
context:
space:
mode:
authormarkusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-30 14:32:01 +0000
committermarkusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-30 14:32:01 +0000
commit446c9df29b0dc6527ec490c13c207bc3bd94d469 (patch)
tree249c673bf1d36aca55a7df40a7d5d2fedde14b2e /tools/grit
parent0138b4a799f9a40992c6f8ea5a43bf40f8a620f0 (diff)
downloadchromium_src-446c9df29b0dc6527ec490c13c207bc3bd94d469.zip
chromium_src-446c9df29b0dc6527ec490c13c207bc3bd94d469.tar.gz
chromium_src-446c9df29b0dc6527ec490c13c207bc3bd94d469.tar.bz2
ADMX/ADML Writer to generate ADMX/ADMl templates.
BUG=53315 TEST=manual Review URL: http://codereview.chromium.org/3162030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57858 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/grit')
-rw-r--r--tools/grit/grit/format/policy_templates/writers/adml_writer.py260
-rw-r--r--tools/grit/grit/format/policy_templates/writers/admx_writer.py421
-rw-r--r--tools/grit/grit/node/misc.py2
3 files changed, 682 insertions, 1 deletions
diff --git a/tools/grit/grit/format/policy_templates/writers/adml_writer.py b/tools/grit/grit/format/policy_templates/writers/adml_writer.py
new file mode 100644
index 0000000..2c74bdf
--- /dev/null
+++ b/tools/grit/grit/format/policy_templates/writers/adml_writer.py
@@ -0,0 +1,260 @@
+# Copyright (c) 2010 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from xml.dom import minidom
+from grit.format.policy_templates.writers import xml_formatted_writer
+
+
+def GetWriter(info, messages):
+ '''Factory method for instanciating the ADMLWriter. Every Writer needs a
+ GetWriter method because the TemplateFormatter uses this method to
+ instantiate a Writer.
+ '''
+ return ADMLWriter(info, messages)
+
+
+class ADMLWriter(xml_formatted_writer.XMLFormattedWriter):
+ ''' Class for generating an ADML policy template. It is used by the
+ PolicyTemplateGenerator to write the ADML file.
+ '''
+
+ # DOM root node of the generated ADML document.
+ _doc = None
+
+ # The string-table contains all ADML "string" elements.
+ _string_table_elem = None
+
+ # The presentation-table is the container for presentation elements, that
+ # describe the presentation of Policy-Groups and Policies.
+ _presentation_table_elem = None
+
+ # The active Policy-Group. At any given point in time this contains the
+ # Policy-Group that is processed.
+ _active_policy_group = None
+
+ # The active ADML "presentation" element. At any given point in time this
+ # contains the "presentation" element for the Policy-Group that is processed.
+ _active_presentation_elem = None
+
+
+ def _AddString(self, parent, id, text):
+ ''' Adds an ADML "string" element to the passed parent. The following
+ ADML snippet contains an example:
+
+ <string id="$(id)">$(text)</string>
+
+ Args:
+ parent: Parent element to which the new "string" element is added.
+ id: ID of the newly created "string" element.
+ text: Value of the newly created "string" element.
+ '''
+ string_elem = self.AddElement(parent, 'string', {'id': id})
+ string_elem.appendChild(self._doc.createTextNode(text))
+
+ def _AddStringPolicy(self, presentation_elem, policy_name, caption):
+ '''Generates ADML elements for a String-Policy. A String-Policy does not
+ require any ADML "string" elements. The presentation of a String-Policy is
+ defined by an ADML "textBox" element. The text-box contains an ADML "label"
+ element that contains the text of the text-box label. The following ADML
+ snipped shows an example:
+
+ <presentation ...>
+ ...
+ <textBox refId="$(policy_name)">
+ <label>$(caption)</label>
+ </textBox>
+ </presentation>
+
+ Args:
+ presentation_elem: The ADML "presentation" element of the policy group
+ that includes the policy.
+ policy_name: Policy name.
+ caption: Caption assisiated with the Policy.
+ '''
+ # A String-Policy requires no additional ADML "string" elements.
+
+ # Add ADML "presentation" elements that are required by a String-Policy to
+ # the presentation-table.
+ textbox_elem = self.AddElement(presentation_elem, 'textBox',
+ {'refId': policy_name})
+ label_elem = self.AddElement(textbox_elem, 'label')
+ label_elem.appendChild(self._doc.createTextNode(caption))
+
+ def _AddEnumPolicy(self, string_table_elem, presentation_elem,
+ policy_name, caption, items):
+ '''Generates ADML elements for an Enum-Policy. For each enum item an ADML
+ "string" element is added to the string-table. The presentation of an
+ Enum-Policy is defined by the ADML "dropdownList" element. The following
+ ADML snippet shows an example:
+
+ <stringTable>
+ ...
+ <string id="$(item_name)">$(description)</string>
+ </stringTable>
+
+ <presentation ...>
+ ...
+ <dropdownList refId="$(policy_name)">$(caption)</dropdownlist>
+ </presentation>
+
+ Args:
+ string_table_elem: The ADML "stringTable" element to which the ADML
+ "string" elements are added.
+ presentation_elem: The ADML "presentation" element of the policy group
+ that includes the policy.
+ policy_name: Policy name.
+ caption: Caption associated with the Policy.
+ items: The enum items.
+ '''
+ # Add ADML "string" elements to the string-table that are required by an
+ # Enum-Policy.
+ for item in items:
+ self._AddString(string_table_elem, item['name'], item['caption'])
+
+ # Add ADML "presentation" elements to the presentation-table that are
+ # required by an Enum-Policy.
+ dropdownlist_elem = self.AddElement(presentation_elem, 'dropdownList',
+ {'refId': policy_name})
+ dropdownlist_elem.appendChild(self._doc.createTextNode(caption))
+
+ def _AddListPolicy(self, string_table_elem, presentation_elem, policy_name,
+ caption):
+ '''Generates ADML elements for a List-Policy. Each List-Policy requires an
+ additional ADML "string" element that contains a description of the items
+ that can be added to the list. The presentation of a List-Policy is defined
+ by an ADML "listBox" element. The following ADML snippet shows an example:
+
+ <stringTable>
+ ...
+ <string id="$(policy_name)Desc">$(caption)</string>
+ </stringTable>
+
+ <presentation ...>
+ ...
+ <listBox refId="$(policy_name)Desc">$(caption)</listBox>
+ </presentation>
+
+ Args:
+ string_table_elem: The ADML "stringTable" element to which the ADML
+ "string" elements are added.
+ presentation_elem: The ADML "presentation" element of the policy group
+ that includes the policy.
+ policy_name: Policy name.
+ caption: Caption assisiated with the Policy.
+ '''
+ # Add ADML "string" elements to the string-table that are required by a
+ # List-Policy.
+ self._AddString(string_table_elem, policy_name + 'Desc', caption)
+
+ # Add ADML "presentation" elements to the presentation-table that are
+ # required by a List-Policy.
+ listbox_elem = self.AddElement(presentation_elem, 'listBox',
+ {'refId': policy_name + 'Desc'})
+ listbox_elem.appendChild(self._doc.createTextNode(caption))
+
+ def WritePolicy(self, policy):
+ '''Generates the ADML elements for a Policy.
+
+ Args:
+ policy: The Policy to generate ADML elements for.
+ '''
+ policy_type = policy['type']
+ policy_name = policy['name']
+ presentation_elem = self._active_presentation_elem
+ string_table_elem = self._string_table_elem
+ if policy_type == 'main':
+ # Nothing needs to be done for a Main-Policy.
+ pass
+ elif policy_type == 'string':
+ self._AddStringPolicy(presentation_elem, policy_name, policy['caption'])
+ elif policy_type == 'enum':
+ self._AddEnumPolicy(string_table_elem, presentation_elem, policy_name,
+ policy['caption'], policy['items'])
+ elif policy_type == 'list':
+ self._AddListPolicy(string_table_elem, presentation_elem, policy_name,
+ policy['caption'])
+ else:
+ raise Exception('Unknown policy type %s.' % policy_type)
+
+ def BeginPolicyGroup(self, group):
+ '''Generates ADML elements for a Policy-Group. For each Policy-Group two
+ ADML "string" elements are added to the string-table. One contains the
+ caption of the Policy-Group and the other a description. A Policy-Group also
+ requires an ADML "presentation" element that must be added to the
+ presentation-table. The "presentation" element is the container for the
+ elements that define the visual presentation of the Policy-Goup's Policies.
+ The following ADML snippet shows an example:
+
+ <stringTable>
+ ...
+ <string id="$(policy_group_name)">$(caption)</string>
+ <string id="$(policy_group_name)_Explain">$(description)</string>
+ </stringTable>
+
+ <presentationTables>
+ ...
+ <presentation id=$(policy_group_name)/>
+ </presentationTables>
+
+ Args:
+ group: The Policy-Group to generate ADML elements for.
+ '''
+ self._active_policy_group = group
+
+ # Add ADML "string" elements to the string-table that are required by a
+ # Policy-Group.
+ id = group['name']
+ self._AddString(self._string_table_elem, id, group['caption'])
+ self._AddString(self._string_table_elem, id + '_Explain', group['desc'])
+
+ # Add ADML "presentation" elements to the presentation-table that are
+ # required by a Policy-Group.
+ self._active_presentation_elem = self.AddElement(
+ self._presentation_table_elem, 'presentation', {'id': id})
+
+ def EndPolicyGroup(self):
+ pass
+
+ def _AddBaseStrings(self, string_table_elem, build):
+ ''' Adds ADML "string" elements to the string-table that are referenced by
+ the ADMX file but not related to any specific Policy-Group or Policy.
+ '''
+ self._AddString(string_table_elem, 'SUPPORTED_WINXPSP2',
+ self.messages['IDS_POLICY_WIN_SUPPORTED_WINXPSP2'])
+ if build == 'chrome':
+ self._AddString(string_table_elem, 'google', 'Google')
+ self._AddString(string_table_elem, 'googlechrome', 'Google Chrome')
+ elif build == 'chromium':
+ self._AddString(string_table_elem, 'chromium', 'Chromium')
+
+ def BeginTemplate(self):
+ dom_impl = minidom.getDOMImplementation('')
+ self._doc = dom_impl.createDocument(None, 'policyDefinitionResources',
+ None)
+ policy_definitions_resources_elem = self._doc.documentElement
+ policy_definitions_resources_elem.attributes['revision'] = '1.0'
+ policy_definitions_resources_elem.attributes['schemaVersion'] = '1.0'
+
+ self.AddElement(policy_definitions_resources_elem, 'displayName')
+ self.AddElement(policy_definitions_resources_elem, 'description')
+ resources_elem = self.AddElement(policy_definitions_resources_elem,
+ 'resources')
+ self._string_table_elem = self.AddElement(resources_elem, 'stringTable')
+ self._AddBaseStrings(self._string_table_elem, self.info['build'])
+ self._presentation_table_elem = self.AddElement(resources_elem,
+ 'presentationTable')
+
+ def EndTemplate(self):
+ pass
+
+ def Prepare(self):
+ pass
+
+ def GetTemplateText(self):
+ # Using "toprettyxml()" confuses the Windows Group Policy Editor
+ # (gpedit.msc) because it interprets whitespace characters in text between
+ # the "string" tags. This prevents gpedit.msc from displaying the category
+ # names correctly.
+ # TODO(markusheintz): Find a better formatting that works with gpedit.
+ return self._doc.toxml()
diff --git a/tools/grit/grit/format/policy_templates/writers/admx_writer.py b/tools/grit/grit/format/policy_templates/writers/admx_writer.py
new file mode 100644
index 0000000..2d8fd64
--- /dev/null
+++ b/tools/grit/grit/format/policy_templates/writers/admx_writer.py
@@ -0,0 +1,421 @@
+# Copyright (c) 2010 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from xml.dom import minidom
+from grit.format.policy_templates.writers import xml_formatted_writer
+
+
+def GetWriter(info, messages):
+ '''Factory method for instanciating the ADMXWriter. Every Writer needs a
+ GetWriter method because the TemplateFormatter uses this method to
+ instantiate a Writer.
+ '''
+ return ADMXWriter(info, messages)
+
+
+class ADMXWriter(xml_formatted_writer.XMLFormattedWriter):
+ '''Class for generating an ADMX policy template. It is used by the
+ PolicyTemplateGenerator to write the admx file.
+ '''
+
+ # The configuration dict contains build (chrome, chromium) specific
+ # information, that is needed for the generation of the ADMX template.
+ _configuration = None
+
+ # DOM root node of the generated ADMX document.
+ _doc = None
+
+ # The ADMX "policies" element that contains the ADMX "policy" elements that
+ # are generated.
+ _active_policies_elem = None
+
+ # The active ADMX "policy" element. At any point in time, the active policy
+ # element contains the element being generated for the Policy-Group currently
+ # being processed.
+ _active_policy_elem = None
+
+ def _GetConfigurationForBuild(self, build):
+ '''Returns a configuration dictionary for the given build that contains
+ build-specific settings and information.
+
+ Args:
+ build: The build type ('chrome' or 'chromium')
+
+ Raises:
+ Exception: Build contains an unknown build-type.
+ '''
+ if build == 'chromium':
+ return {
+ 'CATEGORY_PATH': 'chromium',
+ 'SUPPORTED_OS': 'SUPPORTED_WINXPSP2',
+ 'REGISTRY_KEY': 'Software\Policies\Chromium',
+ 'GROUP_POLICY_CLASS': 'Machine',
+ 'ADMX_NAMESPACE': 'Chromium.Policies.Chromium',
+ 'ADMX_PREFIX': 'chromium',
+ }
+ elif build == 'chrome':
+ return {
+ 'CATEGORY_PATH': 'google/googlechrome',
+ 'SUPPORTED_OS': 'SUPPORTED_WINXPSP2',
+ 'REGISTRY_KEY': 'Software\Policies\Google\Chrome',
+ 'GROUP_POLICY_CLASS': 'Machine',
+ 'ADMX_NAMESPACE': 'Google.Policies.Chrome',
+ 'ADMX_PREFIX': 'chrome',
+ }
+ else:
+ raise Exception('Unknown build type %s.' % build)
+
+ def _AdmlString(self, name):
+ '''Creates a reference to the named string in an ADML file.
+ Args:
+ name: Name of the referenced ADML string.
+ '''
+ return '$(string.' + name + ')'
+
+ def _AdmlStringExplain(self, name):
+ '''Creates a reference to the named explanation string in an ADML file.
+ Args:
+ name: Name of the referenced ADML explanation.
+ '''
+ return '$(string.' + name + '_Explain)'
+
+ def _AdmlPresentation(self, name):
+ '''Creates a reference to the named presentation element in an ADML file.
+ Args:
+ name: Name of the referenced ADML presentation element.
+ '''
+ return '$(presentation.' + name + ')'
+
+ def _AddPolicyNamespaces(self, parent, prefix, namespace):
+ '''Generates the ADMX "policyNamespace" element and adds the elements to the
+ passed parent element. The namespace of the generated ADMX document is
+ define via the ADMX "target" element. Used namespaces are declared with an
+ ADMX "using" element. ADMX "target" and "using" elements are children of the
+ ADMX "policyNamespace" element.
+
+ Args:
+ parent: The parent node to which all generated elements are added.
+ prefix: A logical name that can be used in the generated ADMX document to
+ refere to this namespace.
+ namespace: Namespace of the generated ADMX document.
+ '''
+ policy_namespaces_elem = self.AddElement(parent, 'policyNamespaces')
+ attributes = {
+ 'prefix': prefix,
+ 'namespace': namespace,
+ }
+ self.AddElement(policy_namespaces_elem, 'target', attributes)
+ attributes = {
+ 'prefix': 'windows',
+ 'namespace': 'Microsoft.Policies.Windows',
+ }
+ self.AddElement(policy_namespaces_elem, 'using', attributes)
+
+ def _AddCategory(self, parent, name, display_name,
+ parent_category_name=None):
+ '''Adds an ADMX category element to the passed parent node. The following
+ snippet shows an example of a category element where "chromium" is the value
+ of the parameter name:
+
+ <category displayName="$(string.chromium)" name="chromium"/>
+
+ Args:
+ parent: The parent node to which all generated elements are added.
+ name: Name of the category.
+ display_name: Display name of the category.
+ parent_category_name: Name of the parent category. Defaults to None.
+ '''
+ attributes = {
+ 'name': name,
+ 'displayName': display_name,
+ }
+ category_elem = self.AddElement(parent, 'category', attributes)
+ if parent_category_name:
+ attributes = {'ref': parent_category_name}
+ self.AddElement(category_elem, 'parentCategory', attributes)
+
+ def _AddCategories(self, parent, categories_path):
+ '''Generates the ADMX "categories" element and adds it to the passed parent
+ node. The "categories" element defines the category for the policies defined
+ in this ADMX document. Here is an example of an ADMX "categories" element:
+
+ <categories>
+ <category displayName="$(string.google)" name="google"/>
+ <category displayName="$(string.googlechrome)" name="googlechrome">
+ <parentCategory ref="google"/>
+ </category>
+ </categories>
+
+ Args:
+ parent: The parent node to which all generated elements are added.
+ categories_path: The categories path e.g. google/googlechrome. For each
+ level in the path a "category" element will be generated. Except for
+ the root level, each level refers to its parent. Since the root level
+ category has no parent it does not require a parent reference.
+ '''
+ categories_elem = self.AddElement(parent, 'categories')
+ categories = categories_path.split('/')
+ category_name = None
+ for category in categories:
+ parent_category_name = category_name
+ category_name = category
+ self._AddCategory(categories_elem, category_name,
+ self._AdmlString(category_name), parent_category_name)
+
+ def _AddSupportedOn(self, parent, supported_os):
+ '''Generates the "supportedOn" ADMX element and adds it to the passed
+ parent node. The "supportedOn" element contains information about supported
+ Windows OS versions. The following code snippet contains an example of a
+ "supportedOn" element:
+
+ <supportedOn>
+ <definitions>
+ <definition name="SUPPORTED_WINXPSP2"
+ displayName="$(string.SUPPORTED_WINXPSP2)"/>
+ </definitions>
+ ...
+ </supportedOn>
+
+ Args:
+ parent: The parent element to which all generated elements are added.
+ supported_os: List with all supported Win OSes.
+ '''
+ supported_on_elem = self.AddElement(parent, 'supportedOn')
+ definitions_elem = self.AddElement(supported_on_elem, 'definitions')
+ attributes = {
+ 'name': supported_os,
+ 'displayName': self._AdmlString(supported_os)
+ }
+ self.AddElement(definitions_elem, 'definition', attributes)
+
+ def _AddStringPolicy(self, parent, name):
+ '''Generates ADMX elements for a String-Policy and adds them to the
+ passed parent node. A String-Policy is mapped to an ADMX "text" element.
+ The parent of the ADMX "text" element must be an ADMX "elements" element,
+ which must by a child of the ADMX "policy" element that corresponds to the
+ Policy-Group that contains the String-Policy. The following example shows
+ how the JSON specification of the String-Policy "DisabledPluginsList" of the
+ Policy-Group "DisabledPlugins" is mapped to ADMX:
+
+ {
+ 'name': 'DisabledPlugins',
+ 'policies': [{
+ 'name': 'DisabledPluginsList',
+ 'type' : 'string',
+ }, ... ]
+ }
+
+ <policy ... name="DisabledPlugins" ...>
+ ...
+ <elements>
+ <text id="DisabledPluginsList" valueName="DisabledPluginsList"/>
+ ...
+ </elements>
+ </policy>
+
+ '''
+ attributes = {
+ 'id': name,
+ 'valueName': name,
+ }
+ self.AddElement(parent, 'text', attributes)
+
+ def _AddEnumPolicy(self, parent, name, items):
+ '''Generates ADMX elements for an Enum-Policy and adds them to the
+ passed parent element. An Enum-Policy is mapped to an ADMX "enum" element.
+ The parent of the "enum" element must be the ADMX "elements" element of the
+ ADMX "policy" element that corresponds to the Policy-Group that contains the
+ Enum-Policy. The following example shows how the JSON specification of the
+ Enum-Policy "ProxyServerMode" of the Policy-Group "Proxy" is mapped to ADMX:
+
+ {
+ 'name': 'Proxy',
+ 'policies': [{
+ 'name': 'ProxyServerMode',
+ 'type': 'enum',
+ 'items': [
+ {'name': 'ProxyServerDisabled', 'value': '0'},
+ {'name': 'ProxyServerAutoDetect', 'value': '1'},
+ ...
+ ],
+ }, ... ]
+ }
+
+ <policy ... name="Proxy" ...>
+ ...
+ <elements>
+ <enum id="ProxyServerMode" valueName="ProxyServerMode">
+ <item displayName="$(string.ProxyServerDisabled)">
+ <value>
+ <decimal value="0"/>
+ </value>
+ </item>
+ <item displayName="$(string.ProxyServerAutoDetect)">
+ <value>
+ <decimal value="1"/>
+ </value>
+ </item>
+ ...
+ </enum>
+ ...
+ </elements>
+ </policy>
+ '''
+ attributes = {
+ 'id': name,
+ 'valueName': name,
+ }
+ enum_elem = self.AddElement(parent, 'enum', attributes)
+ for item in items:
+ attributes = {'displayName': self._AdmlString(item['name'])}
+ item_elem = self.AddElement(enum_elem, 'item', attributes)
+ value_elem = self.AddElement(item_elem, 'value')
+ attributes = {'value': str(item['value'])}
+ self.AddElement(value_elem, 'decimal', attributes)
+
+ def _AddListPolicy(self, parent, name):
+ '''Generates ADMX XML elements for a List-Policy and adds them to the
+ passed parent element. A List-Policy is mapped to an ADMX "list" element.
+ The parent of the "list" element must be the ADMX "elements" element of the
+ ADMX "policy" element that corresponds to the Policy-Group that contains the
+ List-Policy. The following example shows how the JSON specification of the
+ List-Policy "ExtensionInstallBlacklist" of the Policy-Group
+ "ExtensionInstallBlacklist" is mapped to ADMX:
+
+ {
+ 'name': 'ExtensionInstallBlacklist',
+ 'policies': [{
+ 'name': 'ExtensionInstallBlacklist',
+ 'type': 'list',
+ }]
+ },
+
+ <policy ... name="ExtensionInstallBlacklist" ...>
+ ...
+ <elements>
+ <list id="ExtensionInstallBlacklistDesc" valuePrefix=""/>
+ </elements>
+ </policy>
+ '''
+ attributes = {
+ # The ID must be in sync with ID of the corresponding element in the ADML
+ # file.
+ 'id': name + 'Desc',
+ 'valuePrefix': '',
+ 'key': self._configuration['REGISTRY_KEY'] + '\\' + name,
+ }
+ self.AddElement(parent, 'list', attributes)
+
+ def _AddMainPolicy(self, parent):
+ '''Generates ADMX elements for a Main-Policy amd adds them to the
+ passed parent element.
+ '''
+ enabled_value_elem = self.AddElement(parent, 'enabledValue');
+ self.AddElement(enabled_value_elem, 'decimal', {'value': '1'})
+ disabled_value_elem = self.AddElement(parent, 'disabledValue');
+ self.AddElement(disabled_value_elem, 'decimal', {'value': '0'})
+
+ def _GetElements(self, policy_group_elem):
+ '''Returns the ADMX "elements" child from an ADMX "policy" element. If the
+ "policy" element has no "elements" child yet, a new child is created.
+
+ Args:
+ policy_group_elem: The ADMX "policy" element from which the child element
+ "elements" is returned.
+
+ Raises:
+ Exception: The policy_group_elem does not contain a ADMX "policy" element.
+ '''
+ if policy_group_elem.tagName != 'policy':
+ raise Exception('Expected a "policy" element but got a "%s" element'
+ % policy_group_elem.tagName)
+ elements_list = policy_group_elem.getElementsByTagName('elements');
+ if len(elements_list) == 0:
+ return self.AddElement(policy_group_elem, 'elements')
+ elif len(elements_list) == 1:
+ return elements_list[0]
+ else:
+ raise Exception('There is supposed to be only one "elements" node but'
+ ' there are %s.' % str(len(elements_list)))
+
+ def WritePolicy(self, policy):
+ '''Generates AMDX elements for a Policy. There are four different policy
+ types: Main-Policy, String-Policy, Enum-Policy and List-Policy.
+ '''
+ policy_type = policy['type']
+ policy_name = policy['name']
+ if policy_type == 'main':
+ self._AddMainPolicy(self._active_policy_elem)
+ elif policy_type == 'string':
+ parent = self._GetElements(self._active_policy_elem)
+ self._AddStringPolicy(parent, policy_name)
+ elif policy_type == 'enum':
+ parent = self._GetElements(self._active_policy_elem)
+ self._AddEnumPolicy(parent, policy_name, policy['items'])
+ elif policy_type == 'list':
+ parent = self._GetElements(self._active_policy_elem)
+ self._AddListPolicy(parent, policy_name)
+ else:
+ raise Exception('Unknown policy type %s.' % policy_type)
+
+ def BeginPolicyGroup(self, group):
+ '''Generates ADMX elements for a Policy-Group and adds them to the ADMX
+ policies element. A Policy-Group is mapped to an ADMX "policy" element. All
+ ADMX policy elements are grouped under the ADMX "policies" element.
+ '''
+ policies_elem = self._active_policies_elem
+ policy_group_name = group['name']
+ attributes = {
+ 'name': policy_group_name,
+ 'class': self._configuration['GROUP_POLICY_CLASS'],
+ 'displayName': self._AdmlString(policy_group_name),
+ 'explainText': self._AdmlStringExplain(policy_group_name),
+ 'presentation': self._AdmlPresentation(policy_group_name),
+ 'key': self._configuration['REGISTRY_KEY'],
+ 'valueName': policy_group_name,
+ }
+ # Store the current "policy" AMDX element in self for later use by the
+ # WritePolicy method.
+ self._active_policy_elem = self.AddElement(policies_elem, 'policy',
+ attributes)
+ self.AddElement(self._active_policy_elem, 'parentCategory',
+ {'ref':self._configuration['CATEGORY_PATH'].split('/')[-1]})
+ self.AddElement(self._active_policy_elem, 'supportedOn',
+ {'ref': self._configuration['SUPPORTED_OS']})
+
+ def EndPolicyGroup(self):
+ return
+
+ def BeginTemplate(self):
+ '''Generates the skeleton of the ADMX template. An ADMX template contains
+ an ADMX "PolicyDefinitions" element with four child nodes: "policies"
+ "policyNamspaces", "resources", "supportedOn" and "categories"
+ '''
+ dom_impl = minidom.getDOMImplementation('')
+ self._doc = dom_impl.createDocument(None, 'policyDefinitions', None)
+ policy_definitions_elem = self._doc.documentElement
+
+ policy_definitions_elem.attributes['revision'] = '1.0'
+ policy_definitions_elem.attributes['schemaVersion'] = '1.0'
+
+ self._AddPolicyNamespaces(policy_definitions_elem,
+ self._configuration['ADMX_PREFIX'],
+ self._configuration['ADMX_NAMESPACE'])
+ self.AddElement(policy_definitions_elem, 'resources',
+ {'minRequiredRevision' : '1.0'})
+ self._AddSupportedOn(policy_definitions_elem,
+ self._configuration['SUPPORTED_OS'])
+ self._AddCategories(policy_definitions_elem,
+ self._configuration['CATEGORY_PATH'])
+ self._active_policies_elem = self.AddElement(policy_definitions_elem,
+ 'policies')
+
+ def EndTemplate(self):
+ pass
+
+ def Prepare(self):
+ self._configuration = self._GetConfigurationForBuild(self.info['build'])
+
+ def GetTemplateText(self):
+ return self._doc.toprettyxml(indent=' ')
diff --git a/tools/grit/grit/node/misc.py b/tools/grit/grit/node/misc.py
index 2ba2ff1..e93133c 100644
--- a/tools/grit/grit/node/misc.py
+++ b/tools/grit/grit/node/misc.py
@@ -250,7 +250,7 @@ class GritNode(base.Node):
elif t == 'js_map_format':
from grit.format import js_map_format
return js_map_format.TopLevel()
- elif t in ['adm', 'plist', 'plist_strings']:
+ elif t in ['adm', 'plist', 'plist_strings', 'admx', 'adml']:
from grit.format.policy_templates import template_formatter
return template_formatter.TemplateFormatter(t)
else: