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

Side by Side Diff: tools/resources/filter_resource_whitelist.py

Issue 2933343002: Deduplicate Monochrome locale .paks (Closed)
Patch Set: Addressing comments Created 3 years, 5 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 2017 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 __doc__ = """filter_resource_whitelist.py [-h] [--input INPUT]
7 [--filter FILTER] [--output OUTPUT] [--output-directory OUTPUT_DIRECTORY]
8
9 INPUT specifies a resource whitelist file containing resource IDs that should
10 be whitelisted, where each line of INPUT contains a single resource ID.
11
12 FILTER specifies a resource whitelist file containing resource IDs that should
13 not be whitelisted, where each line of FILTER contains a single resource ID.
14
15 Filters a resource whitelist by removing resource IDs that are contained in a
16 another resource whitelist.
17
18 This script is used to generate Monochrome's locale paks.
19 """
20
21 import argparse
22 import os
Lei Zhang 2017/06/29 19:08:31 os and re aren't used?
F 2017/06/29 19:20:03 Done.
23 import re
24 import sys
25
26
27 def main():
28 parser = argparse.ArgumentParser(usage=__doc__)
29 parser.add_argument(
30 '--input', type=argparse.FileType('r'), required=True,
31 help='A resource whitelist where each line contains one resource ID. '
32 'These IDs, excluding the ones in FILTER, are to be included.')
33 parser.add_argument(
34 '--filter', type=argparse.FileType('r'), required=True,
35 help='A resource whitelist where each line contains one resource ID. '
36 'These IDs are to be excluded.')
37 parser.add_argument(
38 '--output', type=argparse.FileType('w'), default=sys.stdout,
39 help='The resource list path to write (default stdout)')
40 parser.add_argument(
41 '--output-directory', required=True,
42 help='The out target directory, for example out/Release')
43
44 args = parser.parse_args()
45
46 input_resources = list(int(resource_id) for resource_id in args.input)
47 filter_resources = set(int(resource_id) for resource_id in args.filter)
48 output_resources = [resource_id for resource_id in input_resources
49 if resource_id not in filter_resources]
50
51 for resource_id in sorted(output_resources):
52 args.output.write('%d\n' % resource_id)
53
54 if __name__ == '__main__':
55 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698