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 | 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 |
11 | 11 |
| 12 # This writer outputs a Preferences Manifest file as documented at |
| 13 # https://developer.apple.com/library/mac/documentation/MacOSXServer/Conceptual/
Preference_Manifest_Files |
| 14 |
| 15 |
12 def GetWriter(config): | 16 def GetWriter(config): |
13 '''Factory method for creating PListWriter objects. | 17 '''Factory method for creating PListWriter objects. |
14 See the constructor of TemplateWriter for description of | 18 See the constructor of TemplateWriter for description of |
15 arguments. | 19 arguments. |
16 ''' | 20 ''' |
17 return PListWriter(['mac'], config) | 21 return PListWriter(['mac'], config) |
18 | 22 |
19 | 23 |
20 class PListWriter(xml_formatted_writer.XMLFormattedWriter): | 24 class PListWriter(xml_formatted_writer.XMLFormattedWriter): |
21 '''Class for generating policy templates in Mac plist format. | 25 '''Class for generating policy templates in Mac plist format. |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 self._AddStringKeyValuePair(dict, 'pfm_type', | 100 self._AddStringKeyValuePair(dict, 'pfm_type', |
97 self.TYPE_TO_INPUT[policy_type]) | 101 self.TYPE_TO_INPUT[policy_type]) |
98 if policy_type in ('int-enum', 'string-enum'): | 102 if policy_type in ('int-enum', 'string-enum'): |
99 range_list = self._AddKeyValuePair(dict, 'pfm_range_list', 'array') | 103 range_list = self._AddKeyValuePair(dict, 'pfm_range_list', 'array') |
100 for item in policy['items']: | 104 for item in policy['items']: |
101 if policy_type == 'int-enum': | 105 if policy_type == 'int-enum': |
102 element_type = 'integer' | 106 element_type = 'integer' |
103 else: | 107 else: |
104 element_type = 'string' | 108 element_type = 'string' |
105 self.AddElement(range_list, element_type, {}, str(item['value'])) | 109 self.AddElement(range_list, element_type, {}, str(item['value'])) |
| 110 elif policy_type == 'list': |
| 111 subkeys = self._AddKeyValuePair(dict, 'pfm_subkeys', 'array') |
| 112 subkeys_dict = self.AddElement(subkeys, 'dict') |
| 113 subkeys_type = self._AddKeyValuePair(subkeys_dict, 'pfm_type', 'string') |
| 114 self.AddText(subkeys_type, 'string') |
106 | 115 |
107 def BeginTemplate(self): | 116 def BeginTemplate(self): |
108 self._plist.attributes['version'] = '1' | 117 self._plist.attributes['version'] = '1' |
109 dict = self.AddElement(self._plist, 'dict') | 118 dict = self.AddElement(self._plist, 'dict') |
110 | 119 |
111 app_name = plist_helper.GetPlistFriendlyName(self.config['app_name']) | 120 app_name = plist_helper.GetPlistFriendlyName(self.config['app_name']) |
112 self._AddStringKeyValuePair(dict, 'pfm_name', app_name) | 121 self._AddStringKeyValuePair(dict, 'pfm_name', app_name) |
113 self._AddStringKeyValuePair(dict, 'pfm_description', '') | 122 self._AddStringKeyValuePair(dict, 'pfm_description', '') |
114 self._AddStringKeyValuePair(dict, 'pfm_title', '') | 123 self._AddStringKeyValuePair(dict, 'pfm_title', '') |
115 self._AddStringKeyValuePair(dict, 'pfm_version', '1') | 124 self._AddStringKeyValuePair(dict, 'pfm_version', '1') |
116 self._AddStringKeyValuePair(dict, 'pfm_domain', | 125 self._AddStringKeyValuePair(dict, 'pfm_domain', |
117 self.config['mac_bundle_id']) | 126 self.config['mac_bundle_id']) |
118 | 127 |
119 self._array = self._AddKeyValuePair(dict, 'pfm_subkeys', 'array') | 128 self._array = self._AddKeyValuePair(dict, 'pfm_subkeys', 'array') |
120 | 129 |
121 def Init(self): | 130 def Init(self): |
122 dom_impl = minidom.getDOMImplementation('') | 131 dom_impl = minidom.getDOMImplementation('') |
123 doctype = dom_impl.createDocumentType( | 132 doctype = dom_impl.createDocumentType( |
124 'plist', | 133 'plist', |
125 '-//Apple//DTD PLIST 1.0//EN', | 134 '-//Apple//DTD PLIST 1.0//EN', |
126 'http://www.apple.com/DTDs/PropertyList-1.0.dtd') | 135 'http://www.apple.com/DTDs/PropertyList-1.0.dtd') |
127 self._doc = dom_impl.createDocument(None, 'plist', doctype) | 136 self._doc = dom_impl.createDocument(None, 'plist', doctype) |
128 self._plist = self._doc.documentElement | 137 self._plist = self._doc.documentElement |
129 | 138 |
130 def GetTemplateText(self): | 139 def GetTemplateText(self): |
131 return self.ToPrettyXml(self._doc) | 140 return self.ToPrettyXml(self._doc) |
OLD | NEW |