Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """A tool for interacting with .pak files. | 6 """A tool for interacting with .pak files. |
| 7 | 7 |
| 8 For details on the pak file format, see: | 8 For details on the pak file format, see: |
| 9 https://dev.chromium.org/developers/design-documents/linuxresourcesandlocalizeds trings | 9 https://dev.chromium.org/developers/design-documents/linuxresourcesandlocalizeds trings |
| 10 """ | 10 """ |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 desc = desc[:60] + u'...' | 55 desc = desc[:60] + u'...' |
| 56 desc = desc.replace('\n', '\\n') | 56 desc = desc.replace('\n', '\\n') |
| 57 except UnicodeDecodeError: | 57 except UnicodeDecodeError: |
| 58 pass | 58 pass |
| 59 sha1 = hashlib.sha1(data).hexdigest()[:10] | 59 sha1 = hashlib.sha1(data).hexdigest()[:10] |
| 60 line = u'Entry(id={}, len={}, sha1={}): {}'.format( | 60 line = u'Entry(id={}, len={}, sha1={}): {}'.format( |
| 61 resource_id, len(data), sha1, desc) | 61 resource_id, len(data), sha1, desc) |
| 62 print line.encode('utf-8') | 62 print line.encode('utf-8') |
| 63 | 63 |
| 64 | 64 |
| 65 def _ListMain(args): | |
| 66 resources, _ = data_pack.ReadDataPack(args.pak_file) | |
| 67 for resource_id in sorted(resources.keys()): | |
| 68 args.output.write('%d\n' % resource_id) | |
| 69 | |
| 70 | |
| 65 def main(): | 71 def main(): |
| 66 parser = argparse.ArgumentParser( | 72 parser = argparse.ArgumentParser( |
| 67 description=__doc__, formatter_class=argparse.RawTextHelpFormatter) | 73 description=__doc__, formatter_class=argparse.RawTextHelpFormatter) |
| 68 sub_parsers = parser.add_subparsers() | 74 sub_parsers = parser.add_subparsers() |
| 69 | 75 |
| 70 sub_parser = sub_parsers.add_parser('repack', | 76 sub_parser = sub_parsers.add_parser('repack', |
| 71 help='Combines several .pak files into one.') | 77 help='Combines several .pak files into one.') |
| 72 sub_parser.add_argument('output_pak_file', help='File to create.') | 78 sub_parser.add_argument('output_pak_file', help='File to create.') |
| 73 sub_parser.add_argument('input_pak_files', nargs='+', | 79 sub_parser.add_argument('input_pak_files', nargs='+', |
| 74 help='Input .pak files.') | 80 help='Input .pak files.') |
| 75 sub_parser.add_argument('--whitelist', | 81 sub_parser.add_argument('--whitelist', |
| 76 help='Path to a whitelist used to filter output pak file resource IDs.') | 82 help='Path to a whitelist used to filter output pak file resource IDs.') |
| 77 sub_parser.add_argument('--suppress-removed-key-output', action='store_true', | 83 sub_parser.add_argument('--suppress-removed-key-output', action='store_true', |
| 78 help='Do not log which keys were removed by the whitelist.') | 84 help='Do not log which keys were removed by the whitelist.') |
| 79 sub_parser.set_defaults(func=_RepackMain) | 85 sub_parser.set_defaults(func=_RepackMain) |
| 80 | 86 |
| 81 sub_parser = sub_parsers.add_parser('extract', help='Extracts pak file') | 87 sub_parser = sub_parsers.add_parser('extract', help='Extracts pak file') |
| 82 sub_parser.add_argument('pak_file') | 88 sub_parser.add_argument('pak_file') |
| 83 sub_parser.add_argument('-o', '--output-dir', default='.', | 89 sub_parser.add_argument('-o', '--output-dir', default='.', |
| 84 help='Directory to extract to.') | 90 help='Directory to extract to.') |
| 85 sub_parser.set_defaults(func=_ExtractMain) | 91 sub_parser.set_defaults(func=_ExtractMain) |
| 86 | 92 |
| 87 sub_parser = sub_parsers.add_parser('print', | 93 sub_parser = sub_parsers.add_parser('print', |
| 88 help='Prints all pak IDs and contents. Useful for diffing.') | 94 help='Prints all pak IDs and contents. Useful for diffing.') |
| 89 sub_parser.add_argument('pak_file') | 95 sub_parser.add_argument('pak_file') |
| 90 sub_parser.set_defaults(func=_PrintMain) | 96 sub_parser.set_defaults(func=_PrintMain) |
| 97 | |
| 98 sub_parser = sub_parsers.add_parser('list', | |
|
agrieve
2017/07/17 13:50:52
nit: Might be nice to just make "print" more capab
F
2017/07/17 14:35:14
Resolved offline. Name changed to "list-id"
| |
| 99 help='Outputs all resource IDs to a file.') | |
| 100 sub_parser.add_argument('pak_file') | |
| 101 sub_parser.add_argument('--output', type=argparse.FileType('w'), | |
| 102 default=sys.stdout, | |
| 103 help='The resource list path to write (default stdout)') | |
| 104 sub_parser.set_defaults(func=_ListMain) | |
| 91 | 105 |
| 92 if len(sys.argv) == 1: | 106 if len(sys.argv) == 1: |
| 93 parser.print_help() | 107 parser.print_help() |
| 94 sys.exit(1) | 108 sys.exit(1) |
| 95 elif len(sys.argv) == 2 and sys.argv[1] in actions: | 109 elif len(sys.argv) == 2 and sys.argv[1] in actions: |
| 96 parser.parse_args(sys.argv[1:] + ['-h']) | 110 parser.parse_args(sys.argv[1:] + ['-h']) |
| 97 sys.exit(1) | 111 sys.exit(1) |
| 98 | 112 |
| 99 args = parser.parse_args() | 113 args = parser.parse_args() |
| 100 args.func(args) | 114 args.func(args) |
| 101 | 115 |
| 102 | 116 |
| 103 if __name__ == '__main__': | 117 if __name__ == '__main__': |
| 104 main() | 118 main() |
| OLD | NEW |