diff options
author | gfeher@chromium.org <gfeher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-01 10:21:32 +0000 |
---|---|---|
committer | gfeher@chromium.org <gfeher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-01 10:21:32 +0000 |
commit | 0170c8ebcccc6da30b8fbc67df32fc39da63c536 (patch) | |
tree | 6a41f69f05fce83c3932d2c66098cb6fe6ede10c /tools/grit | |
parent | 72a0f06d9a3c375c6328d6cccf2b0c7685043c7d (diff) | |
download | chromium_src-0170c8ebcccc6da30b8fbc67df32fc39da63c536.zip chromium_src-0170c8ebcccc6da30b8fbc67df32fc39da63c536.tar.gz chromium_src-0170c8ebcccc6da30b8fbc67df32fc39da63c536.tar.bz2 |
Shorten the name of policy groups and sort them by caption
Also add Chromium vs Google Chrome clarification at the beginning of the generated policy documentation and remove ADM outputs with pseudo-translations.
BUG=None
TEST=manual
Review URL: http://codereview.chromium.org/3605003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61163 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/grit')
-rw-r--r-- | tools/grit/grit/format/policy_templates/policy_template_generator.py | 25 | ||||
-rw-r--r-- | tools/grit/grit/format/policy_templates/policy_template_generator_unittest.py | 20 |
2 files changed, 32 insertions, 13 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 10ffa9b..a678ef1 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,22 @@ # found in the LICENSE file. +def GetPolicySortingKey(policy): + '''Extracts a sorting key from a policy. These keys can be used for + list.sort() methods to sort policies. + See PolicyTemplateGenerator._SortPolicies for usage. + ''' + is_group = policy['type'] == 'group' + if is_group: + # Groups are sorted by caption. + str_key = policy['caption'] + else: + # Regular policies are sorted by name. + str_key = policy['name'] + # Groups come before regular policies. + return (not is_group, str_key) + + class PolicyTemplateGenerator: '''Generates template text for a particular platform. @@ -29,20 +45,19 @@ class PolicyTemplateGenerator: self._policy_definitions = policy_definitions # Localized messages to be inserted to the policy_definitions structure: self._messages = messages - self._SortPolicies(self._policy_definitions) self._AddMessagesToPolicyList(self._policy_definitions) + self._SortPolicies(self._policy_definitions) def _SortPolicies(self, policy_list): '''Sorts a list of policies in-place alphabetically. The order is the - following: first groups alphabetically (a-z), then other policies - alphabetically (a-z). The order of policies inside groups is unchanged. + following: first groups alphabetically by caption, then other policies + alphabetically by name. The order of policies inside groups is unchanged. Args: policy_list: The list of policies to sort. Sub-lists in groups will not be sorted. ''' - policy_list.sort( - key=lambda(policy): (policy['type'] != 'group', policy['name'])) + policy_list.sort(key=GetPolicySortingKey) def _AddMessageToItem(self, item_name, item, message_name, default=None): '''Adds a localized message string to an item of the policy data structure 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 fdc0a14..83738ad 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 @@ -302,10 +302,11 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase): def testSorting(self): # Tests that policies are sorted correctly. policy_defs = [ - {'name': 'zp', 'type': 'string'}, + {'name': 'zp', 'type': 'string', 'caption': 'a1'}, { 'type': 'group', - 'name': 'zg', + 'caption': 'z_group1_caption', + 'name': 'group1', 'policies': [ {'name': 'z0', 'type': 'string'}, {'name': 'a0', 'type': 'string'} @@ -313,27 +314,30 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase): }, { 'type': 'group', - 'name': 'ag', + 'caption': 'b_group2_caption', + 'name': 'group2', 'policies': [{'name': 'q', 'type': 'string'}], }, - {'name': 'ap', 'type': 'string'} + {'name': 'ap', 'type': 'string', 'caption': 'a2'} ] sorted_policy_defs = [ { 'type': 'group', - 'name': 'ag', + 'caption': 'b_group2_caption', + 'name': 'group2', 'policies': [{'name': 'q', 'type': 'string'}], }, { 'type': 'group', - 'name': 'zg', + 'caption': 'z_group1_caption', + 'name': 'group1', 'policies': [ {'name': 'z0', 'type': 'string'}, {'name': 'a0', 'type': 'string'} ] }, - {'name': 'ap', 'type': 'string'}, - {'name': 'zp', 'type': 'string'}, + {'name': 'ap', 'type': 'string', 'caption': 'a2'}, + {'name': 'zp', 'type': 'string', 'caption': 'a1'}, ] ptg = policy_template_generator.PolicyTemplateGenerator([], []) ptg._SortPolicies(policy_defs) |