summaryrefslogtreecommitdiffstats
path: root/tools/grit
diff options
context:
space:
mode:
authorgfeher@chromium.org <gfeher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-24 11:25:50 +0000
committergfeher@chromium.org <gfeher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-24 11:25:50 +0000
commitef811fd19fc58d4ebf90904eec8ac5e4251c3e22 (patch)
tree6da019fb79255bdfe301cf5c559640ef8a1a8fb1 /tools/grit
parentf13db4e57df5848e921a9a06c9484df7e9aed072 (diff)
downloadchromium_src-ef811fd19fc58d4ebf90904eec8ac5e4251c3e22.zip
chromium_src-ef811fd19fc58d4ebf90904eec8ac5e4251c3e22.tar.gz
chromium_src-ef811fd19fc58d4ebf90904eec8ac5e4251c3e22.tar.bz2
Clean up the policy and message model of the template generator
In the old model each policy had to be in a group, and messages could be inherited from groups to policies. In the new model single policies does not have to be in groups and there is no inheritance of messages across policies/groups. Instead of that, policies have now two captions for different purposes. (Documented in policy_templates.json.) This is a more simple concept. BUG=55722,56512 TEST=covered by policy template generator unit tests Review URL: http://codereview.chromium.org/3454017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60458 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/grit')
-rw-r--r--tools/grit/grit/format/policy_templates/policy_template_generator.py122
-rw-r--r--tools/grit/grit/format/policy_templates/policy_template_generator_unittest.py130
-rw-r--r--tools/grit/grit/format/policy_templates/template_formatter.py2
-rw-r--r--tools/grit/grit/format/policy_templates/writers/adm_writer.py31
-rw-r--r--tools/grit/grit/format/policy_templates/writers/adm_writer_unittest.py88
-rw-r--r--tools/grit/grit/format/policy_templates/writers/doc_writer.py28
-rw-r--r--tools/grit/grit/format/policy_templates/writers/doc_writer_unittest.py15
-rw-r--r--tools/grit/grit/format/policy_templates/writers/plist_strings_writer.py24
-rw-r--r--tools/grit/grit/format/policy_templates/writers/plist_strings_writer_unittest.py41
-rw-r--r--tools/grit/grit/format/policy_templates/writers/plist_writer_unittest.py33
-rw-r--r--tools/grit/grit/format/policy_templates/writers/template_writer.py21
11 files changed, 222 insertions, 313 deletions
diff --git a/tools/grit/grit/format/policy_templates/policy_template_generator.py b/tools/grit/grit/format/policy_templates/policy_template_generator.py
index bcf5b8f..8c02d96 100644
--- a/tools/grit/grit/format/policy_templates/policy_template_generator.py
+++ b/tools/grit/grit/format/policy_templates/policy_template_generator.py
@@ -12,107 +12,81 @@ class PolicyTemplateGenerator:
this data to policy template files using TemplateWriter objects.
'''
- def __init__(self, messages, policy_groups):
+ def __init__(self, messages, policy_definitions):
'''Initializes this object with all the data necessary to output a
policy template.
Args:
messages: An identifier to string dictionary of all the localized
messages that might appear in the policy template.
- policy_groups: The policies are organized into groups, and each policy
- has a name and type. The user will see a GUI interface for assigning
- values to policies, by using the templates generated here. The traversed
- data structure is a list of policy groups. Each group is a dictionary
- and has an embedded list of policies under the key 'policies'.
- Example:
- policy_groups = [
- {
- 'name': 'PolicyGroup1',
- 'policies': [
- {'name': 'Policy1Name', 'type': 'string'}
- {'name': 'Policy2Name', 'type': 'main'}
- {'name': 'Policy3Name', 'type': 'enum', 'items': [...]}
- ]
- },
- {'name': 'PolicyGroup2', ...}
- ]
- See chrome/app/policy.policy_templates.json for an example and more
- details.
+ policy_definitions: The list of defined policies and groups, as
+ parsed from the polify metafile.
+ See chrome/app/policy.policy_templates.json for description and
+ content.
'''
# List of all the policies:
- self._policy_groups = policy_groups
+ self._policy_definitions = policy_definitions
# Localized messages to be inserted to the policy_groups structure:
self._messages = messages
- self._AddMessagesToPolicies()
+ self._AddMessagesToPolicyList(self._policy_definitions)
- def _AddMessagesToItem(self, item_name, item, needs_caption, needs_desc):
- '''Adds localized message strings to an item of the policy data structure
- (self._policy_groups).
+ def _AddMessageToItem(self, item_name, item, message_name, default=None):
+ '''Adds a localized message strings to an item of the policy data structure
Args:
item_name: The base of the grd name of the item.
- item: The item which will get its message strings now.
- needs_caption: A boolean value. If it is True, an exception will be raised
- in case there is no caption string for item in self._messages.
- needs_desc: A boolean value. If it is True, an exception will be raised
- in case there is no description string for item in self._messages.
+ item: The policy, group, or enum item.
+ message_name: Identifier of the message: 'desc', 'caption' or 'label'.
+ default: If this is specified and the message is not found for item,
+ then this string will be added to the item.
Raises:
- Exception() if a required message string was not found.
+ Exception() if the message string was not found and no default was
+ specified..
'''
# The keys for the item's messages in self._messages:
- caption_name = 'IDS_POLICY_%s_CAPTION' % item_name
- desc_name = 'IDS_POLICY_%s_DESC' % item_name
+ long_message_name = ('IDS_POLICY_%s_%s' %
+ (item_name.upper(), message_name.upper()))
# Copy the messages from self._messages to item:
- if caption_name in self._messages:
- item['caption'] = self._messages[caption_name]
- elif needs_caption:
- raise Exception('No localized caption for %s (missing %s).' %
- (item_name, caption_name))
- if desc_name in self._messages:
- item['desc'] = self._messages[desc_name]
- elif needs_desc:
- raise Exception('No localized description for %s (missing %s).' %
- (item_name, desc_name))
+ if long_message_name in self._messages:
+ item[message_name] = self._messages[long_message_name]
+ elif default != None:
+ item[message_name] = default
+ else:
+ raise Exception('No localized message for %s (missing %s).' %
+ (item_name, long_message_name))
def _AddMessagesToPolicy(self, policy):
- '''Adds localized message strings to a policy.
+ '''Adds localized message strings to a policy or group.
Args:
- policy: The data structure of the policy that will get message strings
- here.
+ policy: The data structure of the policy or group, that will get message
+ strings here.
'''
- full_name = policy['name'].upper()
- if policy['type'] == 'main':
- # In this case, both caption and description are optional.
- self._AddMessagesToItem(full_name, policy, False, False)
- else:
- # Add caption for this policy.
- self._AddMessagesToItem(full_name, policy, True, False)
- if policy['type'] == 'enum':
+ self._AddMessageToItem(policy['name'], policy, 'caption')
+ self._AddMessageToItem(policy['name'], policy, 'desc')
+ if policy['type'] != 'group':
+ # Real policies (that are not groups) might also have an optional
+ # 'label', that defaults to 'caption'.
+ self._AddMessageToItem(
+ policy['name'], policy, 'label', policy['caption'])
+ if policy['type'] == 'group':
+ self._AddMessagesToPolicyList(policy['policies'])
+ elif policy['type'] == 'enum':
# Iterate through all the items of an enum-type policy, and add captions.
for item in policy['items']:
- self._AddMessagesToItem('ENUM_' + item['name'].upper(), item,
- True, False)
+ self._AddMessageToItem('ENUM_' + item['name'], item, 'caption')
- def _AddMessagesToPolicies(self):
- '''Adds localized message strings to each item of the policy data structure
- (self._policy_groups).
+ def _AddMessagesToPolicyList(self, policy_list):
+ '''Adds localized message strings to each item in a list of policies and
+ groups.
+
+ Args:
+ policy_list: A list of policies and groups. Message strings will be added
+ for each item and to their child items, recursively.
'''
- # Iterate through all the policy groups.
- for group in self._policy_groups:
- # Get caption and description for this group.
- group_name = 'GROUP_' + group['name'].upper()
- self._AddMessagesToItem(group_name, group, True, True)
- if 'policies' in group:
- # Iterate through all the policies in the current group.
- for policy in group['policies']:
- # Add messages to the policy.
- self._AddMessagesToPolicy(policy)
- # Store a reference to the group of the policy. This makes
- # it easier to look up messages of the group when we have
- # a policy, like in PListStringsWriter and DocWriter.
- policy['parent'] = group
+ for policy in policy_list:
+ self._AddMessagesToPolicy(policy)
def GetTemplateText(self, template_writer):
'''Generates the text of the template from the arguments given
@@ -125,4 +99,4 @@ class PolicyTemplateGenerator:
Returns:
The text of the generated template.
'''
- return template_writer.WriteTemplate(self._policy_groups)
+ return template_writer.WriteTemplate(self._policy_definitions)
diff --git a/tools/grit/grit/format/policy_templates/policy_template_generator_unittest.py b/tools/grit/grit/format/policy_templates/policy_template_generator_unittest.py
index f2f6c66..7a07077 100644
--- a/tools/grit/grit/format/policy_templates/policy_template_generator_unittest.py
+++ b/tools/grit/grit/format/policy_templates/policy_template_generator_unittest.py
@@ -67,17 +67,17 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase):
def testEmptyGroups(self):
# Test that empty policy groups are not passed to the writer.
messages_mock = {
- 'IDS_POLICY_GROUP_GROUP1_CAPTION': None,
- 'IDS_POLICY_GROUP_GROUP1_DESC': None,
- 'IDS_POLICY_GROUP_GROUP2_CAPTION': None,
- 'IDS_POLICY_GROUP_GROUP2_DESC': None,
- 'IDS_POLICY_GROUP_GROUP3_CAPTION': None,
- 'IDS_POLICY_GROUP_GROUP3_DESC': None,
+ 'IDS_POLICY_GROUP1_CAPTION': '',
+ 'IDS_POLICY_GROUP1_DESC': '',
+ 'IDS_POLICY_GROUP2_CAPTION': '',
+ 'IDS_POLICY_GROUP2_DESC': '',
+ 'IDS_POLICY_GROUP3_CAPTION': '',
+ 'IDS_POLICY_GROUP3_DESC': '',
}
policies_mock = [
- {'name': 'Group1', 'policies': []},
- {'name': 'Group2', 'policies': []},
- {'name': 'Group3', 'policies': []},
+ {'name': 'Group1', 'type': 'group', 'policies': []},
+ {'name': 'Group2', 'type': 'group', 'policies': []},
+ {'name': 'Group3', 'type': 'group', 'policies': []},
]
class LocalMockWriter(mock_writer.MockWriter):
def __init__(self):
@@ -93,20 +93,23 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase):
def testGroups(self):
# Test that policy groups are passed to the writer in the correct order.
messages_mock = {
- 'IDS_POLICY_GROUP_GROUP1_CAPTION': None,
- 'IDS_POLICY_GROUP_GROUP1_DESC': None,
- 'IDS_POLICY_GROUP_GROUP2_CAPTION': None,
- 'IDS_POLICY_GROUP_GROUP2_DESC': None,
- 'IDS_POLICY_GROUP_GROUP3_CAPTION': None,
- 'IDS_POLICY_GROUP_GROUP3_DESC': None,
- 'IDS_POLICY_TAG1_CAPTION': None,
- 'IDS_POLICY_TAG2_CAPTION': None,
- 'IDS_POLICY_TAG3_CAPTION': None,
+ 'IDS_POLICY_GROUP1_CAPTION': '',
+ 'IDS_POLICY_GROUP1_DESC': '',
+ 'IDS_POLICY_GROUP2_CAPTION': '',
+ 'IDS_POLICY_GROUP2_DESC': '',
+ 'IDS_POLICY_GROUP3_CAPTION': '',
+ 'IDS_POLICY_GROUP3_DESC': '',
+ 'IDS_POLICY_TAG1_CAPTION': '',
+ 'IDS_POLICY_TAG1_DESC': '',
+ 'IDS_POLICY_TAG2_CAPTION': '',
+ 'IDS_POLICY_TAG2_DESC': '',
+ 'IDS_POLICY_TAG3_CAPTION': '',
+ 'IDS_POLICY_TAG3_DESC': '',
}
policies_mock = [
- {'name': 'Group1', 'policies': [{'name': 'TAG1', 'type': 'mock'}]},
- {'name': 'Group2', 'policies': [{'name': 'TAG2', 'type': 'mock'}]},
- {'name': 'Group3', 'policies': [{'name': 'TAG3', 'type': 'mock'}]},
+ {'name': 'Group1', 'type': 'group', 'policies': [{'name': 'TAG1', 'type': 'mock'}]},
+ {'name': 'Group2', 'type': 'group', 'policies': [{'name': 'TAG2', 'type': 'mock'}]},
+ {'name': 'Group3', 'type': 'group', 'policies': [{'name': 'TAG3', 'type': 'mock'}]},
]
class LocalMockWriter(mock_writer.MockWriter):
def __init__(self):
@@ -122,14 +125,14 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase):
def testGroupTexts(self):
# Test that GUI strings are assigned correctly to policy groups.
messages_mock = {
- 'IDS_POLICY_GROUP_GROUP1_CAPTION': 'string1',
- 'IDS_POLICY_GROUP_GROUP1_DESC': 'string2',
- 'IDS_POLICY_GROUP_GROUP2_CAPTION': 'string3',
- 'IDS_POLICY_GROUP_GROUP2_DESC': 'string4',
+ 'IDS_POLICY_GROUP1_CAPTION': 'string1',
+ 'IDS_POLICY_GROUP1_DESC': 'string2',
+ 'IDS_POLICY_GROUP2_CAPTION': 'string3',
+ 'IDS_POLICY_GROUP2_DESC': 'string4',
}
policy_groups_mock = [
- {'name': 'Group1'},
- {'name': 'Group2'},
+ {'name': 'Group1', 'type': 'group', 'policies': []},
+ {'name': 'Group2', 'type': 'group', 'policies': []},
]
class LocalMockWriter(mock_writer.MockWriter):
def BeginPolicyGroup(self, group):
@@ -146,17 +149,21 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase):
def testPolicies(self):
# Test that policies are passed to the writer in the correct order.
messages_mock = {
- 'IDS_POLICY_GROUP_GROUP1_CAPTION': None,
- 'IDS_POLICY_GROUP_GROUP1_DESC': None,
- 'IDS_POLICY_GROUP_GROUP2_CAPTION': None,
- 'IDS_POLICY_GROUP_GROUP2_DESC': None,
- 'IDS_POLICY_GROUP1POLICY1_CAPTION': None,
- 'IDS_POLICY_GROUP1POLICY2_CAPTION': None,
- 'IDS_POLICY_GROUP2POLICY3_CAPTION': None,
+ 'IDS_POLICY_GROUP1_CAPTION': '',
+ 'IDS_POLICY_GROUP1_DESC': '',
+ 'IDS_POLICY_GROUP2_CAPTION': '',
+ 'IDS_POLICY_GROUP2_DESC': '',
+ 'IDS_POLICY_GROUP1POLICY1_CAPTION': '',
+ 'IDS_POLICY_GROUP1POLICY1_DESC': '',
+ 'IDS_POLICY_GROUP1POLICY2_CAPTION': '',
+ 'IDS_POLICY_GROUP1POLICY2_DESC': '',
+ 'IDS_POLICY_GROUP2POLICY3_CAPTION': '',
+ 'IDS_POLICY_GROUP2POLICY3_DESC': '',
}
policy_groups_mock = [
{
'name': 'Group1',
+ 'type': 'group',
'policies': [
{'name': 'Group1Policy1', 'type': 'string'},
{'name': 'Group1Policy2', 'type': 'string'},
@@ -164,6 +171,7 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase):
},
{
'name': 'Group2',
+ 'type': 'group',
'policies': [
{'name': 'Group2Policy3', 'type': 'string'},
]
@@ -193,12 +201,13 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase):
'IDS_POLICY_POLICY1_DESC': 'string2',
'IDS_POLICY_POLICY2_CAPTION': 'string3',
'IDS_POLICY_POLICY2_DESC': 'string4',
- 'IDS_POLICY_GROUP_GROUP1_CAPTION': None,
- 'IDS_POLICY_GROUP_GROUP1_DESC': None,
+ 'IDS_POLICY_GROUP1_CAPTION': '',
+ 'IDS_POLICY_GROUP1_DESC': '',
}
policy_groups_mock = [
{
'name': 'Group1',
+ 'type': 'group',
'policies': [
{'name': 'Policy1', 'type': 'string'},
{'name': 'Policy2', 'type': 'string'}
@@ -224,24 +233,20 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase):
'IDS_POLICY_ENUM_ITEM1_CAPTION': 'string1',
'IDS_POLICY_ENUM_ITEM2_CAPTION': 'string2',
'IDS_POLICY_ENUM_ITEM3_CAPTION': 'string3',
- 'IDS_POLICY_POLICY1_CAPTION': None,
- 'IDS_POLICY_GROUP_GROUP1_CAPTION': None,
- 'IDS_POLICY_GROUP_GROUP1_DESC': None,
+ 'IDS_POLICY_POLICY1_CAPTION': '',
+ 'IDS_POLICY_POLICY1_DESC': '',
+
}
- policy_groups_mock = [
- {
- 'name': 'Group1',
- 'policies': [{
- 'name': 'Policy1',
- 'type': 'enum',
- 'items': [
- {'name': 'item1', 'value': '0'},
- {'name': 'item2', 'value': '1'},
- {'name': 'item3', 'value': '3'},
- ]
- }]
- }
- ]
+ policy_groups_mock = [{
+ 'name': 'Policy1',
+ 'type': 'enum',
+ 'items': [
+ {'name': 'item1', 'value': '0'},
+ {'name': 'item2', 'value': '1'},
+ {'name': 'item3', 'value': '3'},
+ ]
+ }]
+
class LocalMockWriter(mock_writer.MockWriter):
def WritePolicy(self, policy):
self.tester.assertEquals(policy['items'][0]['caption'], 'string1')
@@ -252,16 +257,20 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase):
def testPolicyFiltering(self):
# Test that policies are filtered correctly based on their annotations.
messages_mock = {
- 'IDS_POLICY_GROUP_GROUP1_CAPTION': None,
- 'IDS_POLICY_GROUP_GROUP1_DESC': None,
- 'IDS_POLICY_GROUP_GROUP2_CAPTION': None,
- 'IDS_POLICY_GROUP_GROUP2_DESC': None,
- 'IDS_POLICY_GROUP1POLICY1_CAPTION': None,
- 'IDS_POLICY_GROUP1POLICY2_CAPTION': None,
- 'IDS_POLICY_GROUP2POLICY3_CAPTION': None,
+ 'IDS_POLICY_GROUP1_CAPTION': '',
+ 'IDS_POLICY_GROUP1_DESC': '',
+ 'IDS_POLICY_GROUP2_CAPTION': '',
+ 'IDS_POLICY_GROUP2_DESC': '',
+ 'IDS_POLICY_GROUP1POLICY1_CAPTION': '',
+ 'IDS_POLICY_GROUP1POLICY1_DESC': '',
+ 'IDS_POLICY_GROUP1POLICY2_CAPTION': '',
+ 'IDS_POLICY_GROUP1POLICY2_DESC': '',
+ 'IDS_POLICY_GROUP2POLICY3_CAPTION': '',
+ 'IDS_POLICY_GROUP2POLICY3_DESC': '',
}
policy_groups_mock = [{
'name': 'Group1',
+ 'type': 'group',
'policies': [
{
'name': 'Group1Policy1',
@@ -276,6 +285,7 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase):
]
},{
'name': 'Group2',
+ 'type': 'group',
'policies': [
{
'name': 'Group2Policy3',
diff --git a/tools/grit/grit/format/policy_templates/template_formatter.py b/tools/grit/grit/format/policy_templates/template_formatter.py
index 8e03aac..4fd28eb 100644
--- a/tools/grit/grit/format/policy_templates/template_formatter.py
+++ b/tools/grit/grit/format/policy_templates/template_formatter.py
@@ -76,7 +76,7 @@ class TemplateFormatter(interface.ItemFormatter):
'''
policy_generator = policy_template_generator.PolicyTemplateGenerator(
self._messages,
- self._policy_data['policy_groups'])
+ self._policy_data['policy_definitions'])
writer = self._writer_module.GetWriter(self._config, self._messages)
str = policy_generator.GetTemplateText(writer)
return str
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 bea1e38..23df695 100644
--- a/tools/grit/grit/format/policy_templates/writers/adm_writer.py
+++ b/tools/grit/grit/format/policy_templates/writers/adm_writer.py
@@ -25,27 +25,6 @@ class AdmWriter(template_writer.TemplateWriter):
'list': 'LISTBOX'}
NEWLINE = '\r\n'
- # TODO(gfeher): Get rid of this logic by renaming the messages in the .grd
- # file. Before that, all the writers should switch to using
- # this logic.
- def _GetLocalizedPolicyMessage(self, policy, msg_id):
- '''Looks up localized caption or description for a policy.
- If the policy does not have the required message, then it is
- inherited from the group.
-
- Args:
- policy: The data structure of the policy.
- msg_id: Either 'caption' or 'desc'.
-
- Returns:
- The corresponding message for the policy.
- '''
- if msg_id in policy:
- msg = policy[msg_id]
- else:
- msg = policy['parent'][msg_id]
- return msg
-
def _AddGuiString(self, name, value):
# Escape newlines in the value.
value = value.replace('\n','\\n')
@@ -82,9 +61,8 @@ class AdmWriter(template_writer.TemplateWriter):
Args:
policy: The policy to write to the output.
'''
- policy_caption = self._GetLocalizedPolicyMessage(policy, 'caption')
policy_part_name = policy['name'] + '_Part'
- self._AddGuiString(policy_part_name, policy_caption)
+ self._AddGuiString(policy_part_name, policy['label'])
# Print the PART ... END PART section:
self._PrintLine()
@@ -108,14 +86,11 @@ class AdmWriter(template_writer.TemplateWriter):
self._PrintLine('END PART', -1)
def WritePolicy(self, policy):
- policy_desc = self._GetLocalizedPolicyMessage(policy, 'desc')
- policy_caption = self._GetLocalizedPolicyMessage(policy, 'caption')
-
- self._AddGuiString(policy['name'] + '_Policy', policy_caption)
+ self._AddGuiString(policy['name'] + '_Policy', policy['caption'])
self._PrintLine('POLICY !!%s_Policy' % policy['name'], 1)
self._WriteSupported()
policy_explain_name = policy['name'] + '_Explain'
- self._AddGuiString(policy_explain_name, policy_desc)
+ self._AddGuiString(policy_explain_name, policy['desc'])
self._PrintLine('EXPLAIN !!' + policy_explain_name)
if policy['type'] == 'main':
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 1fa1b01..6c75d2b 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
@@ -42,7 +42,7 @@ class AdmWriterUnittest(writer_unittest_common.WriterUnittestCommon):
# Test PListWriter in case of empty polices.
grd = self.PrepareTest('''
{
- 'policy_groups': [],
+ 'policy_definitions': [],
'placeholders': [],
}''', '''
<messages>
@@ -65,21 +65,18 @@ chromium="Chromium"'''
# Tests a policy group with a single policy of type 'main'.
grd = self.PrepareTest('''
{
- 'policy_groups': [
+ 'policy_definitions': [
{
- 'name': 'MainGroup',
- 'policies': [{
- 'name': 'MainPolicy',
- 'type': 'main',
- 'annotations': {'platforms': ['win']}
- }],
+ 'name': 'MainPolicy',
+ 'type': 'main',
+ 'annotations': {'platforms': ['win']}
},
],
'placeholders': [],
}''', '''
<messages>
- <message name="IDS_POLICY_GROUP_MAINGROUP_CAPTION">Caption of main.</message>
- <message name="IDS_POLICY_GROUP_MAINGROUP_DESC">Description of main.</message>
+ <message name="IDS_POLICY_MAINPOLICY_CAPTION">Caption of main.</message>
+ <message name="IDS_POLICY_MAINPOLICY_DESC">Description of main.</message>
<message name="IDS_POLICY_WIN_SUPPORTED_WINXPSP2">At least Windows 3.12</message>
</messages>
''' )
@@ -114,23 +111,19 @@ MainPolicy_Explain="Description of main."'''
# Tests a policy group with a single policy of type 'string'.
grd = self.PrepareTest('''
{
- 'policy_groups': [
+ 'policy_definitions': [
{
- 'name': 'StringGroup',
- 'policies': [{
- 'name': 'StringPolicy',
- 'type': 'string',
- 'annotations': {'platforms': ['win']}
- }],
+ 'name': 'StringPolicy',
+ 'type': 'string',
+ 'annotations': {'platforms': ['win']}
},
],
'placeholders': [],
}''', '''
<messages>
- <message name="IDS_POLICY_GROUP_STRINGGROUP_CAPTION">Caption of group.</message>
- <message name="IDS_POLICY_GROUP_STRINGGROUP_DESC">Description of group.
-With a newline.</message>
<message name="IDS_POLICY_STRINGPOLICY_CAPTION">Caption of policy.</message>
+ <message name="IDS_POLICY_STRINGPOLICY_DESC">Description of group.
+With a newline.</message>
<message name="IDS_POLICY_WIN_SUPPORTED_WINXPSP2">At least Windows 3.13</message>
</messages>
''' )
@@ -165,25 +158,20 @@ StringPolicy_Part="Caption of policy."
# Tests a policy group with a single policy of type 'enum'.
grd = self.PrepareTest('''
{
- 'policy_groups': [
+ 'policy_definitions': [
{
- 'name': 'EnumGroup',
- 'policies': [{
- 'name': 'EnumPolicy',
- 'type': 'enum',
- 'items': [
- {'name': 'ProxyServerDisabled', 'value': '0'},
- {'name': 'ProxyServerAutoDetect', 'value': '1'},
- ],
- 'annotations': {'platforms': ['win']}
- }],
+ 'name': 'EnumPolicy',
+ 'type': 'enum',
+ 'items': [
+ {'name': 'ProxyServerDisabled', 'value': '0'},
+ {'name': 'ProxyServerAutoDetect', 'value': '1'},
+ ],
+ 'annotations': {'platforms': ['win']}
},
],
'placeholders': [],
}''', '''
<messages>
- <message name="IDS_POLICY_GROUP_ENUMGROUP_CAPTION">Caption of group.</message>
- <message name="IDS_POLICY_GROUP_ENUMGROUP_DESC">Description of group.</message>
<message name="IDS_POLICY_ENUMPOLICY_CAPTION">Caption of policy.</message>
<message name="IDS_POLICY_ENUMPOLICY_DESC">Description of policy.</message>
<message name="IDS_POLICY_ENUM_PROXYSERVERDISABLED_CAPTION">Option1</message>
@@ -231,23 +219,20 @@ ProxyServerAutoDetect_DropDown="Option2"
# Tests a policy group with a single policy of type 'list'.
grd = self.PrepareTest('''
{
- 'policy_groups': [
+ 'policy_definitions': [
{
- 'name': 'ListGroup',
- 'policies': [{
- 'name': 'ListPolicy',
- 'type': 'list',
- 'annotations': {'platforms': ['win']}
- }],
+ 'name': 'ListPolicy',
+ 'type': 'list',
+ 'annotations': {'platforms': ['win']}
},
],
'placeholders': [],
}''', '''
<messages>
- <message name="IDS_POLICY_GROUP_LISTGROUP_CAPTION">Caption of list group.</message>
- <message name="IDS_POLICY_GROUP_LISTGROUP_DESC">Description of list group.
+ <message name="IDS_POLICY_LISTPOLICY_DESC">Description of list policy.
With a newline.</message>
<message name="IDS_POLICY_LISTPOLICY_CAPTION">Caption of list policy.</message>
+ <message name="IDS_POLICY_LISTPOLICY_LABEL">Value caption of list policy.</message>
<message name="IDS_POLICY_WIN_SUPPORTED_WINXPSP2">At least Windows 3.15</message>
</messages>
''')
@@ -274,8 +259,8 @@ With a newline.</message>
SUPPORTED_WINXPSP2="At least Windows 3.15"
chromium="Chromium"
ListPolicy_Policy="Caption of list policy."
-ListPolicy_Explain="Description of list group.\\nWith a newline."
-ListPolicy_Part="Caption of list policy."
+ListPolicy_Explain="Description of list policy.\\nWith a newline."
+ListPolicy_Part="Value caption of list policy."
'''
self.CompareOutputs(output, expected_output)
@@ -284,9 +269,10 @@ ListPolicy_Part="Caption of list policy."
# be included in the ADM file.
grd = self.PrepareTest('''
{
- 'policy_groups': [
+ 'policy_definitions': [
{
'name': 'NonWinGroup',
+ 'type': 'group',
'policies': [{
'name': 'NonWinPolicy',
'type': 'list',
@@ -297,9 +283,10 @@ ListPolicy_Part="Caption of list policy."
'placeholders': [],
}''', '''
<messages>
- <message name="IDS_POLICY_GROUP_NONWINGROUP_CAPTION">Group caption.</message>
- <message name="IDS_POLICY_GROUP_NONWINGROUP_DESC">Group description.</message>
+ <message name="IDS_POLICY_NONWINGROUP_CAPTION">Group caption.</message>
+ <message name="IDS_POLICY_NONWINGROUP_DESC">Group description.</message>
<message name="IDS_POLICY_NONWINPOLICY_CAPTION">Caption of list policy.</message>
+ <message name="IDS_POLICY_NONWINPOLICY_DESC">Desc of list policy.</message>
<message name="IDS_POLICY_WIN_SUPPORTED_WINXPSP2">At least Windows 3.16</message>
</messages>
''')
@@ -320,9 +307,10 @@ chromium="Chromium"
# Tests a policy group that has more than one policies.
grd = self.PrepareTest('''
{
- 'policy_groups': [
+ 'policy_definitions': [
{
'name': 'Group1',
+ 'type': 'group',
'policies': [{
'name': 'Policy1',
'type': 'list',
@@ -337,8 +325,8 @@ chromium="Chromium"
'placeholders': [],
}''', '''
<messages>
- <message name="IDS_POLICY_GROUP_GROUP1_CAPTION">Caption of group.</message>
- <message name="IDS_POLICY_GROUP_GROUP1_DESC">Description of group.</message>
+ <message name="IDS_POLICY_GROUP1_CAPTION">Caption of group.</message>
+ <message name="IDS_POLICY_GROUP1_DESC">Description of group.</message>
<message name="IDS_POLICY_POLICY1_DESC">Description of policy1.
With a newline.</message>
<message name="IDS_POLICY_POLICY2_DESC">Description of policy2.
diff --git a/tools/grit/grit/format/policy_templates/writers/doc_writer.py b/tools/grit/grit/format/policy_templates/writers/doc_writer.py
index ad28ace..cde4227 100644
--- a/tools/grit/grit/format/policy_templates/writers/doc_writer.py
+++ b/tools/grit/grit/format/policy_templates/writers/doc_writer.py
@@ -32,25 +32,6 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter):
files.
'''
- # TODO(gfeher): This function is duplicated in PListWriter.
- def _GetLocalizedPolicyMessage(self, policy, msg_id):
- '''Looks up localized caption or description for a policy.
- If the policy does not have the required message, then it is
- inherited from the group.
-
- Args:
- policy: The data structure of the policy.
- msg_id: Either 'caption' or 'desc'.
-
- Returns:
- The corresponding message for the policy.
- '''
- if msg_id in policy:
- msg = policy[msg_id]
- else:
- msg = policy['parent'][msg_id]
- return msg
-
def _GetLocalizedMessage(self, msg_id):
'''Returns a localized message for this writer.
@@ -131,9 +112,8 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter):
parent: The DOM node for which the feature list will be added.
policy: The data structure of a policy.
'''
- desc = self._GetLocalizedPolicyMessage(policy, 'desc')
# Replace URLs with links in the description.
- self._AddTextWithLinks(parent, desc)
+ self._AddTextWithLinks(parent, policy['desc'])
# Add list of enum items.
if policy['type'] == 'enum':
ul = self.AddElement(parent, 'ul')
@@ -370,13 +350,12 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter):
parent: The DOM node of the summary table.
policy: The data structure of the policy.
'''
- caption = self._GetLocalizedPolicyMessage(policy, 'caption')
tr = self._AddStyledElement(parent, 'tr', ['tr'])
name_td = self._AddStyledElement(tr, 'td', ['td', 'td.left'])
self.AddElement(
name_td, 'a',
{'href': '#' + policy['name']}, policy['name'])
- self._AddStyledElement(tr, 'td', ['td', 'td.right'], {}, caption)
+ self._AddStyledElement(tr, 'td', ['td', 'td.right'], {}, policy['caption'])
def _AddPolicySection(self, parent, policy):
'''Adds a section about the policy in the detailed policy listing.
@@ -386,10 +365,9 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter):
policy: The data structure of the policy.
'''
h2 = self.AddElement(parent, 'h2')
- caption = self._GetLocalizedPolicyMessage(policy, 'caption')
self.AddElement(h2, 'a', {'name': policy['name']})
self.AddText(h2, policy['name'])
- self.AddElement(parent, 'span', {}, caption)
+ self.AddElement(parent, 'span', {}, policy['caption'])
self._AddPolicyNote(parent, policy)
self._AddPolicyDetails(parent, policy)
diff --git a/tools/grit/grit/format/policy_templates/writers/doc_writer_unittest.py b/tools/grit/grit/format/policy_templates/writers/doc_writer_unittest.py
index 2166916..a394db7 100644
--- a/tools/grit/grit/format/policy_templates/writers/doc_writer_unittest.py
+++ b/tools/grit/grit/format/policy_templates/writers/doc_writer_unittest.py
@@ -104,21 +104,6 @@ class DocWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'<div/>'
'</div>')
- def testGetLocalizedPolicyMessage(self):
- # Test if the message inheritance logic works well in
- # DocWriter.GetLocalizedPolicyMessage()
- policy = {'message_id1': '1hello, world'}
- self.assertEquals(
- self.writer._GetLocalizedPolicyMessage(policy, 'message_id1'),
- '1hello, world')
- self.assertRaises(
- KeyError,
- self.writer._GetLocalizedPolicyMessage, policy, 'message_id2')
- policy['parent'] = {'message_id3': '3hello, world'}
- self.assertEquals(
- self.writer._GetLocalizedPolicyMessage(policy, 'message_id3'),
- '3hello, world')
-
def testGetLocalizedMessage(self):
# Test if localized messages are retrieved correctly.
self.writer.messages = {
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 47b1816..e85d85e 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
@@ -20,25 +20,6 @@ class PListStringsWriter(template_writer.TemplateWriter):
[lang].lproj subdirectories of the manifest bundle.
'''
- # TODO(gfeher): This function is duplicated in DocWriter.
- def _GetLocalizedPolicyMessage(self, policy, msg_id):
- '''Looks up localized caption or description for a policy.
- If the policy does not have the required message, then it is
- inherited from the group.
-
- Args:
- policy: The data structure of the policy.
- msg_id: Either 'caption' or 'desc'.
-
- Returns:
- The corresponding message for the policy.
- '''
- if msg_id in policy:
- msg = policy[msg_id]
- else:
- msg = policy['parent'][msg_id]
- return msg
-
def _AddToStringTable(self, item_name, caption, desc):
'''Add a title and a description of an item to the string table.
@@ -62,8 +43,7 @@ class PListStringsWriter(template_writer.TemplateWriter):
policy: The policy for which the strings will be added to the
string table.
'''
- desc = self._GetLocalizedPolicyMessage(policy, 'desc')
- caption = self._GetLocalizedPolicyMessage(policy, 'caption')
+ desc = policy['desc']
if (policy['type'] == 'enum'):
# Append the captions of enum items to the description string.
item_descs = []
@@ -71,7 +51,7 @@ class PListStringsWriter(template_writer.TemplateWriter):
item_descs.append(item['value'] + ' - ' + item['caption'])
desc = '\n'.join(item_descs) + '\n' + desc
- self._AddToStringTable(policy['name'], caption, desc)
+ self._AddToStringTable(policy['name'], policy['label'], desc)
def BeginTemplate(self):
self._AddToStringTable(
diff --git a/tools/grit/grit/format/policy_templates/writers/plist_strings_writer_unittest.py b/tools/grit/grit/format/policy_templates/writers/plist_strings_writer_unittest.py
index b604511..e8e8463 100644
--- a/tools/grit/grit/format/policy_templates/writers/plist_strings_writer_unittest.py
+++ b/tools/grit/grit/format/policy_templates/writers/plist_strings_writer_unittest.py
@@ -28,7 +28,7 @@ class PListStringsWriterUnittest(writer_unittest_common.WriterUnittestCommon):
# Test PListStringsWriter in case of empty polices.
grd = self.PrepareTest('''
{
- 'policy_groups': [],
+ 'policy_definitions': [],
'placeholders': [],
}''', '''
<messages>
@@ -51,9 +51,10 @@ Chromium.pfm_description = "Chromium preferen\\"ces";
# Tests a policy group with a single policy of type 'main'.
grd = self.PrepareTest('''
{
- 'policy_groups': [
+ 'policy_definitions': [
{
'name': 'MainGroup',
+ 'type': 'group',
'policies': [{
'name': 'MainPolicy',
'type': 'main',
@@ -64,8 +65,10 @@ Chromium.pfm_description = "Chromium preferen\\"ces";
'placeholders': [],
}''', '''
<messages>
- <message name="IDS_POLICY_GROUP_MAINGROUP_CAPTION">Caption of main.</message>
- <message name="IDS_POLICY_GROUP_MAINGROUP_DESC">Title of main.</message>
+ <message name="IDS_POLICY_MAINGROUP_CAPTION">Caption of main.</message>
+ <message name="IDS_POLICY_MAINGROUP_DESC">Title of main.</message>
+ <message name="IDS_POLICY_MAINPOLICY_CAPTION">Caption of main policy.</message>
+ <message name="IDS_POLICY_MAINPOLICY_DESC">Title of main policy.</message>
<message name="IDS_POLICY_MAC_CHROME_PREFERENCES">Preferences of $1</message>
</messages>
''' )
@@ -78,8 +81,8 @@ Chromium.pfm_description = "Chromium preferen\\"ces";
expected_output = \
'''Google Chrome.pfm_title = "Google Chrome";
Google Chrome.pfm_description = "Preferences of Google Chrome";
-MainPolicy.pfm_title = "Caption of main.";
-MainPolicy.pfm_description = "Title of main.";
+MainPolicy.pfm_title = "Caption of main policy.";
+MainPolicy.pfm_description = "Title of main policy.";
'''
self.assertEquals(output.strip(), expected_output.strip())
@@ -88,9 +91,10 @@ MainPolicy.pfm_description = "Title of main.";
# inheriting group description to policy description.
grd = self.PrepareTest('''
{
- 'policy_groups': [
+ 'policy_definitions': [
{
'name': 'StringGroup',
+ 'type': 'group',
'policies': [{
'name': 'StringPolicy',
'type': 'string',
@@ -101,10 +105,12 @@ MainPolicy.pfm_description = "Title of main.";
'placeholders': [],
}''', '''
<messages>
- <message name="IDS_POLICY_GROUP_STRINGGROUP_CAPTION">Caption of group.</message>
- <message name="IDS_POLICY_GROUP_STRINGGROUP_DESC">Description of group.
+ <message name="IDS_POLICY_STRINGGROUP_CAPTION">Caption of group.</message>
+ <message name="IDS_POLICY_STRINGGROUP_DESC">Description of group.
With a newline.</message>
<message name="IDS_POLICY_STRINGPOLICY_CAPTION">Caption of policy.</message>
+ <message name="IDS_POLICY_STRINGPOLICY_DESC">Description of policy.
+With a newline.</message>
<message name="IDS_POLICY_MAC_CHROME_PREFERENCES">Preferences Of $1</message>
</messages>
''' )
@@ -118,7 +124,7 @@ With a newline.</message>
'''Chromium.pfm_title = "Chromium";
Chromium.pfm_description = "Preferences Of Chromium";
StringPolicy.pfm_title = "Caption of policy.";
-StringPolicy.pfm_description = "Description of group.\\nWith a newline.";
+StringPolicy.pfm_description = "Description of policy.\\nWith a newline.";
'''
self.assertEquals(output.strip(), expected_output.strip())
@@ -126,9 +132,10 @@ StringPolicy.pfm_description = "Description of group.\\nWith a newline.";
# Tests a policy group with a single policy of type 'enum'.
grd = self.PrepareTest('''
{
- 'policy_groups': [
+ 'policy_definitions': [
{
'name': 'EnumGroup',
+ 'type': 'group',
'policies': [{
'name': 'EnumPolicy',
'type': 'enum',
@@ -143,8 +150,8 @@ StringPolicy.pfm_description = "Description of group.\\nWith a newline.";
'placeholders': [],
}''', '''
<messages>
- <message name="IDS_POLICY_GROUP_ENUMGROUP_CAPTION">Caption of group.</message>
- <message name="IDS_POLICY_GROUP_ENUMGROUP_DESC">Description of group.</message>
+ <message name="IDS_POLICY_ENUMGROUP_CAPTION">Caption of group.</message>
+ <message name="IDS_POLICY_ENUMGROUP_DESC">Description of group.</message>
<message name="IDS_POLICY_ENUMPOLICY_CAPTION">Caption of policy.</message>
<message name="IDS_POLICY_ENUMPOLICY_DESC">Description of policy.</message>
<message name="IDS_POLICY_ENUM_PROXYSERVERDISABLED_CAPTION">Option1</message>
@@ -171,9 +178,10 @@ EnumPolicy.pfm_description = "0 - Option1\\n1 - Option2\\nDescription of policy.
# be included in the plist string table.
grd = self.PrepareTest('''
{
- 'policy_groups': [
+ 'policy_definitions': [
{
'name': 'NonMacGroup',
+ 'type': 'group',
'policies': [{
'name': 'NonMacPolicy',
'type': 'string',
@@ -184,9 +192,10 @@ EnumPolicy.pfm_description = "0 - Option1\\n1 - Option2\\nDescription of policy.
'placeholders': [],
}''', '''
<messages>
- <message name="IDS_POLICY_GROUP_NONMACGROUP_CAPTION">Caption of group.</message>
- <message name="IDS_POLICY_GROUP_NONMACGROUP_DESC">Description of group.</message>
+ <message name="IDS_POLICY_NONMACGROUP_CAPTION">Caption of group.</message>
+ <message name="IDS_POLICY_NONMACGROUP_DESC">Description of group.</message>
<message name="IDS_POLICY_NONMACPOLICY_CAPTION">Caption of policy.</message>
+ <message name="IDS_POLICY_NONMACPOLICY_DESC">Description of policy.</message>
<message name="IDS_POLICY_MAC_CHROME_PREFERENCES">$1 preferences</message>
</messages>
''' )
diff --git a/tools/grit/grit/format/policy_templates/writers/plist_writer_unittest.py b/tools/grit/grit/format/policy_templates/writers/plist_writer_unittest.py
index 157a258..4b21ec4 100644
--- a/tools/grit/grit/format/policy_templates/writers/plist_writer_unittest.py
+++ b/tools/grit/grit/format/policy_templates/writers/plist_writer_unittest.py
@@ -63,7 +63,7 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
# Test PListWriter in case of empty polices.
grd = self.PrepareTest('''
{
- 'policy_groups': [],
+ 'policy_definitions': [],
'placeholders': [],
}''', '''<messages />''' )
@@ -81,9 +81,10 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
# Tests a policy group with a single policy of type 'main'.
grd = self.PrepareTest('''
{
- 'policy_groups': [
+ 'policy_definitions': [
{
'name': 'MainGroup',
+ 'type': 'group',
'policies': [{
'name': 'MainPolicy',
'type': 'main',
@@ -94,8 +95,10 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'placeholders': [],
}''', '''
<messages>
- <message name="IDS_POLICY_GROUP_MAINGROUP_CAPTION">This is not tested here.</message>
- <message name="IDS_POLICY_GROUP_MAINGROUP_DESC">This is not tested here.</message>
+ <message name="IDS_POLICY_MAINGROUP_CAPTION">This is not tested here.</message>
+ <message name="IDS_POLICY_MAINGROUP_DESC">This is not tested here.</message>
+ <message name="IDS_POLICY_MAINPOLICY_CAPTION">This is not tested here.</message>
+ <message name="IDS_POLICY_MAINPOLICY_DESC">This is not tested here.</message>
</messages>
''' )
output = self.GetOutput(
@@ -127,9 +130,10 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
# Tests a policy group with a single policy of type 'string'.
grd = self.PrepareTest('''
{
- 'policy_groups': [
+ 'policy_definitions': [
{
'name': 'StringGroup',
+ 'type': 'group',
'policies': [{
'name': 'StringPolicy',
'type': 'string',
@@ -140,8 +144,8 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'placeholders': [],
}''', '''
<messages>
- <message name="IDS_POLICY_GROUP_STRINGGROUP_CAPTION">This is not tested here.</message>
- <message name="IDS_POLICY_GROUP_STRINGGROUP_DESC">This is not tested here.</message>
+ <message name="IDS_POLICY_STRINGGROUP_CAPTION">This is not tested here.</message>
+ <message name="IDS_POLICY_STRINGGROUP_DESC">This is not tested here.</message>
<message name="IDS_POLICY_STRINGPOLICY_CAPTION">This is not tested here.</message>
<message name="IDS_POLICY_STRINGPOLICY_DESC">This is not tested here.</message>
</messages>
@@ -175,9 +179,10 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
# Tests a policy group with a single policy of type 'enum'.
grd = self.PrepareTest('''
{
- 'policy_groups': [
+ 'policy_definitions': [
{
'name': 'EnumGroup',
+ 'type': 'group',
'policies': [{
'name': 'EnumPolicy',
'type': 'enum',
@@ -192,8 +197,8 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'placeholders': [],
}''', '''
<messages>
- <message name="IDS_POLICY_GROUP_ENUMGROUP_CAPTION">This is not tested here.</message>
- <message name="IDS_POLICY_GROUP_ENUMGROUP_DESC">This is not tested here.</message>
+ <message name="IDS_POLICY_ENUMGROUP_CAPTION">This is not tested here.</message>
+ <message name="IDS_POLICY_ENUMGROUP_DESC">This is not tested here.</message>
<message name="IDS_POLICY_ENUMPOLICY_CAPTION">This is not tested here.</message>
<message name="IDS_POLICY_ENUMPOLICY_DESC">This is not tested here.</message>
<message name="IDS_POLICY_ENUM_PROXYSERVERDISABLED_CAPTION">This is not tested here.</message>
@@ -235,9 +240,10 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
# be included in the plist file.
grd = self.PrepareTest('''
{
- 'policy_groups': [
+ 'policy_definitions': [
{
'name': 'NonMacGroup',
+ 'type': 'group',
'policies': [{
'name': 'NonMacPolicy',
'type': 'string',
@@ -248,9 +254,10 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'placeholders': [],
}''', '''
<messages>
- <message name="IDS_POLICY_GROUP_NONMACGROUP_CAPTION">This is not tested here. (1)</message>
- <message name="IDS_POLICY_GROUP_NONMACGROUP_DESC">This is not tested here. (2)</message>
+ <message name="IDS_POLICY_NONMACGROUP_CAPTION">This is not tested here. (1)</message>
+ <message name="IDS_POLICY_NONMACGROUP_DESC">This is not tested here. (2)</message>
<message name="IDS_POLICY_NONMACPOLICY_CAPTION">This is not tested here. (3)</message>
+ <message name="IDS_POLICY_NONMACPOLICY_DESC">This is not tested here. (4)</message>
</messages>
''' )
output = self.GetOutput(
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 fd31c90..4af1e458 100644
--- a/tools/grit/grit/format/policy_templates/writers/template_writer.py
+++ b/tools/grit/grit/format/policy_templates/writers/template_writer.py
@@ -69,7 +69,6 @@ class TemplateWriter(object):
'''
pass
-
def WriteTemplate(self, template):
'''Writes the given template definition.
@@ -81,14 +80,18 @@ class TemplateWriter(object):
'''
self.Init()
self.BeginTemplate()
- for group in template:
- policies = self._GetPoliciesForWriter(group)
- if policies:
- # Only write nonempty groups.
- self.BeginPolicyGroup(group)
- for policy in policies:
- self.WritePolicy(policy)
- self.EndPolicyGroup()
+ for policy in template:
+ if policy['type'] == 'group':
+ child_policies = self._GetPoliciesForWriter(policy)
+ if child_policies:
+ # Only write nonempty groups.
+ self.BeginPolicyGroup(policy)
+ for child_policy in child_policies:
+ # Nesting of groups is currently not supported.
+ self.WritePolicy(child_policy)
+ self.EndPolicyGroup()
+ else:
+ self.WritePolicy(policy)
self.EndTemplate()
return self.GetTemplateText()