OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright 2016 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 import os | |
7 import re | |
8 import sys | |
9 | |
10 | |
11 _HERE_PATH = os.path.join(os.path.dirname(__file__)) | |
12 | |
13 | |
14 _SRC_PATH = os.path.normpath(os.path.join(_HERE_PATH, '..', '..', '..')) | |
15 sys.path.append(os.path.join(_SRC_PATH, 'tools', 'grit')) | |
16 from grit.format import data_pack | |
17 | |
18 | |
19 def unpack(pak_path, out_path): | |
20 pak_dir = os.path.dirname(pak_path); | |
21 pak_id = os.path.splitext(os.path.basename(pak_path))[0] | |
22 | |
23 data = data_pack.DataPack.ReadDataPack(pak_path) | |
24 | |
25 # Associate numerical grit IDs to strings. | |
26 # For example 120045 -> 'IDR_SETTINGS_ABOUT_PAGE_HTML' | |
27 resource_ids = dict() | |
28 resources_path = os.path.join(pak_dir, 'grit', pak_id + '.h') | |
29 with open(resources_path) as resources_file: | |
30 for line in resources_file: | |
31 res = re.match('#define ([^ ]+) (\d+)', line) | |
32 if res: | |
33 resource_ids[int(res.group(2))] = res.group(1) | |
34 | |
35 # Associate numerical string IDs to files. | |
36 resource_filenames = dict() | |
37 resources_map_path = os.path.join(pak_dir, 'grit', pak_id + '_map.cc') | |
38 with open(resources_map_path) as resources_map: | |
39 for line in resources_map: | |
40 res = re.match(' {"([^"]+)", ([^}]+)', line) | |
41 if res: | |
42 resource_filenames[res.group(2)] = res.group(1) | |
43 | |
44 # Extract packed files, while preserving directory structure. | |
45 for (resource_id, text) in data.resources.iteritems(): | |
46 filename = resource_filenames[resource_ids[resource_id]] | |
47 dirname = os.path.join(out_path, os.path.dirname(filename)) | |
48 if not os.path.exists(dirname): | |
49 os.makedirs(dirname) | |
50 with open(os.path.join(out_path, filename), 'w') as file: | |
51 file.write(text) | |
52 | |
Dan Beam
2017/01/21 02:39:23
\n\n
dpapad
2017/01/23 22:48:20
Done.
| |
53 if __name__ == '__main__': | |
54 pak_path = os.path.join( | |
55 _SRC_PATH, | |
56 'out/gchrome_gn/gen/chrome/browser/resources/settings/' + | |
Dan Beam
2017/01/21 02:39:23
you need to pass like root_gen_dir or something
dpapad
2017/01/23 22:48:20
Removed main(). That was only useful while debuggi
| |
57 'settings_resources.pak'); | |
58 out_path = os.path.join( | |
59 _SRC_PATH, | |
60 'out/gchrome_gn/gen/chrome/browser/resources/settings/flattened'); | |
61 unpack(pak_path, out_path) | |
OLD | NEW |