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 """Support for formatting a data pack file used for platform agnostic resource | 6 """Support for formatting a data pack file used for platform agnostic resource |
7 files. | 7 files. |
8 """ | 8 """ |
9 | 9 |
10 import collections | 10 import collections |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 whitelist = map(int, whitelist) | 130 whitelist = map(int, whitelist) |
131 resources, encoding = RePackFromDataPackStrings(input_data_packs, whitelist) | 131 resources, encoding = RePackFromDataPackStrings(input_data_packs, whitelist) |
132 WriteDataPack(resources, output_file, encoding) | 132 WriteDataPack(resources, output_file, encoding) |
133 | 133 |
134 | 134 |
135 def RePackFromDataPackStrings(inputs, whitelist): | 135 def RePackFromDataPackStrings(inputs, whitelist): |
136 """Returns a data pack string that combines the resources from inputs. | 136 """Returns a data pack string that combines the resources from inputs. |
137 | 137 |
138 Args: | 138 Args: |
139 inputs: a list of data pack strings that need to be combined. | 139 inputs: a list of data pack strings that need to be combined. |
140 whitelist: a list of resource IDs that should be kep in the output string | 140 whitelist: a list of resource IDs that should be kept in the output string |
141 or None to include all resources. | 141 or None to include all resources. |
142 | 142 |
143 Returns: | 143 Returns: |
144 DataPackContents: a tuple containing the new combined data pack and its | 144 DataPackContents: a tuple containing the new combined data pack and its |
145 encoding. | 145 encoding. |
146 | 146 |
147 Raises: | 147 Raises: |
148 KeyError: if there are duplicate keys or resource encoding is | 148 KeyError: if there are duplicate keys or resource encoding is |
149 inconsistent. | 149 inconsistent. |
150 """ | 150 """ |
(...skipping 10 matching lines...) Expand all Loading... |
161 encoding = content.encoding | 161 encoding = content.encoding |
162 elif content.encoding not in (BINARY, encoding): | 162 elif content.encoding not in (BINARY, encoding): |
163 raise exceptions.KeyError('Inconsistent encodings: ' + str(encoding) + | 163 raise exceptions.KeyError('Inconsistent encodings: ' + str(encoding) + |
164 ' vs ' + str(content.encoding)) | 164 ' vs ' + str(content.encoding)) |
165 | 165 |
166 if whitelist: | 166 if whitelist: |
167 whitelisted_resources = dict([(key, content.resources[key]) | 167 whitelisted_resources = dict([(key, content.resources[key]) |
168 for key in content.resources.keys() | 168 for key in content.resources.keys() |
169 if key in whitelist]) | 169 if key in whitelist]) |
170 resources.update(whitelisted_resources) | 170 resources.update(whitelisted_resources) |
| 171 removed_keys = [key for key in content.resources.keys() |
| 172 if key not in whitelist] |
| 173 for key in removed_keys: |
| 174 print 'RePackFromDataPackStrings Removed Key:', key |
171 else: | 175 else: |
172 resources.update(content.resources) | 176 resources.update(content.resources) |
173 | 177 |
174 # Encoding is 0 for BINARY, 1 for UTF8 and 2 for UTF16 | 178 # Encoding is 0 for BINARY, 1 for UTF8 and 2 for UTF16 |
175 if encoding is None: | 179 if encoding is None: |
176 encoding = BINARY | 180 encoding = BINARY |
177 return DataPackContents(resources, encoding) | 181 return DataPackContents(resources, encoding) |
178 | 182 |
179 | 183 |
180 # Temporary hack for external programs that import data_pack. | 184 # Temporary hack for external programs that import data_pack. |
(...skipping 18 matching lines...) Expand all Loading... |
199 # Just write a simple file. | 203 # Just write a simple file. |
200 data = {1: '', 4: 'this is id 4', 6: 'this is id 6', 10: ''} | 204 data = {1: '', 4: 'this is id 4', 6: 'this is id 6', 10: ''} |
201 WriteDataPack(data, 'datapack1.pak', UTF8) | 205 WriteDataPack(data, 'datapack1.pak', UTF8) |
202 data2 = {1000: 'test', 5: 'five'} | 206 data2 = {1000: 'test', 5: 'five'} |
203 WriteDataPack(data2, 'datapack2.pak', UTF8) | 207 WriteDataPack(data2, 'datapack2.pak', UTF8) |
204 print 'wrote datapack1 and datapack2 to current directory.' | 208 print 'wrote datapack1 and datapack2 to current directory.' |
205 | 209 |
206 | 210 |
207 if __name__ == '__main__': | 211 if __name__ == '__main__': |
208 main() | 212 main() |
OLD | NEW |