summaryrefslogtreecommitdiffstats
path: root/tools/grit
diff options
context:
space:
mode:
authorgfeher@chromium.org <gfeher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-22 08:37:34 +0000
committergfeher@chromium.org <gfeher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-22 08:37:34 +0000
commit1b3e5390c3b3ad2e4ddc3dd6b3412e89332d07cd (patch)
treedbaa4020ce0597ec0be9682d29545aa09304ba5e /tools/grit
parentc2a7f433eef23f5711f8e80ca38d4661aa95e17f (diff)
downloadchromium_src-1b3e5390c3b3ad2e4ddc3dd6b3412e89332d07cd.zip
chromium_src-1b3e5390c3b3ad2e4ddc3dd6b3412e89332d07cd.tar.gz
chromium_src-1b3e5390c3b3ad2e4ddc3dd6b3412e89332d07cd.tar.bz2
Use 'Categories' instead of 'ADM policies' in ADM for related policies
This is necessary because the Windows Group Policy editor does not support setting a list to empty, but if the list is in a separate policy, then it can be set to disabled or not configured. BUG=55722 TEST=AdmWriterUnittest.* Review URL: http://codereview.chromium.org/3436013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60160 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/grit')
-rw-r--r--tools/grit/grit/format/policy_templates/writers/adm_writer.py89
-rw-r--r--tools/grit/grit/format/policy_templates/writers/adm_writer_unittest.py109
2 files changed, 157 insertions, 41 deletions
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 e3a079f..df3620c 100644
--- a/tools/grit/grit/format/policy_templates/writers/adm_writer.py
+++ b/tools/grit/grit/format/policy_templates/writers/adm_writer.py
@@ -25,6 +25,27 @@ 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')
@@ -55,32 +76,29 @@ class AdmWriter(template_writer.TemplateWriter):
self._PrintLine('SUPPORTED !!SUPPORTED_WINXPSP2')
self._PrintLine('#endif', -1)
- def WritePolicy(self, policy):
- policy_type = policy['type']
- policy_name = policy['name']
- if policy_type == 'main':
- self._PrintLine('VALUENAME "%s"' % policy_name )
- self._PrintLine('VALUEON NUMERIC 1')
- self._PrintLine('VALUEOFF NUMERIC 0')
- return
+ def _WritePart(self, policy):
+ '''Writes the PART ... END PART section of a policy.
- policy_part_name = policy_name + '_Part'
- self._AddGuiString(policy_part_name, policy['caption'])
+ 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._PrintLine()
# Print the PART ... END PART section:
- self._PrintLine(
- 'PART !!%s %s' % (policy_part_name, self.TYPE_TO_INPUT[policy_type]),
- 1)
- if policy_type == 'list':
+ self._PrintLine()
+ adm_type = self.TYPE_TO_INPUT[policy['type']]
+ self._PrintLine('PART !!%s %s' % (policy_part_name, adm_type), 1)
+ 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.config['win_reg_key_name'], policy_name))
+ (self.config['win_reg_key_name'], policy['name']))
self._PrintLine('VALUEPREFIX ""')
else:
- self._PrintLine('VALUENAME "%s"' % policy_name)
- if policy_type == 'enum':
+ self._PrintLine('VALUENAME "%s"' % policy['name'])
+ if policy['type'] == 'enum':
self._PrintLine('ITEMLIST', 1)
for item in policy['items']:
self._PrintLine('NAME !!%s_DropDown VALUE NUMERIC %s' %
@@ -89,19 +107,40 @@ class AdmWriter(template_writer.TemplateWriter):
self._PrintLine('END ITEMLIST', -1)
self._PrintLine('END PART', -1)
- def BeginPolicyGroup(self, group):
- group_explain_name = group['name'] + '_Explain'
- self._AddGuiString(group['name'] + '_Policy', group['caption'])
- self._AddGuiString(group_explain_name, group['desc'])
+ def WritePolicy(self, policy):
+ policy_desc = self._GetLocalizedPolicyMessage(policy, 'desc')
+ policy_caption = self._GetLocalizedPolicyMessage(policy, 'caption')
- self._PrintLine('POLICY !!%s_Policy' % group['name'], 1)
+ self._AddGuiString(policy['name'] + '_Policy', policy_caption)
+ self._PrintLine('POLICY !!%s_Policy' % policy['name'], 1)
self._WriteSupported()
- self._PrintLine('EXPLAIN !!' + group_explain_name)
+ policy_explain_name = policy['name'] + '_Explain'
+ self._AddGuiString(policy_explain_name, policy_desc)
+ self._PrintLine('EXPLAIN !!' + policy_explain_name)
+
+ if policy['type'] == 'main':
+ self._PrintLine('VALUENAME "%s"' % policy['name'])
+ self._PrintLine('VALUEON NUMERIC 1')
+ self._PrintLine('VALUEOFF NUMERIC 0')
+ else:
+ self._WritePart(policy)
- def EndPolicyGroup(self):
self._PrintLine('END POLICY', -1)
self._PrintLine()
+ def BeginPolicyGroup(self, group):
+ self._open_category = len(group['policies']) > 1
+ # Open a category for the policies if there is more than one in the
+ # group.
+ if self._open_category:
+ category_name = group['name'] + '_Category'
+ self._AddGuiString(category_name, group['caption'])
+ self._PrintLine('CATEGORY !!' + category_name, 1)
+
+ def EndPolicyGroup(self):
+ if self._open_category:
+ self._PrintLine('END CATEGORY', -1)
+
def BeginTemplate(self):
category_path = self.config['win_category_path']
self._AddGuiString(self.config['win_supported_os'],
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 c82abcb..1fa1b01 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
@@ -89,11 +89,11 @@ chromium="Chromium"'''
CATEGORY !!googlechrome
KEYNAME "Software\\Policies\\Google\\Chrome"
- POLICY !!MainGroup_Policy
+ POLICY !!MainPolicy_Policy
#if version >= 4
SUPPORTED !!SUPPORTED_WINXPSP2
#endif
- EXPLAIN !!MainGroup_Explain
+ EXPLAIN !!MainPolicy_Explain
VALUENAME "MainPolicy"
VALUEON NUMERIC 1
VALUEOFF NUMERIC 0
@@ -106,8 +106,8 @@ chromium="Chromium"'''
SUPPORTED_WINXPSP2="At least Windows 3.12"
google="Google"
googlechrome="Google Chrome"
-MainGroup_Policy="Caption of main."
-MainGroup_Explain="Description of main."'''
+MainPolicy_Policy="Caption of main."
+MainPolicy_Explain="Description of main."'''
self.CompareOutputs(output, expected_output)
def testStringPolicy(self):
@@ -139,11 +139,11 @@ With a newline.</message>
CATEGORY !!chromium
KEYNAME "Software\\Policies\\Chromium"
- POLICY !!StringGroup_Policy
+ POLICY !!StringPolicy_Policy
#if version >= 4
SUPPORTED !!SUPPORTED_WINXPSP2
#endif
- EXPLAIN !!StringGroup_Explain
+ EXPLAIN !!StringPolicy_Explain
PART !!StringPolicy_Part EDITTEXT
VALUENAME "StringPolicy"
@@ -155,8 +155,8 @@ With a newline.</message>
[Strings]
SUPPORTED_WINXPSP2="At least Windows 3.13"
chromium="Chromium"
-StringGroup_Policy="Caption of group."
-StringGroup_Explain="Description of group.\\nWith a newline."
+StringPolicy_Policy="Caption of policy."
+StringPolicy_Explain="Description of group.\\nWith a newline."
StringPolicy_Part="Caption of policy."
'''
self.CompareOutputs(output, expected_output)
@@ -197,11 +197,11 @@ StringPolicy_Part="Caption of policy."
CATEGORY !!googlechrome
KEYNAME "Software\\Policies\\Google\\Chrome"
- POLICY !!EnumGroup_Policy
+ POLICY !!EnumPolicy_Policy
#if version >= 4
SUPPORTED !!SUPPORTED_WINXPSP2
#endif
- EXPLAIN !!EnumGroup_Explain
+ EXPLAIN !!EnumPolicy_Explain
PART !!EnumPolicy_Part DROPDOWNLIST
VALUENAME "EnumPolicy"
@@ -219,8 +219,8 @@ StringPolicy_Part="Caption of policy."
SUPPORTED_WINXPSP2="At least Windows 3.14"
google="Google"
googlechrome="Google Chrome"
-EnumGroup_Policy="Caption of group."
-EnumGroup_Explain="Description of group."
+EnumPolicy_Policy="Caption of policy."
+EnumPolicy_Explain="Description of policy."
EnumPolicy_Part="Caption of policy."
ProxyServerDisabled_DropDown="Option1"
ProxyServerAutoDetect_DropDown="Option2"
@@ -256,11 +256,11 @@ With a newline.</message>
CATEGORY !!chromium
KEYNAME "Software\\Policies\\Chromium"
- POLICY !!ListGroup_Policy
+ POLICY !!ListPolicy_Policy
#if version >= 4
SUPPORTED !!SUPPORTED_WINXPSP2
#endif
- EXPLAIN !!ListGroup_Explain
+ EXPLAIN !!ListPolicy_Explain
PART !!ListPolicy_Part LISTBOX
KEYNAME "Software\\Policies\\Chromium\\ListPolicy"
@@ -273,8 +273,8 @@ With a newline.</message>
[Strings]
SUPPORTED_WINXPSP2="At least Windows 3.15"
chromium="Chromium"
-ListGroup_Policy="Caption of list group."
-ListGroup_Explain="Description of list group.\\nWith a newline."
+ListPolicy_Policy="Caption of list policy."
+ListPolicy_Explain="Description of list group.\\nWith a newline."
ListPolicy_Part="Caption of list policy."
'''
self.CompareOutputs(output, expected_output)
@@ -316,5 +316,82 @@ chromium="Chromium"
'''
self.CompareOutputs(output, expected_output)
+ def testPolicyGroup(self):
+ # Tests a policy group that has more than one policies.
+ grd = self.PrepareTest('''
+ {
+ 'policy_groups': [
+ {
+ 'name': 'Group1',
+ 'policies': [{
+ 'name': 'Policy1',
+ 'type': 'list',
+ 'annotations': {'platforms': ['win']}
+ },{
+ 'name': 'Policy2',
+ 'type': 'string',
+ 'annotations': {'platforms': ['win']}
+ }],
+ },
+ ],
+ '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_POLICY1_DESC">Description of policy1.
+With a newline.</message>
+ <message name="IDS_POLICY_POLICY2_DESC">Description of policy2.
+With a newline.</message>
+ <message name="IDS_POLICY_POLICY1_CAPTION">Caption of policy1.</message>
+ <message name="IDS_POLICY_POLICY2_CAPTION">Caption of policy2.</message>
+ <message name="IDS_POLICY_WIN_SUPPORTED_WINXPSP2">At least Windows 3.16</message>
+ </messages>
+ ''')
+ output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'adm', 'en')
+ expected_output = '''CLASS MACHINE
+ CATEGORY !!chromium
+ KEYNAME "Software\\Policies\\Chromium"
+
+ CATEGORY !!Group1_Category
+ POLICY !!Policy1_Policy
+ #if version >= 4
+ SUPPORTED !!SUPPORTED_WINXPSP2
+ #endif
+ EXPLAIN !!Policy1_Explain
+
+ PART !!Policy1_Part LISTBOX
+ KEYNAME "Software\\Policies\\Chromium\\Policy1"
+ VALUEPREFIX ""
+ END PART
+ END POLICY
+
+ POLICY !!Policy2_Policy
+ #if version >= 4
+ SUPPORTED !!SUPPORTED_WINXPSP2
+ #endif
+ EXPLAIN !!Policy2_Explain
+
+ PART !!Policy2_Part EDITTEXT
+ VALUENAME "Policy2"
+ END PART
+ END POLICY
+
+ END CATEGORY
+ END CATEGORY
+
+[Strings]
+SUPPORTED_WINXPSP2="At least Windows 3.16"
+chromium="Chromium"
+Group1_Category="Caption of group."
+Policy1_Policy="Caption of policy1."
+Policy1_Explain="Description of policy1.\\nWith a newline."
+Policy1_Part="Caption of policy1."
+Policy2_Policy="Caption of policy2."
+Policy2_Explain="Description of policy2.\\nWith a newline."
+Policy2_Part="Caption of policy2."
+'''
+ self.CompareOutputs(output, expected_output)
+
if __name__ == '__main__':
unittest.main()