OLD | NEW |
---|---|
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import argparse | 5 import argparse |
6 import os | 6 import os |
7 import plistlib | 7 import plist_util |
8 import sys | 8 import sys |
9 | 9 |
10 # This script creates a PkgInfo file for an OS X .app bundle's plist. | 10 # This script creates a PkgInfo file for an OS X .app bundle's plist. |
11 # Usage: python write_pkg_info.py --plist Foo.app/Contents/Info.plist \ | 11 # Usage: python write_pkg_info.py --plist Foo.app/Contents/Info.plist \ |
12 # --output Foo.app/Contents/PkgInfo | 12 # --output Foo.app/Contents/PkgInfo |
13 | 13 |
14 def Main(): | 14 def Main(): |
15 parser = argparse.ArgumentParser( | 15 parser = argparse.ArgumentParser( |
16 description='A script to write PkgInfo files for .app bundles.') | 16 description='A script to write PkgInfo files for .app bundles.') |
17 parser.add_argument('--plist', required=True, | 17 parser.add_argument('--plist', required=True, |
18 help='Path to the Info.plist for the .app.') | 18 help='Path to the Info.plist for the .app.') |
19 parser.add_argument('--output', required=True, | 19 parser.add_argument('--output', required=True, |
20 help='Path to the desired output file.') | 20 help='Path to the desired output file.') |
21 args = parser.parse_args() | 21 args = parser.parse_args() |
22 | 22 |
23 # Remove the output if it exists already. | 23 # Remove the output if it exists already. |
24 if os.path.exists(args.output): | 24 if os.path.exists(args.output): |
25 os.unlink(args.output) | 25 os.unlink(args.output) |
26 | 26 |
27 plist = plistlib.readPlist(args.plist) | 27 plist = plist_util.LoadPList(args.plist) |
28 package_type = plist['CFBundlePackageType'] | 28 package_type = plist['CFBundlePackageType'] |
29 if package_type != 'APPL': | 29 if package_type != 'APPL': |
30 raise ValueError('Expected CFBundlePackageType to be %s, got %s' % \ | 30 raise ValueError('Expected CFBundlePackageType to be %s, got %s' % \ |
31 ('AAPL', package_type)) | 31 ('AAPL', package_type)) |
Robert Sesek
2016/12/09 15:55:08
I made a typo here but if it's already in the CQ,
sdefresne
2016/12/09 16:03:06
Will do in a followup :-)
| |
32 | 32 |
33 # The format of PkgInfo is eight characters, representing the bundle type | 33 # The format of PkgInfo is eight characters, representing the bundle type |
34 # and bundle signature, each four characters. If that is missing, four | 34 # and bundle signature, each four characters. If that is missing, four |
35 # '?' characters are used instead. | 35 # '?' characters are used instead. |
36 signature_code = plist.get('CFBundleSignature', '????') | 36 signature_code = plist.get('CFBundleSignature', '????') |
37 if len(signature_code) != 4: | 37 if len(signature_code) != 4: |
38 raise ValueError('CFBundleSignature should be exactly four characters, ' + | 38 raise ValueError('CFBundleSignature should be exactly four characters, ' + |
39 'got %s' % signature_code) | 39 'got %s' % signature_code) |
40 | 40 |
41 with open(args.output, 'w') as fp: | 41 with open(args.output, 'w') as fp: |
42 fp.write('%s%s' % (package_type, signature_code)) | 42 fp.write('%s%s' % (package_type, signature_code)) |
43 return 0 | 43 return 0 |
44 | 44 |
45 | 45 |
46 if __name__ == '__main__': | 46 if __name__ == '__main__': |
47 sys.exit(Main()) | 47 sys.exit(Main()) |
OLD | NEW |