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

Side by Side Diff: tools/data_pack/repack.py

Issue 7744017: Updated *.pak file format to support both UTF8 and UTF16 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up comments/ Created 9 years, 3 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/python 1 #!/usr/bin/python
2 # Copyright (c) 2008 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2008 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 """A simple utility function to merge data pack files into a single data pack. 6 """A simple utility function to merge data pack files into a single data pack.
7 See base/pack_file* for details about the file format. 7 See base/pack_file* for details about the file format.
8 """ 8 """
9 9
10 import exceptions 10 import exceptions
11 import struct 11 import struct
12 import sys 12 import sys
13 13
14 import data_pack 14 import data_pack
15 15
16 def RePack(output_file, input_files): 16 def RePack(output_file, input_files):
17 """Write a new data pack to |output_file| based on a list of filenames 17 """Write a new data pack to |output_file| based on a list of filenames
18 (|input_files|)""" 18 (|input_files|)"""
19 resources = {} 19 resources = {}
20 encoding = None
20 for filename in input_files: 21 for filename in input_files:
21 new_resources = data_pack.ReadDataPack(filename) 22 new_resources, new_encoding = data_pack.ReadDataPack(filename)
22 23
23 # Make sure we have no dups. 24 # Make sure we have no dups.
24 duplicate_keys = set(new_resources.keys()) & set(resources.keys()) 25 duplicate_keys = set(new_resources.keys()) & set(resources.keys())
25 if len(duplicate_keys) != 0: 26 if len(duplicate_keys) != 0:
26 raise exceptions.KeyError("Duplicate keys: " + str(list(duplicate_keys))) 27 raise exceptions.KeyError("Duplicate keys: " + str(list(duplicate_keys)))
27 28
29 # Make sure encoding is consistent.
30 if (encoding is None or encoding is data_pack.BINARY):
tony 2011/08/29 21:24:39 Nit: no () around the condition and I would write
marcvs 2011/08/30 07:58:55 Done.
31 encoding = new_encoding
32 else:
33 if (new_encoding != data_pack.BINARY and encoding != new_encoding):
tony 2011/08/29 21:24:39 Nit: no () around the condition and use elif.
marcvs 2011/08/30 07:58:55 Done.
34 raise exceptions.KeyError("Inconsistent encodings: " +
35 str(encoding) + " vs " + str(new_encoding))
36
28 resources.update(new_resources) 37 resources.update(new_resources)
29 38
30 data_pack.WriteDataPack(resources, output_file) 39 # Encoding is 0 for BINARY, 1 for UTF8 and 2 for UTF16
40 if (encoding is None):
tony 2011/08/29 21:24:39 Nit: no () around the condition
marcvs 2011/08/30 07:58:55 Done.
41 encoding = data_pack.BINARY
42 data_pack.WriteDataPack(resources, output_file, encoding)
31 43
32 def main(argv): 44 def main(argv):
33 if len(argv) < 3: 45 if len(argv) < 3:
34 print ("Usage:\n %s <output_filename> <input_file1> [input_file2] ... " % 46 print ("Usage:\n %s <output_filename> <input_file1> [input_file2] ... " %
35 argv[0]) 47 argv[0])
36 sys.exit(-1) 48 sys.exit(-1)
37 RePack(argv[1], argv[2:]) 49 RePack(argv[1], argv[2:])
38 50
39 if '__main__' == __name__: 51 if '__main__' == __name__:
40 main(sys.argv) 52 main(sys.argv)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698