filter_resource_allowlist.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. """filter_resource_allowlist.py [-h] [--input INPUT] [--filter FILTER]
  6. [--output OUTPUT]
  7. INPUT specifies a resource allowlist file containing resource IDs that should
  8. be allowed, where each line of INPUT contains a single resource ID.
  9. FILTER specifies a resource denylist file containing resource IDs that should
  10. not be allowed, where each line of FILTER contains a single resource ID.
  11. Filters a resource allowlist by removing resource IDs that are contained in a
  12. another resource allowlist.
  13. This script is used to generate Monochrome's locale paks.
  14. """
  15. import argparse
  16. import sys
  17. def main():
  18. parser = argparse.ArgumentParser(usage=__doc__)
  19. parser.add_argument(
  20. '--input', type=argparse.FileType('r'), required=True,
  21. help='A resource allowlist where each line contains one resource ID. '
  22. 'These IDs, excluding the ones in FILTER, are to be included.')
  23. parser.add_argument(
  24. '--filter', type=argparse.FileType('r'), required=True,
  25. help='A resource allowlist where each line contains one resource ID. '
  26. 'These IDs are to be excluded.')
  27. parser.add_argument(
  28. '--output', type=argparse.FileType('w'), default=sys.stdout,
  29. help='The resource list path to write (default stdout)')
  30. args = parser.parse_args()
  31. input_resources = list(int(resource_id) for resource_id in args.input)
  32. filter_resources = set(int(resource_id) for resource_id in args.filter)
  33. output_resources = [resource_id for resource_id in input_resources
  34. if resource_id not in filter_resources]
  35. for resource_id in sorted(output_resources):
  36. args.output.write('%d\n' % resource_id)
  37. if __name__ == '__main__':
  38. main()