| 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 import json | 6 import json |
| 7 | 7 |
| 8 from textwrap import TextWrapper | 8 from textwrap import TextWrapper |
| 9 from grit.format.policy_templates.writers import template_writer | 9 from grit.format.policy_templates.writers import template_writer |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 class JsonWriter(template_writer.TemplateWriter): | 32 class JsonWriter(template_writer.TemplateWriter): |
| 33 '''Class for generating policy files in JSON format (for Linux). The | 33 '''Class for generating policy files in JSON format (for Linux). The |
| 34 generated files will define all the supported policies with example values | 34 generated files will define all the supported policies with example values |
| 35 set for them. This class is used by PolicyTemplateGenerator to write .json | 35 set for them. This class is used by PolicyTemplateGenerator to write .json |
| 36 files. | 36 files. |
| 37 ''' | 37 ''' |
| 38 | 38 |
| 39 def PreprocessPolicies(self, policy_list): | 39 def PreprocessPolicies(self, policy_list): |
| 40 return self.FlattenGroupsAndSortPolicies(policy_list) | 40 return self.FlattenGroupsAndSortPolicies(policy_list) |
| 41 | 41 |
| 42 def WriteComment(self, comment): |
| 43 self._out.append('// ' + comment) |
| 44 |
| 42 def WritePolicy(self, policy): | 45 def WritePolicy(self, policy): |
| 43 if policy['type'] == 'external': | 46 if policy['type'] == 'external': |
| 44 # This type can only be set through cloud policy. | 47 # This type can only be set through cloud policy. |
| 45 return | 48 return |
| 46 example_value_str = json.dumps(policy['example_value'], sort_keys=True) | 49 example_value_str = json.dumps(policy['example_value'], sort_keys=True) |
| 47 | 50 |
| 48 # Add comma to the end of the previous line. | 51 # Add comma to the end of the previous line. |
| 49 if not self._first_written: | 52 if not self._first_written: |
| 50 self._out[-2] += ',' | 53 self._out[-2] += ',' |
| 51 | 54 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 62 description = self._text_wrapper.wrap(policy['desc']) | 65 description = self._text_wrapper.wrap(policy['desc']) |
| 63 self._out += description; | 66 self._out += description; |
| 64 line = ' //"%s": %s' % (policy['name'], example_value_str) | 67 line = ' //"%s": %s' % (policy['name'], example_value_str) |
| 65 self._out.append('') | 68 self._out.append('') |
| 66 self._out.append(line) | 69 self._out.append(line) |
| 67 self._out.append('') | 70 self._out.append('') |
| 68 | 71 |
| 69 self._first_written = False | 72 self._first_written = False |
| 70 | 73 |
| 71 def BeginTemplate(self): | 74 def BeginTemplate(self): |
| 75 if self._GetChromiumVersionString() is not None: |
| 76 self.WriteComment(self.config['build'] + ''' version: ''' + \ |
| 77 self._GetChromiumVersionString()) |
| 72 self._out.append(TEMPLATE_HEADER) | 78 self._out.append(TEMPLATE_HEADER) |
| 73 | 79 |
| 74 def EndTemplate(self): | 80 def EndTemplate(self): |
| 75 self._out.append('}') | 81 self._out.append('}') |
| 76 | 82 |
| 77 def Init(self): | 83 def Init(self): |
| 78 self._out = [] | 84 self._out = [] |
| 79 # The following boolean member is true until the first policy is written. | 85 # The following boolean member is true until the first policy is written. |
| 80 self._first_written = True | 86 self._first_written = True |
| 81 # Create the TextWrapper object once. | 87 # Create the TextWrapper object once. |
| 82 self._text_wrapper = TextWrapper( | 88 self._text_wrapper = TextWrapper( |
| 83 initial_indent = ' // ', | 89 initial_indent = ' // ', |
| 84 subsequent_indent = ' // ', | 90 subsequent_indent = ' // ', |
| 85 break_long_words = False, | 91 break_long_words = False, |
| 86 width = 80) | 92 width = 80) |
| 87 | 93 |
| 88 def GetTemplateText(self): | 94 def GetTemplateText(self): |
| 89 return '\n'.join(self._out) | 95 return '\n'.join(self._out) |
| OLD | NEW |