| 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 from writers import template_writer | 7 from writers import template_writer |
| 8 import re | 8 import re |
| 9 | 9 |
| 10 NEWLINE = '\r\n' | 10 NEWLINE = '\r\n' |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 It is used by PolicyTemplateGenerator to write ADM files. | 65 It is used by PolicyTemplateGenerator to write ADM files. |
| 66 ''' | 66 ''' |
| 67 | 67 |
| 68 TYPE_TO_INPUT = { | 68 TYPE_TO_INPUT = { |
| 69 'string': 'EDITTEXT', | 69 'string': 'EDITTEXT', |
| 70 'int': 'NUMERIC', | 70 'int': 'NUMERIC', |
| 71 'string-enum': 'DROPDOWNLIST', | 71 'string-enum': 'DROPDOWNLIST', |
| 72 'int-enum': 'DROPDOWNLIST', | 72 'int-enum': 'DROPDOWNLIST', |
| 73 'list': 'LISTBOX', | 73 'list': 'LISTBOX', |
| 74 'string-enum-list': 'LISTBOX', | 74 'string-enum-list': 'LISTBOX', |
| 75 'dict': 'EDITTEXT' | 75 'dict': 'EDITTEXT', |
| 76 'external': 'EDITTEXT' |
| 76 } | 77 } |
| 77 | 78 |
| 78 def _Escape(self, string): | 79 def _Escape(self, string): |
| 79 return string.replace('.', '_') | 80 return string.replace('.', '_') |
| 80 | 81 |
| 81 def _AddGuiString(self, name, value): | 82 def _AddGuiString(self, name, value): |
| 82 # The |name| must be escaped. | 83 # The |name| must be escaped. |
| 83 assert name == self._Escape(name) | 84 assert name == self._Escape(name) |
| 84 # Escape newlines in the value. | 85 # Escape newlines in the value. |
| 85 value = value.replace('\n', '\\n') | 86 value = value.replace('\n', '\\n') |
| (...skipping 29 matching lines...) Expand all Loading... |
| 115 if policy['type'] in ('list', 'string-enum-list'): | 116 if policy['type'] in ('list', 'string-enum-list'): |
| 116 # Note that the following line causes FullArmor ADMX Migrator to create | 117 # Note that the following line causes FullArmor ADMX Migrator to create |
| 117 # corrupt ADMX files. Please use admx_writer to get ADMX files. | 118 # corrupt ADMX files. Please use admx_writer to get ADMX files. |
| 118 builder.AddLine('KEYNAME "%s\\%s"' % (key_name, policy['name'])) | 119 builder.AddLine('KEYNAME "%s\\%s"' % (key_name, policy['name'])) |
| 119 builder.AddLine('VALUEPREFIX ""') | 120 builder.AddLine('VALUEPREFIX ""') |
| 120 else: | 121 else: |
| 121 builder.AddLine('VALUENAME "%s"' % policy['name']) | 122 builder.AddLine('VALUENAME "%s"' % policy['name']) |
| 122 if policy['type'] == 'int': | 123 if policy['type'] == 'int': |
| 123 # The default max for NUMERIC values is 9999 which is too small for us. | 124 # The default max for NUMERIC values is 9999 which is too small for us. |
| 124 builder.AddLine('MIN 0 MAX 2000000000') | 125 builder.AddLine('MIN 0 MAX 2000000000') |
| 125 if policy['type'] in ('string', 'dict'): | 126 if policy['type'] in ('string', 'dict', 'external'): |
| 126 # The default max for EDITTEXT values is 1023, which is too small for | 127 # The default max for EDITTEXT values is 1023, which is too small for |
| 127 # big JSON blobs and other string policies. | 128 # big JSON blobs and other string policies. |
| 128 builder.AddLine('MAXLEN 1000000') | 129 builder.AddLine('MAXLEN 1000000') |
| 129 if policy['type'] in ('int-enum', 'string-enum'): | 130 if policy['type'] in ('int-enum', 'string-enum'): |
| 130 builder.AddLine('ITEMLIST', 1) | 131 builder.AddLine('ITEMLIST', 1) |
| 131 for item in policy['items']: | 132 for item in policy['items']: |
| 132 if policy['type'] == 'int-enum': | 133 if policy['type'] == 'int-enum': |
| 133 value_text = 'NUMERIC ' + str(item['value']) | 134 value_text = 'NUMERIC ' + str(item['value']) |
| 134 else: | 135 else: |
| 135 value_text = '"' + item['value'] + '"' | 136 value_text = '"' + item['value'] + '"' |
| 136 string_id = self._Escape(item['name'] + '_DropDown') | 137 string_id = self._Escape(item['name'] + '_DropDown') |
| 137 builder.AddLine('NAME !!%s VALUE %s' % (string_id, value_text)) | 138 builder.AddLine('NAME !!%s VALUE %s' % (string_id, value_text)) |
| 138 self._AddGuiString(string_id, item['caption']) | 139 self._AddGuiString(string_id, item['caption']) |
| 139 builder.AddLine('END ITEMLIST', -1) | 140 builder.AddLine('END ITEMLIST', -1) |
| 140 builder.AddLine('END PART', -1) | 141 builder.AddLine('END PART', -1) |
| 141 | 142 |
| 142 def _WritePolicy(self, policy, key_name, builder): | 143 def _WritePolicy(self, policy, key_name, builder): |
| 143 if policy['type'] == 'external': | |
| 144 # This type can only be set through cloud policy. | |
| 145 return | |
| 146 | |
| 147 policy_name = self._Escape(policy['name'] + '_Policy') | 144 policy_name = self._Escape(policy['name'] + '_Policy') |
| 148 self._AddGuiString(policy_name, policy['caption']) | 145 self._AddGuiString(policy_name, policy['caption']) |
| 149 builder.AddLine('POLICY !!%s' % policy_name, 1) | 146 builder.AddLine('POLICY !!%s' % policy_name, 1) |
| 150 self._WriteSupported(builder) | 147 self._WriteSupported(builder) |
| 151 policy_explain_name = self._Escape(policy['name'] + '_Explain') | 148 policy_explain_name = self._Escape(policy['name'] + '_Explain') |
| 152 self._AddGuiString(policy_explain_name, policy['desc']) | 149 self._AddGuiString(policy_explain_name, policy['desc']) |
| 153 builder.AddLine('EXPLAIN !!' + policy_explain_name) | 150 builder.AddLine('EXPLAIN !!' + policy_explain_name) |
| 154 | 151 |
| 155 if policy['type'] == 'main': | 152 if policy['type'] == 'main': |
| 156 builder.AddLine('VALUENAME "%s"' % policy['name']) | 153 builder.AddLine('VALUENAME "%s"' % policy['name']) |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 self.recommended_policies = IndentedStringBuilder() | 269 self.recommended_policies = IndentedStringBuilder() |
| 273 # Shortcut to platform-specific ADMX/ADM specific configuration. | 270 # Shortcut to platform-specific ADMX/ADM specific configuration. |
| 274 assert len(self.platforms) == 1 | 271 assert len(self.platforms) == 1 |
| 275 self.winconfig = self.config['win_config'][self.platforms[0]] | 272 self.winconfig = self.config['win_config'][self.platforms[0]] |
| 276 | 273 |
| 277 def GetTemplateText(self): | 274 def GetTemplateText(self): |
| 278 return self.lines.ToString() | 275 return self.lines.ToString() |
| 279 | 276 |
| 280 def GetClass(self): | 277 def GetClass(self): |
| 281 return 'Both'; | 278 return 'Both'; |
| OLD | NEW |