OLD | NEW |
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 from xml.dom import minidom | 6 from xml.dom import minidom |
7 from grit.format.policy_templates.writers import template_writer | 7 from grit.format.policy_templates.writers import template_writer |
8 | 8 |
9 | 9 |
10 def GetWriter(config): | 10 def GetWriter(config): |
11 '''Factory method for creating JsonWriter objects. | 11 '''Factory method for creating JsonWriter objects. |
12 See the constructor of TemplateWriter for description of | 12 See the constructor of TemplateWriter for description of |
13 arguments. | 13 arguments. |
14 ''' | 14 ''' |
15 return JsonWriter(['linux'], config) | 15 return JsonWriter(['linux'], config) |
16 | 16 |
17 | 17 |
18 class JsonWriter(template_writer.TemplateWriter): | 18 class JsonWriter(template_writer.TemplateWriter): |
19 '''Class for generating policy files in JSON format (for Linux). The | 19 '''Class for generating policy files in JSON format (for Linux). The |
20 generated files will define all the supported policies with example values | 20 generated files will define all the supported policies with example values |
21 set for them. This class is used by PolicyTemplateGenerator to write .json | 21 set for them. This class is used by PolicyTemplateGenerator to write .json |
22 files. | 22 files. |
23 ''' | 23 ''' |
24 | 24 |
25 def PreprocessPolicies(self, policy_list): | 25 def PreprocessPolicies(self, policy_list): |
26 return self.FlattenGroupsAndSortPolicies(policy_list) | 26 return self.FlattenGroupsAndSortPolicies(policy_list) |
27 | 27 |
28 def WritePolicy(self, policy): | 28 def WritePolicy(self, policy): |
29 example_value = policy['annotations']['example_value'] | 29 example_value = policy['example_value'] |
30 if policy['type'] == 'string': | 30 if policy['type'] == 'string': |
31 example_value_str = '"' + example_value + '"' | 31 example_value_str = '"' + example_value + '"' |
32 elif policy['type'] == 'int': | 32 elif policy['type'] == 'int': |
33 example_value_str = str(example_value) | 33 example_value_str = str(example_value) |
34 elif policy['type'] == 'list': | 34 elif policy['type'] == 'list': |
35 if example_value == []: | 35 if example_value == []: |
36 example_value_str = '[]' | 36 example_value_str = '[]' |
37 else: | 37 else: |
38 example_value_str = '["%s"]' % '", "'.join(example_value) | 38 example_value_str = '["%s"]' % '", "'.join(example_value) |
39 elif policy['type'] == 'main': | 39 elif policy['type'] == 'main': |
(...skipping 23 matching lines...) Expand all Loading... |
63 def EndTemplate(self): | 63 def EndTemplate(self): |
64 self._out.append('}') | 64 self._out.append('}') |
65 | 65 |
66 def Init(self): | 66 def Init(self): |
67 self._out = [] | 67 self._out = [] |
68 # The following boolean member is true until the first policy is written. | 68 # The following boolean member is true until the first policy is written. |
69 self._first_written = True | 69 self._first_written = True |
70 | 70 |
71 def GetTemplateText(self): | 71 def GetTemplateText(self): |
72 return '\n'.join(self._out) | 72 return '\n'.join(self._out) |
OLD | NEW |