summaryrefslogtreecommitdiffstats
path: root/tools/grit
diff options
context:
space:
mode:
authorgfeher@chromium.org <gfeher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-07 14:20:15 +0000
committergfeher@chromium.org <gfeher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-07 14:20:15 +0000
commitd58aec51b604b7aece0d0102871ef5532c93983b (patch)
tree3ec09ffb133f3267c03bb6a53195cbf6e6038670 /tools/grit
parent81e32608bbb2da6f58291981fee183b3da913081 (diff)
downloadchromium_src-d58aec51b604b7aece0d0102871ef5532c93983b.zip
chromium_src-d58aec51b604b7aece0d0102871ef5532c93983b.tar.gz
chromium_src-d58aec51b604b7aece0d0102871ef5532c93983b.tar.bz2
Fix Chrome ADM registry key and move template config strings to one place
Set the Chrome policy registry keyname to "Software\\Policies\\Google\\Chrome" for ADM output. Move all such constant strings to a common place for ADM, ADMX and plist output. (So that such bugs will be harder to overlook next time.) BUG=54630 TEST=manual + grit/format/policy_templates/writer/* Review URL: http://codereview.chromium.org/3299009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58696 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/grit')
-rw-r--r--tools/grit/grit/format/policy_templates/template_formatter.py39
-rw-r--r--tools/grit/grit/format/policy_templates/writer_configuration.py47
-rw-r--r--tools/grit/grit/format/policy_templates/writers/adm_writer.py36
-rw-r--r--tools/grit/grit/format/policy_templates/writers/adm_writer_unittest.py4
-rw-r--r--tools/grit/grit/format/policy_templates/writers/adml_writer.py15
-rw-r--r--tools/grit/grit/format/policy_templates/writers/admx_writer.py72
-rw-r--r--tools/grit/grit/format/policy_templates/writers/plist_strings_writer.py8
-rw-r--r--tools/grit/grit/format/policy_templates/writers/plist_writer.py9
-rw-r--r--tools/grit/grit/format/policy_templates/writers/template_writer.py10
9 files changed, 119 insertions, 121 deletions
diff --git a/tools/grit/grit/format/policy_templates/template_formatter.py b/tools/grit/grit/format/policy_templates/template_formatter.py
index fa479a5..354a5f8 100644
--- a/tools/grit/grit/format/policy_templates/template_formatter.py
+++ b/tools/grit/grit/format/policy_templates/template_formatter.py
@@ -3,14 +3,16 @@
# found in the LICENSE file.
+import os
+import sys
+import types
+
from grit.format import interface
+from grit.format.policy_templates import policy_template_generator
+from grit.format.policy_templates import writer_configuration
from grit.node import structure
from grit.node import message
from grit.node import misc
-from policy_template_generator import PolicyTemplateGenerator
-import types
-import os
-import sys
class TemplateFormatter(interface.ItemFormatter):
@@ -58,7 +60,7 @@ class TemplateFormatter(interface.ItemFormatter):
return ''
self._lang = lang
- self._GetFlags(item)
+ self._config = writer_configuration.GetConfigurationForBuild(item.defines)
self._policy_data = None
self._messages = {}
self._ParseGritNodes(item)
@@ -72,34 +74,13 @@ class TemplateFormatter(interface.ItemFormatter):
The text of the policy template based on the parameters passed
to __init__() and Format().
'''
- policy_generator = PolicyTemplateGenerator(
+ policy_generator = policy_template_generator.PolicyTemplateGenerator(
self._messages,
self._policy_data['policy_groups'])
- writer = self._writer_module.GetWriter(self._info, self._messages)
+ writer = self._writer_module.GetWriter(self._config, self._messages)
str = policy_generator.GetTemplateText(writer)
return str
- def _GetFlags(self, item):
- '''Sets values in self._info based on the -D flags
- passed to grit.
-
- Args:
- item: The <grit> root node of the grit tree.
- '''
- defines = item.defines
-
- self._info = {}
- if 'mac_bundle_id' in defines:
- self._info['mac_bundle_id'] = defines['mac_bundle_id']
- if '_chromium' in defines:
- self._info['app_name'] = 'Chromium'
- self._info['build'] = 'chromium'
- elif '_google_chrome' in defines:
- self._info['app_name'] = 'Google Chrome'
- self._info['build'] = 'chrome'
- else:
- raise Exception('Unknown build')
-
def _ImportMessage(self, message):
'''Takes a grit message node and adds its translated content to
self._messages.
@@ -111,7 +92,7 @@ class TemplateFormatter(interface.ItemFormatter):
# Get translation of message.
msg_txt = message.Translate(self._lang)
# Replace the placeholder of app name.
- msg_txt = msg_txt.replace('$1', self._info['app_name'])
+ msg_txt = msg_txt.replace('$1', self._config['app_name'])
# Replace other placeholders.
for placeholder in self._policy_data['placeholders']:
msg_txt = msg_txt.replace(placeholder['key'], placeholder['value'])
diff --git a/tools/grit/grit/format/policy_templates/writer_configuration.py b/tools/grit/grit/format/policy_templates/writer_configuration.py
new file mode 100644
index 0000000..fc1a821
--- /dev/null
+++ b/tools/grit/grit/format/policy_templates/writer_configuration.py
@@ -0,0 +1,47 @@
+# 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.
+
+
+def GetConfigurationForBuild(defines):
+ '''Returns a configuration dictionary for the given build that contains
+ build-specific settings and information.
+
+ Args:
+ defines: Definitions coming from the build system.
+
+ Raises:
+ Exception: If 'defines' contains an unknown build-type.
+ '''
+ # The prefix of key names in config determines which writer will use their
+ # corresponding values:
+ # win: Both ADM and ADMX.
+ # mac: Only plist.
+ # admx: Only ADMX.
+ # none/other: Used by all the writers.
+ if '_chromium' in defines:
+ config = {
+ 'build': 'chromium',
+ 'app_name': 'Chromium',
+ 'win_reg_key_name': 'Software\\Policies\\Chromium',
+ 'win_category_path': ['chromium'],
+ 'admx_namespace': 'Chromium.Policies.Chromium',
+ 'admx_prefix': 'chromium',
+ }
+ elif '_google_chrome' in defines:
+ config = {
+ 'build': 'chrome',
+ 'app_name': 'Google Chrome',
+ 'win_reg_key_name': 'Software\\Policies\\Google\\Chrome',
+ 'win_category_path': ['google', 'googlechrome'],
+ 'admx_namespace': 'Google.Policies.Chrome',
+ 'admx_prefix': 'chrome',
+ }
+ else:
+ raise Exception('Unknown build')
+ config['win_group_policy_class'] = 'Machine'
+ config['win_supported_os'] = 'SUPPORTED_WINXPSP2'
+ config['win_supported_os_msg'] = 'IDS_POLICY_WIN_SUPPORTED_WINXPSP2'
+ if 'mac_bundle_id' in defines:
+ config['mac_bundle_id'] = defines['mac_bundle_id']
+ return config
diff --git a/tools/grit/grit/format/policy_templates/writers/adm_writer.py b/tools/grit/grit/format/policy_templates/writers/adm_writer.py
index 3e094a1..68987fb 100644
--- a/tools/grit/grit/format/policy_templates/writers/adm_writer.py
+++ b/tools/grit/grit/format/policy_templates/writers/adm_writer.py
@@ -75,7 +75,8 @@ class AdmWriter(template_writer.TemplateWriter):
if policy_type == 'list':
# Note that the following line causes FullArmor ADMX Migrator to create
# corrupt ADMX files. Please use admx_writer to get ADMX files.
- self._PrintLine('KEYNAME "%s\\%s"' % (self._key_name, policy_name))
+ self._PrintLine('KEYNAME "%s\\%s"' %
+ (self.config['win_reg_key_name'], policy_name))
self._PrintLine('VALUEPREFIX ""')
else:
self._PrintLine('VALUENAME "%s"' % policy_name)
@@ -102,28 +103,29 @@ class AdmWriter(template_writer.TemplateWriter):
self._PrintLine()
def BeginTemplate(self):
- self._AddGuiString('SUPPORTED_WINXPSP2',
- self.messages['IDS_POLICY_WIN_SUPPORTED_WINXPSP2'])
- self._PrintLine('CLASS MACHINE', 1)
- if self.info['build'] == 'chrome':
- self._AddGuiString('google', 'Google')
- self._AddGuiString('googlechrome', 'Google Chrome')
- self._PrintLine('CATEGORY !!google', 1)
- self._PrintLine('CATEGORY !!googlechrome', 1)
- self._key_name = 'Software\\Policies\\Google\\Google Chrome'
- elif self.info['build'] == 'chromium':
- self._AddGuiString('chromium', 'Chromium')
- self._PrintLine('CATEGORY !!chromium', 1)
- self._key_name = 'Software\\Policies\\Chromium'
- self._PrintLine('KEYNAME "%s"' % self._key_name)
+ category_path = self.config['win_category_path']
+ self._AddGuiString(self.config['win_supported_os'],
+ self.messages[self.config['win_supported_os_msg']])
+ self._PrintLine(
+ 'CLASS ' + self.config['win_group_policy_class'].upper(),
+ 1)
+ if self.config['build'] == 'chrome':
+ self._AddGuiString(category_path[0], 'Google')
+ self._AddGuiString(category_path[1], self.config['app_name'])
+ self._PrintLine('CATEGORY !!' + category_path[0], 1)
+ self._PrintLine('CATEGORY !!' + category_path[1], 1)
+ elif self.config['build'] == 'chromium':
+ self._AddGuiString(category_path[0], self.config['app_name'])
+ self._PrintLine('CATEGORY !!' + category_path[0], 1)
+ self._PrintLine('KEYNAME "%s"' % self.config['win_reg_key_name'])
self._PrintLine()
def EndTemplate(self):
- if self.info['build'] == 'chrome':
+ if self.config['build'] == 'chrome':
self._PrintLine('END CATEGORY', -1)
self._PrintLine('END CATEGORY', -1)
self._PrintLine('', -1)
- elif self.info['build'] == 'chromium':
+ elif self.config['build'] == 'chromium':
self._PrintLine('END CATEGORY', -1)
self._PrintLine('', -1)
diff --git a/tools/grit/grit/format/policy_templates/writers/adm_writer_unittest.py b/tools/grit/grit/format/policy_templates/writers/adm_writer_unittest.py
index ed2b684..ec47e33 100644
--- a/tools/grit/grit/format/policy_templates/writers/adm_writer_unittest.py
+++ b/tools/grit/grit/format/policy_templates/writers/adm_writer_unittest.py
@@ -86,7 +86,7 @@ chromium="Chromium"'''
expected_output = '''CLASS MACHINE
CATEGORY !!google
CATEGORY !!googlechrome
- KEYNAME "Software\\Policies\\Google\\Google Chrome"
+ KEYNAME "Software\\Policies\\Google\\Chrome"
POLICY !!MainGroup_Policy
#if version >= 4
@@ -192,7 +192,7 @@ StringPolicy_Part="Caption of policy."
expected_output = '''CLASS MACHINE
CATEGORY !!google
CATEGORY !!googlechrome
- KEYNAME "Software\\Policies\\Google\\Google Chrome"
+ KEYNAME "Software\\Policies\\Google\\Chrome"
POLICY !!EnumGroup_Policy
#if version >= 4
diff --git a/tools/grit/grit/format/policy_templates/writers/adml_writer.py b/tools/grit/grit/format/policy_templates/writers/adml_writer.py
index 2c74bdf..fa40104 100644
--- a/tools/grit/grit/format/policy_templates/writers/adml_writer.py
+++ b/tools/grit/grit/format/policy_templates/writers/adml_writer.py
@@ -220,13 +220,16 @@ class ADMLWriter(xml_formatted_writer.XMLFormattedWriter):
''' 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'])
+ self._AddString(string_table_elem, self.config['win_supported_os'],
+ self.messages[self.config['win_supported_os_msg']])
if build == 'chrome':
- self._AddString(string_table_elem, 'google', 'Google')
- self._AddString(string_table_elem, 'googlechrome', 'Google Chrome')
+ self._AddString(string_table_elem, self.config['win_category_path'][0],
+ 'Google')
+ self._AddString(string_table_elem, self.config['win_category_path'][1],
+ self.config['app_name'])
elif build == 'chromium':
- self._AddString(string_table_elem, 'chromium', 'Chromium')
+ self._AddString(string_table_elem, self.config['win_category_path'][0],
+ self.config['app_name'])
def BeginTemplate(self):
dom_impl = minidom.getDOMImplementation('')
@@ -241,7 +244,7 @@ class ADMLWriter(xml_formatted_writer.XMLFormattedWriter):
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._AddBaseStrings(self._string_table_elem, self.config['build'])
self._presentation_table_elem = self.AddElement(resources_elem,
'presentationTable')
diff --git a/tools/grit/grit/format/policy_templates/writers/admx_writer.py b/tools/grit/grit/format/policy_templates/writers/admx_writer.py
index 2d8fd64..5eb67ca 100644
--- a/tools/grit/grit/format/policy_templates/writers/admx_writer.py
+++ b/tools/grit/grit/format/policy_templates/writers/admx_writer.py
@@ -6,12 +6,12 @@ from xml.dom import minidom
from grit.format.policy_templates.writers import xml_formatted_writer
-def GetWriter(info, messages):
+def GetWriter(config, 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)
+ return ADMXWriter(config, messages)
class ADMXWriter(xml_formatted_writer.XMLFormattedWriter):
@@ -19,10 +19,6 @@ class ADMXWriter(xml_formatted_writer.XMLFormattedWriter):
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
@@ -35,37 +31,6 @@ class ADMXWriter(xml_formatted_writer.XMLFormattedWriter):
# 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:
@@ -135,7 +100,7 @@ class ADMXWriter(xml_formatted_writer.XMLFormattedWriter):
attributes = {'ref': parent_category_name}
self.AddElement(category_elem, 'parentCategory', attributes)
- def _AddCategories(self, parent, categories_path):
+ def _AddCategories(self, parent, categories):
'''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:
@@ -143,19 +108,18 @@ class ADMXWriter(xml_formatted_writer.XMLFormattedWriter):
<categories>
<category displayName="$(string.google)" name="google"/>
<category displayName="$(string.googlechrome)" name="googlechrome">
- <parentCategory ref="google"/>
+ <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_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
@@ -303,7 +267,7 @@ class ADMXWriter(xml_formatted_writer.XMLFormattedWriter):
# file.
'id': name + 'Desc',
'valuePrefix': '',
- 'key': self._configuration['REGISTRY_KEY'] + '\\' + name,
+ 'key': self.config['win_reg_key_name'] + '\\' + name,
}
self.AddElement(parent, 'list', attributes)
@@ -368,11 +332,11 @@ class ADMXWriter(xml_formatted_writer.XMLFormattedWriter):
policy_group_name = group['name']
attributes = {
'name': policy_group_name,
- 'class': self._configuration['GROUP_POLICY_CLASS'],
+ 'class': self.config['win_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'],
+ 'key': self.config['win_reg_key_name'],
'valueName': policy_group_name,
}
# Store the current "policy" AMDX element in self for later use by the
@@ -380,9 +344,9 @@ class ADMXWriter(xml_formatted_writer.XMLFormattedWriter):
self._active_policy_elem = self.AddElement(policies_elem, 'policy',
attributes)
self.AddElement(self._active_policy_elem, 'parentCategory',
- {'ref':self._configuration['CATEGORY_PATH'].split('/')[-1]})
+ {'ref': self.config['win_category_path'][-1]})
self.AddElement(self._active_policy_elem, 'supportedOn',
- {'ref': self._configuration['SUPPORTED_OS']})
+ {'ref': self.config['win_supported_os']})
def EndPolicyGroup(self):
return
@@ -400,14 +364,14 @@ class ADMXWriter(xml_formatted_writer.XMLFormattedWriter):
policy_definitions_elem.attributes['schemaVersion'] = '1.0'
self._AddPolicyNamespaces(policy_definitions_elem,
- self._configuration['ADMX_PREFIX'],
- self._configuration['ADMX_NAMESPACE'])
+ self.config['admx_prefix'],
+ self.config['admx_namespace'])
self.AddElement(policy_definitions_elem, 'resources',
{'minRequiredRevision' : '1.0'})
self._AddSupportedOn(policy_definitions_elem,
- self._configuration['SUPPORTED_OS'])
+ self.config['win_supported_os'])
self._AddCategories(policy_definitions_elem,
- self._configuration['CATEGORY_PATH'])
+ self.config['win_category_path'])
self._active_policies_elem = self.AddElement(policy_definitions_elem,
'policies')
@@ -415,7 +379,7 @@ class ADMXWriter(xml_formatted_writer.XMLFormattedWriter):
pass
def Prepare(self):
- self._configuration = self._GetConfigurationForBuild(self.info['build'])
+ pass
def GetTemplateText(self):
return self._doc.toprettyxml(indent=' ')
diff --git a/tools/grit/grit/format/policy_templates/writers/plist_strings_writer.py b/tools/grit/grit/format/policy_templates/writers/plist_strings_writer.py
index a1e9e3c..51c43e9 100644
--- a/tools/grit/grit/format/policy_templates/writers/plist_strings_writer.py
+++ b/tools/grit/grit/format/policy_templates/writers/plist_strings_writer.py
@@ -6,12 +6,12 @@
from grit.format.policy_templates.writers import template_writer
-def GetWriter(info, messages):
+def GetWriter(config, messages):
'''Factory method for creating PListStringsWriter objects.
See the constructor of TemplateWriter for description of
arguments.
'''
- return PListStringsWriter(info, messages)
+ return PListStringsWriter(config, messages)
class PListStringsWriter(template_writer.TemplateWriter):
@@ -80,8 +80,8 @@ class PListStringsWriter(template_writer.TemplateWriter):
def BeginTemplate(self):
self._AddToStringTable(
- self.info['app_name'],
- self.info['app_name'],
+ self.config['app_name'],
+ self.config['app_name'],
self.messages['IDS_POLICY_MAC_CHROME_PREFERENCES'])
def EndTemplate(self):
diff --git a/tools/grit/grit/format/policy_templates/writers/plist_writer.py b/tools/grit/grit/format/policy_templates/writers/plist_writer.py
index 3399fcee..aff1d05 100644
--- a/tools/grit/grit/format/policy_templates/writers/plist_writer.py
+++ b/tools/grit/grit/format/policy_templates/writers/plist_writer.py
@@ -7,12 +7,12 @@ from xml.dom import minidom
from grit.format.policy_templates.writers import xml_formatted_writer
-def GetWriter(info, messages):
+def GetWriter(config, messages):
'''Factory method for creating PListWriter objects.
See the constructor of TemplateWriter for description of
arguments.
'''
- return PListWriter(info, messages)
+ return PListWriter(config, messages)
class PListWriter(xml_formatted_writer.XMLFormattedWriter):
@@ -99,11 +99,12 @@ class PListWriter(xml_formatted_writer.XMLFormattedWriter):
self._plist.attributes['version'] = '1'
dict = self.AddElement(self._plist, 'dict')
- self._AddStringKeyValuePair(dict, 'pfm_name', self.info['app_name'])
+ self._AddStringKeyValuePair(dict, 'pfm_name', self.config['app_name'])
self._AddStringKeyValuePair(dict, 'pfm_description', '')
self._AddStringKeyValuePair(dict, 'pfm_title', '')
self._AddStringKeyValuePair(dict, 'pfm_version', '1')
- self._AddStringKeyValuePair(dict, 'pfm_domain', self.info['mac_bundle_id'])
+ self._AddStringKeyValuePair(dict, 'pfm_domain',
+ self.config['mac_bundle_id'])
self._array = self._AddKeyValuePair(dict, 'pfm_subkeys', 'array')
diff --git a/tools/grit/grit/format/policy_templates/writers/template_writer.py b/tools/grit/grit/format/policy_templates/writers/template_writer.py
index b853b7d..7894d06 100644
--- a/tools/grit/grit/format/policy_templates/writers/template_writer.py
+++ b/tools/grit/grit/format/policy_templates/writers/template_writer.py
@@ -8,12 +8,12 @@ class TemplateWriter(object):
The methods of this class will be called by PolicyTemplateGenerator.
'''
- def __init__(self, info, messages):
+ def __init__(self, config, messages):
'''Initializes a TemplateWriter object.
Args:
- info: A dictionary of extra information required to generate the template.
- Currently it contains three keys:
+ config: A dictionary of information required to generate the template.
+ It contains some key-value pairs, including the following examples:
'build': 'chrome' or 'chromium'
'branding': 'Google Chrome' or 'Chromium'
'mac_bundle_id': The Mac bundle id of Chrome. (Only set when building
@@ -23,9 +23,9 @@ class TemplateWriter(object):
methods. That is the preferred way of accessing them, this should only
be used in exceptional cases. An example for its use is the
IDS_POLICY_WIN_SUPPORTED_WINXPSP2 message in ADM files, because that
- can not be associated with any policy or group.
+ cannot be associated with any policy or group.
'''
- self.info = info
+ self.config = config
self.messages = messages
def Prepare(self):