Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1141)

Side by Side Diff: grit/format/policy_templates/writers/json_writer.py

Issue 631223003: Include chromium version number in policy templates (Closed) Base URL: http://grit-i18n.googlecode.com/svn/trunk/
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698