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

Side by Side Diff: chrome/browser/resources/unpack_pak.py

Issue 2569283002: WebUI: Add GN rules for Vulcanize. (Closed)
Patch Set: Rename Created 3 years, 11 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
OLDNEW
(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 _HERE_PATH = os.path.join(os.path.dirname(__file__))
11 _SRC_PATH = os.path.normpath(os.path.join(_HERE_PATH, '..', '..', '..'))
12 sys.path.append(os.path.join(_SRC_PATH, 'tools', 'grit'))
13 from grit.format import data_pack
14
15 def unpack(pak_path, out_path):
16 pak_dir = os.path.dirname(pak_path);
17 pak_id = os.path.splitext(os.path.basename(pak_path))[0]
18
19 data = data_pack.DataPack.ReadDataPack(pak_path)
20
21 # Associate numerical grit IDs to strings.
22 # For example 120045 -> 'IDR_SETTINGS_ABOUT_PAGE_HTML'
23 resource_ids = dict()
24 resources_path = os.path.join(pak_dir, 'grit', pak_id + '.h')
25 with open(resources_path) as resources_file:
26 for line in resources_file:
27 res = re.match('#define ([^ ]+) (\d+)', line)
28 if res:
29 resource_ids[int(res.group(2))] = res.group(1)
30
31 # Associate numerical string IDs to files.
32 resource_filenames = dict()
33 resources_map_path = os.path.join(pak_dir, 'grit', pak_id + '_map.cc')
34 with open(resources_map_path) as resources_map:
35 for line in resources_map:
36 res = re.match(' {"([^"]+)", ([^}]+)', line)
37 if res:
38 resource_filenames[res.group(2)] = res.group(1)
39
40 # Extract packed files, while preserving directory structure.
41 for (resource_id, text) in data.resources.iteritems():
42 #print '%s: %s' % (resource_id, text)
43
44 filename = resource_filenames[resource_ids[resource_id]]
45 dirname = os.path.join(out_path, os.path.dirname(filename))
46 if not os.path.exists(dirname):
47 os.makedirs(dirname)
48 with open(os.path.join(out_path, filename), 'w') as file:
49 file.write(text)
50
51 if __name__ == '__main__':
52 pak_path = os.path.join(
53 _SRC_PATH,
54 'out/gchrome_gn/gen/chrome/browser/resources/settings/' +
55 'settings_resources.pak');
56 out_path = os.path.join(
57 _SRC_PATH,
58 'out/gchrome_gn/gen/chrome/browser/resources/settings/flattened');
59 unpack(pak_path, out_path)
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/vulcanize.gni » ('j') | chrome/browser/resources/vulcanize.gni » ('J')

Powered by Google App Engine
This is Rietveld 408576698