Chromium Code Reviews| Index: tools/resources/filter_resource_whitelist.py |
| diff --git a/tools/resources/filter_resource_whitelist.py b/tools/resources/filter_resource_whitelist.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..17f07b68e8cbdf57043242c7df3046a101e98222 |
| --- /dev/null |
| +++ b/tools/resources/filter_resource_whitelist.py |
| @@ -0,0 +1,55 @@ |
| +#!/usr/bin/env python |
|
agrieve
2017/06/29 01:29:25
Also: Add yourself (and me) to the OWNERS file her
F
2017/06/29 18:31:20
Done.
|
| +# Copyright 2017 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import argparse |
| +import os |
| +import re |
| +import sys |
| + |
| +USAGE = """filter_resource_whitelist.py [-h] [-i INPUT] [-f FILTER] [-o OUTPUT] |
|
agrieve
2017/06/29 01:09:53
nit: Use this as the __doc__ string (put before im
F
2017/06/29 18:31:20
Done.
|
| + |
| +INPUT specifies a resource whitelist file containing resource IDs that should |
| +be whitelisted, where each line of INPUT contains a single resource ID. |
| + |
| +FILTER specifies a resource whitelist file containing resource IDs that should |
| +not be whitelisted, where each line of FILTER contains a single resource ID. |
| + |
| +Filters a resource whitelist by removing resource IDs that are contained in a |
| +another resource whitelist. |
| + |
| +This script is used to generate Monochrome's locale paks. |
| + |
|
agrieve
2017/06/29 01:09:53
nit: remove blank line
F
2017/06/29 18:31:20
Done.
|
| +""" |
| + |
| + |
| +def main(): |
| + parser = argparse.ArgumentParser(usage=USAGE) |
| + parser.add_argument( |
| + '-i', '--input', type=argparse.FileType('r'), default=sys.stdin, |
|
agrieve
2017/06/29 01:09:53
nit: drop the short form arguments. They just serv
F
2017/06/29 18:31:20
Done.
|
| + help='A resource whitelist where each line contains one resource ID. ' |
| + 'These IDs, excluding the ones in FILTER, are to be included.') |
| + parser.add_argument( |
| + '-f', '--filter', type=argparse.FileType('r'), default=sys.stdin, |
|
agrieve
2017/06/29 01:09:53
Seems strange to have two different flags default
F
2017/06/29 18:31:20
Done.
|
| + help='A resource whitelist where each line contains one resource ID. ' |
| + 'These IDs are to be excluded.') |
| + parser.add_argument( |
| + '-o', '--output', type=argparse.FileType('w'), default=sys.stdout, |
| + help='The resource list path to write (default stdout)') |
| + parser.add_argument( |
| + '--out-dir', required=True, |
|
agrieve
2017/06/29 01:09:53
nit: call this '--output-directory' to be consiste
F
2017/06/29 18:31:20
Done.
|
| + help='The out target directory, for example out/Release') |
| + |
| + args = parser.parse_args() |
| + |
| + input_resources = list(int(resource_id) for resource_id in args.input) |
| + filter_resources = set(int(resource_id) for resource_id in args.filter) |
| + output_resources = [resource_id for resource_id in input_resources |
| + if resource_id not in filter_resources] |
| + |
| + for resource_id in sorted(output_resources): |
| + args.output.write('%d\n' % resource_id) |
| + |
| +if __name__ == '__main__': |
| + main() |