Chromium Code Reviews| 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) | |
|
pastarmovj
2014/10/07 14:54:35
No need for triple quotes.
cschuet1
2014/10/07 15:42:46
Done.
| |
| 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: ''' + self._GetChrom iumVersionString()) | |
|
pastarmovj
2014/10/07 14:54:35
line too long, quotes.
cschuet1
2014/10/07 15:42:46
Done.
| |
| 72 self._out.append(TEMPLATE_HEADER) | 77 self._out.append(TEMPLATE_HEADER) |
| 73 | 78 |
| 74 def EndTemplate(self): | 79 def EndTemplate(self): |
| 75 self._out.append('}') | 80 self._out.append('}') |
| 76 | 81 |
| 77 def Init(self): | 82 def Init(self): |
| 78 self._out = [] | 83 self._out = [] |
| 79 # The following boolean member is true until the first policy is written. | 84 # The following boolean member is true until the first policy is written. |
| 80 self._first_written = True | 85 self._first_written = True |
| 81 # Create the TextWrapper object once. | 86 # Create the TextWrapper object once. |
| 82 self._text_wrapper = TextWrapper( | 87 self._text_wrapper = TextWrapper( |
| 83 initial_indent = ' // ', | 88 initial_indent = ' // ', |
| 84 subsequent_indent = ' // ', | 89 subsequent_indent = ' // ', |
| 85 break_long_words = False, | 90 break_long_words = False, |
| 86 width = 80) | 91 width = 80) |
| 87 | 92 |
| 88 def GetTemplateText(self): | 93 def GetTemplateText(self): |
| 89 return '\n'.join(self._out) | 94 return '\n'.join(self._out) |
| OLD | NEW |