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

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

Issue 550163002: Add optional mandatory policy setting for template generation (Closed) Base URL: http://grit-i18n.googlecode.com/svn/trunk/
Patch Set: Created 6 years, 3 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 def WritePolicy(self, policy): 42 def WritePolicy(self, policy):
43 if policy['type'] == 'external': 43 if policy['type'] == 'external':
44 # This type can only be set through cloud policy. 44 # This type can only be set through cloud policy.
45 return 45 return
46 example_value_str = json.dumps(policy['example_value'], sort_keys=True) 46 example_value_str = json.dumps(policy['example_value'], sort_keys=True)
47 47
48 # Add comma to the end of the previous line. 48 # Add comma to the end of the previous line.
49 if not self._first_written: 49 if not self._first_written:
50 self._out[-2] += ',' 50 self._out[-2] += ','
51 51
52 if not self.CanBeMandatory(policy) and self.CanBeRecommended(policy):
53 line = ' // Note: this policy is supported only in recommended mode.'
54 self._out.append(line)
55 line = ' // The JSON file should be placed in %srecommended.' % \
56 self.config['linux_policy_path']
57 self._out.append(line)
58
52 line = ' // %s' % policy['caption'] 59 line = ' // %s' % policy['caption']
53 self._out.append(line) 60 self._out.append(line)
54 self._out.append(HEADER_DELIMETER) 61 self._out.append(HEADER_DELIMETER)
55 description = self._text_wrapper.wrap(policy['desc']) 62 description = self._text_wrapper.wrap(policy['desc'])
56 self._out += description; 63 self._out += description;
57 line = ' //"%s": %s' % (policy['name'], example_value_str) 64 line = ' //"%s": %s' % (policy['name'], example_value_str)
58 self._out.append('') 65 self._out.append('')
59 self._out.append(line) 66 self._out.append(line)
60 self._out.append('') 67 self._out.append('')
61 68
(...skipping 11 matching lines...) Expand all
73 self._first_written = True 80 self._first_written = True
74 # Create the TextWrapper object once. 81 # Create the TextWrapper object once.
75 self._text_wrapper = TextWrapper( 82 self._text_wrapper = TextWrapper(
76 initial_indent = ' // ', 83 initial_indent = ' // ',
77 subsequent_indent = ' // ', 84 subsequent_indent = ' // ',
78 break_long_words = False, 85 break_long_words = False,
79 width = 80) 86 width = 80)
80 87
81 def GetTemplateText(self): 88 def GetTemplateText(self):
82 return '\n'.join(self._out) 89 return '\n'.join(self._out)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698