diff options
author | gfeher@chromium.org <gfeher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-18 09:26:00 +0000 |
---|---|---|
committer | gfeher@chromium.org <gfeher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-18 09:26:00 +0000 |
commit | 8a4c938f3a096ab1cc4a9f29a63b75f2df7c16a7 (patch) | |
tree | 6dba6c86b249801a090d298a11fa767c890caa09 /tools | |
parent | a894250823ff98c8856bb71f7c8c6e05b521094e (diff) | |
download | chromium_src-8a4c938f3a096ab1cc4a9f29a63b75f2df7c16a7.zip chromium_src-8a4c938f3a096ab1cc4a9f29a63b75f2df7c16a7.tar.gz chromium_src-8a4c938f3a096ab1cc4a9f29a63b75f2df7c16a7.tar.bz2 |
Add version information to the policy templates
Add for each policy the version number of Chrome when is was introduced.
Update platform-based policy filtering to use the new template format (no
new logic introduced.) Update the HTML documentation writer to use the new
version numbers.
BUG=62500
TEST=PolicyTemplateGeneratorUnittest.testPolicyFiltering,DocWriterUnittest.testAddPolicyDetails,DocWriterUnittest.testAddPolicySection
Review URL: http://codereview.chromium.org/4704006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66601 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools')
11 files changed, 192 insertions, 87 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 a678ef1..3b2447e 100644 --- a/tools/grit/grit/format/policy_templates/policy_template_generator.py +++ b/tools/grit/grit/format/policy_templates/policy_template_generator.py @@ -3,6 +3,9 @@ # found in the LICENSE file. +import copy + + def GetPolicySortingKey(policy): '''Extracts a sorting key from a policy. These keys can be used for list.sort() methods to sort policies. @@ -42,10 +45,10 @@ class PolicyTemplateGenerator: content. ''' # List of all the policies: - self._policy_definitions = policy_definitions + self._policy_definitions = copy.deepcopy(policy_definitions) # Localized messages to be inserted to the policy_definitions structure: self._messages = messages - self._AddMessagesToPolicyList(self._policy_definitions) + self._ProcessPolicyList(self._policy_definitions) self._SortPolicies(self._policy_definitions) def _SortPolicies(self, policy_list): @@ -59,6 +62,56 @@ class PolicyTemplateGenerator: ''' policy_list.sort(key=GetPolicySortingKey) + def _ProcessSupportedOn(self, supported_on): + '''Parses and converts the string items of the list of supported platforms + into dictionaries. + + Args: + supported_on: The list of supported platforms. E.g.: + ['chrome.win:8-10', 'chrome_frame:10-'] + + Returns: + supported_on: The list with its items converted to dictionaries. E.g.: + [{ + 'product': 'chrome', + 'platform': 'win', + 'since_version': '8', + 'until_version': '10' + }, { + 'product': 'chrome_frame', + 'platform': 'win', + 'since_version': '10', + 'until_version': '' + }] + ''' + result = [] + for supported_on_item in supported_on: + product_platform_part, version_part = supported_on_item.split(':') + if '.' in product_platform_part: + product, platform = product_platform_part.split('.') + if platform == '*': + # e.g.: 'chrome.*:8-10' + platforms = ['linux', 'mac', 'win'] + else: + # e.g.: 'chrome.win:-10' + platforms = [platform] + else: + # e.g.: 'chrome_frame:7-' + product = product_platform_part + platform = { + 'chrome_os': 'chrome_os', + 'chrome_frame': 'win' + }[product] + platforms = [platform] + since_version, until_version = version_part.split('-') + result.append({ + 'product': product, + 'platforms': platforms, + 'since_version': since_version, + 'until_version': until_version + }) + return result + def _AddMessageToItem(self, item_name, item, message_name, default=None): '''Adds a localized message string to an item of the policy data structure @@ -85,8 +138,9 @@ class PolicyTemplateGenerator: raise Exception('No localized message for %s (missing %s).' % (item_name, long_message_name)) - def _AddMessagesToPolicy(self, policy): + def _ProcessPolicy(self, policy): '''Adds localized message strings to a policy or group. + Also breaks up the content of 'supported_on' attribute into a list. Args: policy: The data structure of the policy or group, that will get message @@ -99,23 +153,26 @@ class PolicyTemplateGenerator: # 'label', that defaults to 'caption'. self._AddMessageToItem( policy['name'], policy, 'label', policy['caption']) + policy['supported_on'] = self._ProcessSupportedOn( + policy['supported_on']) if policy['type'] == 'group': - self._AddMessagesToPolicyList(policy['policies']) + self._ProcessPolicyList(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._AddMessageToItem('ENUM_' + item['name'], item, 'caption') - def _AddMessagesToPolicyList(self, policy_list): + def _ProcessPolicyList(self, policy_list): '''Adds localized message strings to each item in a list of policies and - groups. + groups. Also breaks up the content of 'supported_on' attributes into lists + of dictionaries. Args: policy_list: A list of policies and groups. Message strings will be added for each item and to their child items, recursively. ''' for policy in policy_list: - self._AddMessagesToPolicy(policy) + self._ProcessPolicy(policy) def GetTemplateText(self, template_writer): '''Generates the text of the template from the arguments given 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 7401a6d..5a73cf72 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 @@ -97,15 +97,15 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase): policies_mock = [ { 'name': 'Group1', 'type': 'group', - 'policies': [{'name': 'TAG1', 'type': 'mock'}] + 'policies': [{'name': 'TAG1', 'type': 'mock', 'supported_on': []}] }, { 'name': 'Group2', 'type': 'group', - 'policies': [{'name': 'TAG2', 'type': 'mock'}] + 'policies': [{'name': 'TAG2', 'type': 'mock', 'supported_on': []}] }, { 'name': 'Group3', 'type': 'group', - 'policies': [{'name': 'TAG3', 'type': 'mock'}] + 'policies': [{'name': 'TAG3', 'type': 'mock', 'supported_on': []}] }, ] class LocalMockWriter(mock_writer.MockWriter): @@ -150,15 +150,15 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase): 'name': 'Group1', 'type': 'group', 'policies': [ - {'name': 'Group1Policy1', 'type': 'string'}, - {'name': 'Group1Policy2', 'type': 'string'}, + {'name': 'Group1Policy1', 'type': 'string', 'supported_on': []}, + {'name': 'Group1Policy2', 'type': 'string', 'supported_on': []}, ] }, { 'name': 'Group2', 'type': 'group', 'policies': [ - {'name': 'Group2Policy3', 'type': 'string'}, + {'name': 'Group2Policy3', 'type': 'string', 'supported_on': []}, ] } ] @@ -194,8 +194,8 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase): 'name': 'Group1', 'type': 'group', 'policies': [ - {'name': 'Policy1', 'type': 'string'}, - {'name': 'Policy2', 'type': 'string'} + {'name': 'Policy1', 'type': 'string', 'supported_on': []}, + {'name': 'Policy2', 'type': 'string', 'supported_on': []} ] } ] @@ -225,6 +225,7 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase): policy_defs_mock = [{ 'name': 'Policy1', 'type': 'enum', + 'supported_on': [], 'items': [ {'name': 'item1', 'value': '0'}, {'name': 'item2', 'value': '1'}, @@ -248,12 +249,12 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase): { 'name': 'Group1Policy1', 'type': 'string', - 'annotations': {'platforms': ['aaa', 'bbb', 'ccc']} + 'supported_on': ['chrome.aaa:8-', 'chrome.bbb:8-', 'chrome.ccc:8-'] }, { 'name': 'Group1Policy2', 'type': 'string', - 'annotations': {'platforms': ['ddd']} + 'supported_on': ['chrome.ddd:8-'] }, ] },{ @@ -263,13 +264,13 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase): { 'name': 'Group2Policy3', 'type': 'string', - 'annotations': {'platforms': ['eee']} + 'supported_on': ['chrome.eee:8-'] }, ] },{ 'name': 'SinglePolicy', 'type': 'int', - 'annotations': {'platforms': ['eee']} + 'supported_on': ['chrome.eee:8-'] }] # This writer accumulates the list of policies it is asked to write. # This list is stored in the result_list member variable and can @@ -308,42 +309,42 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase): def testSorting(self): # Tests that policies are sorted correctly. policy_defs = [ - {'name': 'zp', 'type': 'string', 'caption': 'a1'}, + {'name': 'zp', 'type': 'string', 'caption': 'a1', 'supported_on': []}, { 'type': 'group', 'caption': 'z_group1_caption', 'name': 'group1', 'policies': [ - {'name': 'z0', 'type': 'string'}, - {'name': 'a0', 'type': 'string'} + {'name': 'z0', 'type': 'string', 'supported_on': []}, + {'name': 'a0', 'type': 'string', 'supported_on': []} ] }, { 'type': 'group', 'caption': 'b_group2_caption', 'name': 'group2', - 'policies': [{'name': 'q', 'type': 'string'}], + 'policies': [{'name': 'q', 'type': 'string', 'supported_on': []}], }, - {'name': 'ap', 'type': 'string', 'caption': 'a2'} + {'name': 'ap', 'type': 'string', 'caption': 'a2', 'supported_on': []} ] sorted_policy_defs = [ { 'type': 'group', 'caption': 'b_group2_caption', 'name': 'group2', - 'policies': [{'name': 'q', 'type': 'string'}], + 'policies': [{'name': 'q', 'type': 'string', 'supported_on': []}], }, { 'type': 'group', 'caption': 'z_group1_caption', 'name': 'group1', 'policies': [ - {'name': 'z0', 'type': 'string'}, - {'name': 'a0', 'type': 'string'} + {'name': 'z0', 'type': 'string', 'supported_on': []}, + {'name': 'a0', 'type': 'string', 'supported_on': []} ] }, - {'name': 'ap', 'type': 'string', 'caption': 'a2'}, - {'name': 'zp', 'type': 'string', 'caption': 'a1'}, + {'name': 'ap', 'type': 'string', 'caption': 'a2', 'supported_on': []}, + {'name': 'zp', 'type': 'string', 'caption': 'a1', 'supported_on': []}, ] ptg = policy_template_generator.PolicyTemplateGenerator([], []) ptg._SortPolicies(policy_defs) @@ -354,8 +355,8 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase): def testSortingInvoked(self): # Tests that policy-sorting happens before passing policies to the writer. policy_defs = [ - {'name': 'zp', 'type': 'string'}, - {'name': 'ap', 'type': 'string'} + {'name': 'zp', 'type': 'string', 'supported_on': []}, + {'name': 'ap', 'type': 'string', 'supported_on': []} ] class LocalMockWriter(mock_writer.MockWriter): def __init__(self): 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 6c75d2b..b823aae 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 @@ -69,7 +69,7 @@ chromium="Chromium"''' { 'name': 'MainPolicy', 'type': 'main', - 'annotations': {'platforms': ['win']} + 'supported_on': ['chrome.win:8-'] }, ], 'placeholders': [], @@ -115,7 +115,7 @@ MainPolicy_Explain="Description of main."''' { 'name': 'StringPolicy', 'type': 'string', - 'annotations': {'platforms': ['win']} + 'supported_on': ['chrome.win:8-'] }, ], 'placeholders': [], @@ -166,7 +166,7 @@ StringPolicy_Part="Caption of policy." {'name': 'ProxyServerDisabled', 'value': '0'}, {'name': 'ProxyServerAutoDetect', 'value': '1'}, ], - 'annotations': {'platforms': ['win']} + 'supported_on': ['chrome.win:8-'] }, ], 'placeholders': [], @@ -223,7 +223,7 @@ ProxyServerAutoDetect_DropDown="Option2" { 'name': 'ListPolicy', 'type': 'list', - 'annotations': {'platforms': ['win']} + 'supported_on': ['chrome.win:8-'] }, ], 'placeholders': [], @@ -276,7 +276,7 @@ ListPolicy_Part="Value caption of list policy." 'policies': [{ 'name': 'NonWinPolicy', 'type': 'list', - 'annotations': {'platforms': ['linux', 'mac']} + 'supported_on': ['chrome.linux:8-', 'chrome.mac:8-'] }], }, ], @@ -314,11 +314,11 @@ chromium="Chromium" 'policies': [{ 'name': 'Policy1', 'type': 'list', - 'annotations': {'platforms': ['win']} + 'supported_on': ['chrome.win:8-'] },{ 'name': 'Policy2', 'type': 'string', - 'annotations': {'platforms': ['win']} + 'supported_on': ['chrome.win:8-'] }], }, ], diff --git a/tools/grit/grit/format/policy_templates/writers/adml_writer_unittest.py b/tools/grit/grit/format/policy_templates/writers/adml_writer_unittest.py index 04a16f5..dd4d42e 100644 --- a/tools/grit/grit/format/policy_templates/writers/adml_writer_unittest.py +++ b/tools/grit/grit/format/policy_templates/writers/adml_writer_unittest.py @@ -242,14 +242,14 @@ class AdmlWriterTest(xml_writer_base_unittest.XmlWriterBaseTest): def testPlatform(self): # Test that the writer correctly chooses policies of platform Windows. self.assertTrue(self.writer.IsPolicySupported({ - 'annotations': { - 'platforms': ['win', 'zzz', 'aaa'] - } + 'supported_on': [ + {'platforms': ['win', 'zzz']}, {'platforms': ['aaa']} + ] })) self.assertFalse(self.writer.IsPolicySupported({ - 'annotations': { - 'platforms': ['mac', 'linux', 'aaa'] - } + 'supported_on': [ + {'platforms': ['mac', 'linux']}, {'platforms': ['aaa']} + ] })) diff --git a/tools/grit/grit/format/policy_templates/writers/admx_writer_unittest.py b/tools/grit/grit/format/policy_templates/writers/admx_writer_unittest.py index b964a25..c645be0 100644 --- a/tools/grit/grit/format/policy_templates/writers/admx_writer_unittest.py +++ b/tools/grit/grit/format/policy_templates/writers/admx_writer_unittest.py @@ -264,14 +264,14 @@ class AdmxWriterTest(xml_writer_base_unittest.XmlWriterBaseTest): def testPlatform(self): # Test that the writer correctly chooses policies of platform Windows. self.assertTrue(self.writer.IsPolicySupported({ - 'annotations': { - 'platforms': ['win', 'zzz', 'aaa'] - } + 'supported_on': [ + {'platforms': ['win', 'zzz']}, {'platforms': ['aaa']} + ] })) self.assertFalse(self.writer.IsPolicySupported({ - 'annotations': { - 'platforms': ['mac', 'linux', 'aaa'] - } + 'supported_on': [ + {'platforms': ['mac', 'linux']}, {'platforms': ['aaa']} + ] })) 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 279f374..1f4afe7 100644 --- a/tools/grit/grit/format/policy_templates/writers/doc_writer.py +++ b/tools/grit/grit/format/policy_templates/writers/doc_writer.py @@ -14,7 +14,7 @@ def GetWriter(config, messages): See the constructor of TemplateWriter for description of arguments. ''' - return DocWriter(['mac', 'linux', 'win'], config, messages) + return DocWriter(['*'], config, messages) class DocWriter(xml_formatted_writer.XMLFormattedWriter): @@ -286,6 +286,32 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter): self._AddStyledElement(dl, 'dt', ['dt'], {}, term) return self._AddStyledElement(dl, 'dd', definition_style, {}, definition) + def _AddSupportedOnList(self, parent, supported_on_list): + '''Creates a HTML list containing the platforms, products and versions + that are specified in the list of supported_on. + + Args: + parent: The DOM node for which the list will be added. + supported_on_list: The list of supported products, as a list of + dictionaries. + ''' + ul = self._AddStyledElement(parent, 'ul', ['ul']) + for supported_on in supported_on_list: + text = [] + product = supported_on['product'] + platforms = supported_on['platforms'] + text.append(self._PRODUCT_MAP[product]) + text.append('(%s)' % + self._MapListToString(self._PLATFORM_MAP, platforms)) + if supported_on['since_version']: + since_version = self._GetLocalizedMessage('since_version') + text.append(since_version.replace('$6', supported_on['since_version'])) + if supported_on['until_version']: + until_version = self._GetLocalizedMessage('until_version') + text.append(until_version.replace('$6', supported_on['until_version'])) + # Add the list element: + self.AddElement(ul, 'li', {}, ' '.join(text)) + def _AddPolicyDetails(self, parent, policy): '''Adds the list of attributes of a policy to the HTML DOM node parent. It will have the form: @@ -315,14 +341,8 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter): 'mac_linux_pref_name', policy['name'], ['.monospace']) - self._AddPolicyAttribute( - dl, - 'supported_on_platforms', - self._MapListToString(self._PLATFORM_MAP, annotations['platforms'])) - self._AddPolicyAttribute( - dl, - 'supported_in_products', - self._MapListToString(self._PRODUCT_MAP, annotations['products'])) + dd = self._AddPolicyAttribute(dl, 'supported_on') + self._AddSupportedOnList(dd, policy['supported_on']) dd = self._AddPolicyAttribute(dl, 'supported_features') self._AddFeatures(dd, policy) dd = self._AddPolicyAttribute(dl, 'description') @@ -491,6 +511,7 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter): '.pre': 'white-space: pre;', 'div.note': 'border: 2px solid black; padding: 5px; margin: 5px;', 'div.group_desc': 'margin-top: 20px; margin-bottom: 20px;', + 'ul': 'padding-left: 0px; margin-left: 0px;' } # A simple regexp to search for URLs. It is enough for now. 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 15ccc68..8f1ec8c 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 @@ -283,13 +283,18 @@ MockKey\\PolicyName\\1 = "Bar"</dd><dt>Linux:</dt><dd style="style_.mo 'name': 'TestPolicyName', 'caption': 'TestPolicyCaption', 'desc': 'TestPolicyDesc', - 'annotations': { + 'supported_on': [{ + 'product': 'chrome', 'platforms': ['win'], - 'products': ['chrome'], + 'since_version': '8', + 'until_version': '', + }], + 'annotations': { 'features': {'dynamic_refresh': 0}, 'example_value': False } } + self.writer.messages.msg_dict['since_version'] = '...$6...' self.writer._AddPolicyDetails(self.doc_root, policy) self.assertEquals( self.doc_root.toxml(), @@ -299,8 +304,12 @@ MockKey\\PolicyName\\1 = "Bar"</dd><dt>Linux:</dt><dd style="style_.mo '<dd style="style_.monospace;">MockKey\TestPolicyName</dd>' '<dt style="style_dt;">_test_mac_linux_pref_name</dt>' '<dd style="style_.monospace;">TestPolicyName</dd>' - '<dt style="style_dt;">_test_supported_on_platforms</dt><dd>Windows</dd>' - '<dt style="style_dt;">_test_supported_in_products</dt><dd>Chrome</dd>' + '<dt style="style_dt;">_test_supported_on</dt>' + '<dd>' + '<ul style="style_ul;">' + '<li>Chrome (Windows) ...8...</li>' + '</ul>' + '</dd>' '<dt style="style_dt;">_test_supported_features</dt>' '<dd>Dynamic Policy Refresh: _test_not_supported</dd>' '<dt style="style_dt;">_test_description</dt><dd>TestPolicyDesc</dd>' @@ -363,13 +372,18 @@ MockKey\\PolicyName\\1 = "Bar"</dd><dt>Linux:</dt><dd style="style_.mo 'caption': 'PolicyCaption', 'desc': 'PolicyDesc', 'type': 'string', - 'annotations': { + 'supported_on': [{ + 'product': 'chrome', 'platforms': ['win'], - 'products': ['chrome'], + 'since_version': '7', + 'until_version': '', + }], + 'annotations': { 'features': {'dynamic_refresh': 0}, 'example_value': False } } + self.writer.messages.msg_dict['since_version'] = '..$6..' self.writer._AddPolicySection(self.doc_root, policy) self.assertEquals( self.doc_root.toxml(), @@ -384,10 +398,12 @@ MockKey\\PolicyName\\1 = "Bar"</dd><dt>Linux:</dt><dd style="style_.mo '<dd style="style_.monospace;">MockKey\\PolicyName</dd>' '<dt style="style_dt;">_test_mac_linux_pref_name</dt>' '<dd style="style_.monospace;">PolicyName</dd>' - '<dt style="style_dt;">_test_supported_on_platforms</dt>' - '<dd>Windows</dd>' - '<dt style="style_dt;">_test_supported_in_products</dt>' - '<dd>Chrome</dd>' + '<dt style="style_dt;">_test_supported_on</dt>' + '<dd>' + '<ul style="style_ul;">' + '<li>Chrome (Windows) ..7..</li>' + '</ul>' + '</dd>' '<dt style="style_dt;">_test_supported_features</dt>' '<dd>Dynamic Policy Refresh: _test_not_supported</dd>' '<dt style="style_dt;">_test_description</dt>' diff --git a/tools/grit/grit/format/policy_templates/writers/json_writer_unittest.py b/tools/grit/grit/format/policy_templates/writers/json_writer_unittest.py index 35d84f0..bce4c87 100644 --- a/tools/grit/grit/format/policy_templates/writers/json_writer_unittest.py +++ b/tools/grit/grit/format/policy_templates/writers/json_writer_unittest.py @@ -52,8 +52,8 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon): ' {' ' "name": "MainPolicy",' ' "type": "main",' + ' "supported_on": ["chrome.linux:8-"],' ' "annotations": {' - ' "platforms": ["linux"],' ' "example_value": True' ' }' ' },' @@ -79,8 +79,8 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon): ' {' ' "name": "StringPolicy",' ' "type": "string",' + ' "supported_on": ["chrome.linux:8-"],' ' "annotations": {' - ' "platforms": ["linux"],' ' "example_value": "hello, world!"' ' }' ' },' @@ -110,8 +110,8 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon): ' {"name": "ProxyServerDisabled", "value": "0"},' ' {"name": "ProxyServerAutoDetect", "value": "1"},' ' ],' + ' "supported_on": ["chrome.linux:8-"],' ' "annotations": {' - ' "platforms": ["linux"],' ' "example_value": "1"' ' }' ' },' @@ -141,8 +141,8 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon): ' {' ' "name": "ListPolicy",' ' "type": "list",' + ' "supported_on": ["chrome.linux:8-"],' ' "annotations": {' - ' "platforms": ["linux"],' ' "example_value": ["foo", "bar"]' ' }' ' },' @@ -170,8 +170,8 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon): ' {' ' "name": "NonLinuxPolicy",' ' "type": "list",' + ' "supported_on": ["chrome.mac:8-"],' ' "annotations": {' - ' "platforms": ["win"],' ' "example_value": ["a"]' ' }' ' },' @@ -197,15 +197,15 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon): ' "policies": [{' ' "name": "Policy1",' ' "type": "list",' + ' "supported_on": ["chrome.linux:8-"],' ' "annotations": {' - ' "platforms": ["linux"],' ' "example_value": ["a", "b"]' ' }' ' },{' ' "name": "Policy2",' ' "type": "string",' + ' "supported_on": ["chrome.linux:8-"],' ' "annotations": {' - ' "platforms": ["linux"],' ' "example_value": "c"' ' }' ' }],' 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 6df8f84..1fc19c8 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 @@ -57,7 +57,7 @@ class PListStringsWriterUnittest(writer_unittest_common.WriterUnittestCommon): 'policies': [{ 'name': 'MainPolicy', 'type': 'main', - 'annotations': {'platforms': ['mac']}, + 'supported_on': ['chrome.mac:8-'], }], }, ], @@ -96,7 +96,7 @@ class PListStringsWriterUnittest(writer_unittest_common.WriterUnittestCommon): 'policies': [{ 'name': 'StringPolicy', 'type': 'string', - 'annotations': {'platforms': ['mac']}, + 'supported_on': ['chrome.mac:8-'], }], }, ], @@ -141,7 +141,7 @@ With a newline.</message> {'name': 'ProxyServerDisabled', 'value': '0'}, {'name': 'ProxyServerAutoDetect', 'value': '1'}, ], - 'annotations': {'platforms': ['mac']}, + 'supported_on': ['chrome.mac:8-'], }], }, ], @@ -184,7 +184,7 @@ With a newline.</message> 'policies': [{ 'name': 'NonMacPolicy', 'type': 'string', - 'annotations': {'platforms': ['win', 'linux']}, + 'supported_on': ['chrome_os:8-'], }], }, ], 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 bcebcaa..88240cd 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 @@ -88,7 +88,7 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon): 'policies': [{ 'name': 'MainPolicy', 'type': 'main', - 'annotations': {'platforms': ['mac']}, + 'supported_on': ['chrome.mac:8-'], }], }, ], @@ -137,7 +137,7 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon): 'policies': [{ 'name': 'StringPolicy', 'type': 'string', - 'annotations': {'platforms': ['mac']}, + 'supported_on': ['chrome.mac:8-'], }], }, ], @@ -190,7 +190,7 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon): {'name': 'ProxyServerDisabled', 'value': '0'}, {'name': 'ProxyServerAutoDetect', 'value': '1'}, ], - 'annotations': {'platforms': ['mac']}, + 'supported_on': ['chrome.mac:8-'], }], }, ], @@ -247,7 +247,7 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon): 'policies': [{ 'name': 'NonMacPolicy', 'type': 'string', - 'annotations': {'platforms': ['win', 'linux']}, + 'supported_on': ['chrome.linux:8-', 'chrome.win:7-'], }], }, ], 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 aa4f233..8b742d5 100644 --- a/tools/grit/grit/format/policy_templates/writers/template_writer.py +++ b/tools/grit/grit/format/policy_templates/writers/template_writer.py @@ -3,6 +3,9 @@ # found in the LICENSE file. +import itertools + + class TemplateWriter(object): '''Abstract base class for writing policy templates in various formats. The methods of this class will be called by PolicyTemplateGenerator. @@ -32,6 +35,9 @@ class TemplateWriter(object): def IsPolicySupported(self, policy): '''Checks if the given policy is supported by the writer. + In other words, the set of platforms supported by the writer + has a common subset with the set of platforms that support + the policy. Args: policy: The dictionary of the policy. @@ -39,9 +45,13 @@ class TemplateWriter(object): Returns: True if the writer chooses to include 'policy' in its output. ''' - for platform in self.platforms: - if platform in policy['annotations']['platforms']: - return True + if '*' in self.platforms: + # Currently chrome_os is only catched here. + return True + for supported_on in policy['supported_on']: + for supported_on_platform in supported_on['platforms']: + if supported_on_platform in self.platforms: + return True return False def _GetPoliciesForWriter(self, group): |