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

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

Issue 347293003: Added support for string-enum-list. (Closed) Base URL: http://grit-i18n.googlecode.com/svn/trunk/
Patch Set: Created 6 years, 5 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 6
7 from xml.dom import minidom 7 from xml.dom import minidom
8 from grit.format.policy_templates.writers import plist_helper 8 from grit.format.policy_templates.writers import plist_helper
9 from grit.format.policy_templates.writers import xml_formatted_writer 9 from grit.format.policy_templates.writers import xml_formatted_writer
10 10
(...skipping 14 matching lines...) Expand all
25 '''Class for generating policy templates in Mac plist format. 25 '''Class for generating policy templates in Mac plist format.
26 It is used by PolicyTemplateGenerator to write plist files. 26 It is used by PolicyTemplateGenerator to write plist files.
27 ''' 27 '''
28 28
29 STRING_TABLE = 'Localizable.strings' 29 STRING_TABLE = 'Localizable.strings'
30 TYPE_TO_INPUT = { 30 TYPE_TO_INPUT = {
31 'string': 'string', 31 'string': 'string',
32 'int': 'integer', 32 'int': 'integer',
33 'int-enum': 'integer', 33 'int-enum': 'integer',
34 'string-enum': 'string', 34 'string-enum': 'string',
35 'string-enum-list': 'array',
35 'main': 'boolean', 36 'main': 'boolean',
36 'list': 'array', 37 'list': 'array',
37 'dict': 'dictionary', 38 'dict': 'dictionary',
38 } 39 }
39 40
40 def _AddKeyValuePair(self, parent, key_string, value_tag): 41 def _AddKeyValuePair(self, parent, key_string, value_tag):
41 '''Adds a plist key-value pair to a parent XML element. 42 '''Adds a plist key-value pair to a parent XML element.
42 43
43 A key-value pair in plist consists of two XML elements next two each other: 44 A key-value pair in plist consists of two XML elements next two each other:
44 <key>key_string</key> 45 <key>key_string</key>
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 self._AddStringKeyValuePair(dict, 'pfm_type', 101 self._AddStringKeyValuePair(dict, 'pfm_type',
101 self.TYPE_TO_INPUT[policy_type]) 102 self.TYPE_TO_INPUT[policy_type])
102 if policy_type in ('int-enum', 'string-enum'): 103 if policy_type in ('int-enum', 'string-enum'):
103 range_list = self._AddKeyValuePair(dict, 'pfm_range_list', 'array') 104 range_list = self._AddKeyValuePair(dict, 'pfm_range_list', 'array')
104 for item in policy['items']: 105 for item in policy['items']:
105 if policy_type == 'int-enum': 106 if policy_type == 'int-enum':
106 element_type = 'integer' 107 element_type = 'integer'
107 else: 108 else:
108 element_type = 'string' 109 element_type = 'string'
109 self.AddElement(range_list, element_type, {}, str(item['value'])) 110 self.AddElement(range_list, element_type, {}, str(item['value']))
110 elif policy_type == 'list': 111 elif policy_type in ('list', 'string-enum-list'):
111 subkeys = self._AddKeyValuePair(dict, 'pfm_subkeys', 'array') 112 subkeys = self._AddKeyValuePair(dict, 'pfm_subkeys', 'array')
112 subkeys_dict = self.AddElement(subkeys, 'dict') 113 subkeys_dict = self.AddElement(subkeys, 'dict')
113 subkeys_type = self._AddKeyValuePair(subkeys_dict, 'pfm_type', 'string') 114 subkeys_type = self._AddKeyValuePair(subkeys_dict, 'pfm_type', 'string')
114 self.AddText(subkeys_type, 'string') 115 self.AddText(subkeys_type, 'string')
115 116
116 def BeginTemplate(self): 117 def BeginTemplate(self):
117 self._plist.attributes['version'] = '1' 118 self._plist.attributes['version'] = '1'
118 dict = self.AddElement(self._plist, 'dict') 119 dict = self.AddElement(self._plist, 'dict')
119 120
120 app_name = plist_helper.GetPlistFriendlyName(self.config['app_name']) 121 app_name = plist_helper.GetPlistFriendlyName(self.config['app_name'])
(...skipping 13 matching lines...) Expand all
134 '-//Apple//DTD PLIST 1.0//EN', 135 '-//Apple//DTD PLIST 1.0//EN',
135 'http://www.apple.com/DTDs/PropertyList-1.0.dtd') 136 'http://www.apple.com/DTDs/PropertyList-1.0.dtd')
136 return dom_impl.createDocument(None, 'plist', doctype) 137 return dom_impl.createDocument(None, 'plist', doctype)
137 138
138 def Init(self): 139 def Init(self):
139 self._doc = self.CreatePlistDocument() 140 self._doc = self.CreatePlistDocument()
140 self._plist = self._doc.documentElement 141 self._plist = self._doc.documentElement
141 142
142 def GetTemplateText(self): 143 def GetTemplateText(self):
143 return self.ToPrettyXml(self._doc) 144 return self.ToPrettyXml(self._doc)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698