| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 | 6 |
| 7 import json | 7 import json |
| 8 | 8 |
| 9 from grit.format.policy_templates.writers import template_writer | 9 from grit.format.policy_templates.writers import template_writer |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 def PreprocessPolicies(self, policy_list): | 41 def PreprocessPolicies(self, policy_list): |
| 42 return self.FlattenGroupsAndSortPolicies(policy_list, | 42 return self.FlattenGroupsAndSortPolicies(policy_list, |
| 43 self.GetPolicySortingKey) | 43 self.GetPolicySortingKey) |
| 44 | 44 |
| 45 def GetPolicySortingKey(self, policy): | 45 def GetPolicySortingKey(self, policy): |
| 46 '''Extracts a sorting key from a policy. These keys can be used for | 46 '''Extracts a sorting key from a policy. These keys can be used for |
| 47 list.sort() methods to sort policies. | 47 list.sort() methods to sort policies. |
| 48 See TemplateWriter.SortPoliciesGroupsFirst for usage. | 48 See TemplateWriter.SortPoliciesGroupsFirst for usage. |
| 49 ''' | 49 ''' |
| 50 is_list = policy['type'] == 'list' | 50 is_list = policy['type'] in ('list', 'string-enum-list') |
| 51 # Lists come after regular policies. | 51 # Lists come after regular policies. |
| 52 return (is_list, policy['name']) | 52 return (is_list, policy['name']) |
| 53 | 53 |
| 54 def _WritePolicy(self, policy, key, list): | 54 def _WritePolicy(self, policy, key, list): |
| 55 example_value = policy['example_value'] | 55 example_value = policy['example_value'] |
| 56 | 56 |
| 57 if policy['type'] == 'external': | 57 if policy['type'] == 'external': |
| 58 # This type can only be set through cloud policy. | 58 # This type can only be set through cloud policy. |
| 59 return | 59 return |
| 60 elif policy['type'] == 'list': | 60 elif policy['type'] in ('list', 'string-enum-list'): |
| 61 self._StartBlock(key, policy['name'], list) | 61 self._StartBlock(key, policy['name'], list) |
| 62 i = 1 | 62 i = 1 |
| 63 for item in example_value: | 63 for item in example_value: |
| 64 escaped_str = self._EscapeRegString(item) | 64 escaped_str = self._EscapeRegString(item) |
| 65 list.append('"%d"="%s"' % (i, escaped_str)) | 65 list.append('"%d"="%s"' % (i, escaped_str)) |
| 66 i = i + 1 | 66 i = i + 1 |
| 67 else: | 67 else: |
| 68 self._StartBlock(key, None, list) | 68 self._StartBlock(key, None, list) |
| 69 if policy['type'] in ('string', 'string-enum', 'dict'): | 69 if policy['type'] in ('string', 'string-enum', 'dict'): |
| 70 example_value_str = json.dumps(example_value, sort_keys=True) | 70 example_value_str = json.dumps(example_value, sort_keys=True) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 100 | 100 |
| 101 def Init(self): | 101 def Init(self): |
| 102 self._mandatory = [] | 102 self._mandatory = [] |
| 103 self._recommended = [] | 103 self._recommended = [] |
| 104 self._last_key = {} | 104 self._last_key = {} |
| 105 | 105 |
| 106 def GetTemplateText(self): | 106 def GetTemplateText(self): |
| 107 prefix = ['Windows Registry Editor Version 5.00'] | 107 prefix = ['Windows Registry Editor Version 5.00'] |
| 108 all = prefix + self._mandatory + self._recommended | 108 all = prefix + self._mandatory + self._recommended |
| 109 return self.NEWLINE.join(all) | 109 return self.NEWLINE.join(all) |
| OLD | NEW |