OLD | NEW |
1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 '''Support for "policy_templates.json" format used by the policy template | 6 '''Support for "policy_templates.json" format used by the policy template |
7 generator as a source for generating ADM,ADMX,etc files.''' | 7 generator as a source for generating ADM,ADMX,etc files.''' |
8 | 8 |
9 import types | 9 import types |
10 import pprint | 10 import pprint |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 self._AddIndentedNontranslateableChunk(depth, "'%s': " % key) | 171 self._AddIndentedNontranslateableChunk(depth, "'%s': " % key) |
172 if key in ('desc', 'caption', 'label'): | 172 if key in ('desc', 'caption', 'label'): |
173 self._AddNontranslateableChunk("'''") | 173 self._AddNontranslateableChunk("'''") |
174 self._ParseMessage( | 174 self._ParseMessage( |
175 item[key], | 175 item[key], |
176 self._GetDescription(item, item_type, parent_item, key)) | 176 self._GetDescription(item, item_type, parent_item, key)) |
177 self._AddNontranslateableChunk("''',\n") | 177 self._AddNontranslateableChunk("''',\n") |
178 else: | 178 else: |
179 str_val = item[key] | 179 str_val = item[key] |
180 if type(str_val) == types.StringType: | 180 if type(str_val) == types.StringType: |
181 str_val = "'%s'" % str_val | 181 str_val = "'%s'" % self.Escape(str_val) |
182 else: | 182 else: |
183 str_val = str(str_val) | 183 str_val = str(str_val) |
184 self._AddNontranslateableChunk(str_val + ',\n') | 184 self._AddNontranslateableChunk(str_val + ',\n') |
185 | 185 |
186 def _AddItems(self, items, item_type, parent_item, depth): | 186 def _AddItems(self, items, item_type, parent_item, depth): |
187 '''Parses and adds a list of items from the JSON file. Items can be policies | 187 '''Parses and adds a list of items from the JSON file. Items can be policies |
188 or parts of an enum policy. | 188 or parts of an enum policy. |
189 | 189 |
190 Args: | 190 Args: |
191 items: Either a list of policies or a list of dictionaries. | 191 items: Either a list of policies or a list of dictionaries. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 | 254 |
255 def FromFile(filename_or_stream, extkey=None, encoding='cp1252'): | 255 def FromFile(filename_or_stream, extkey=None, encoding='cp1252'): |
256 if isinstance(filename_or_stream, types.StringTypes): | 256 if isinstance(filename_or_stream, types.StringTypes): |
257 if util.IsVerbose(): | 257 if util.IsVerbose(): |
258 print "PolicyJson reading file %s, encoding %s" % ( | 258 print "PolicyJson reading file %s, encoding %s" % ( |
259 filename_or_stream, encoding) | 259 filename_or_stream, encoding) |
260 filename_or_stream = \ | 260 filename_or_stream = \ |
261 util.WrapInputStream(file(filename_or_stream, 'r'), encoding) | 261 util.WrapInputStream(file(filename_or_stream, 'r'), encoding) |
262 return PolicyJson(filename_or_stream.read()) | 262 return PolicyJson(filename_or_stream.read()) |
263 FromFile = staticmethod(FromFile) | 263 FromFile = staticmethod(FromFile) |
OLD | NEW |