| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 all resources. | 120 all resources. |
| 121 | 121 |
| 122 Raises: | 122 Raises: |
| 123 KeyError: if there are duplicate keys or resource encoding is | 123 KeyError: if there are duplicate keys or resource encoding is |
| 124 inconsistent. | 124 inconsistent. |
| 125 """ | 125 """ |
| 126 input_data_packs = [ReadDataPack(filename) for filename in input_files] | 126 input_data_packs = [ReadDataPack(filename) for filename in input_files] |
| 127 whitelist = None | 127 whitelist = None |
| 128 if whitelist_file: | 128 if whitelist_file: |
| 129 whitelist = util.ReadFile(whitelist_file, util.RAW_TEXT).strip().split('\n') | 129 whitelist = util.ReadFile(whitelist_file, util.RAW_TEXT).strip().split('\n') |
| 130 whitelist = map(int, whitelist) | 130 whitelist = set(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 kep in the output string |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 # Just write a simple file. | 199 # Just write a simple file. |
| 200 data = {1: '', 4: 'this is id 4', 6: 'this is id 6', 10: ''} | 200 data = {1: '', 4: 'this is id 4', 6: 'this is id 6', 10: ''} |
| 201 WriteDataPack(data, 'datapack1.pak', UTF8) | 201 WriteDataPack(data, 'datapack1.pak', UTF8) |
| 202 data2 = {1000: 'test', 5: 'five'} | 202 data2 = {1000: 'test', 5: 'five'} |
| 203 WriteDataPack(data2, 'datapack2.pak', UTF8) | 203 WriteDataPack(data2, 'datapack2.pak', UTF8) |
| 204 print 'wrote datapack1 and datapack2 to current directory.' | 204 print 'wrote datapack1 and datapack2 to current directory.' |
| 205 | 205 |
| 206 | 206 |
| 207 if __name__ == '__main__': | 207 if __name__ == '__main__': |
| 208 main() | 208 main() |
| OLD | NEW |