OLD | NEW |
(Empty) | |
| 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 |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import argparse |
| 6 import os |
| 7 import plistlib |
| 8 import sys |
| 9 |
| 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 \ |
| 12 # --output Foo.app/Contents/PkgInfo |
| 13 |
| 14 def Main(): |
| 15 parser = argparse.ArgumentParser( |
| 16 description='A script to write PkgInfo files for .app bundles.') |
| 17 parser.add_argument('--plist', required=True, |
| 18 help='Path to the Info.plist for the .app.') |
| 19 parser.add_argument('--output', required=True, |
| 20 help='Path to the desired output file.') |
| 21 args = parser.parse_args() |
| 22 |
| 23 # Remove the output if it exists already. |
| 24 if os.path.exists(args.output): |
| 25 os.unlink(args.output) |
| 26 |
| 27 plist = plistlib.readPlist(args.plist) |
| 28 package_type = plist['CFBundlePackageType'] |
| 29 if package_type != 'APPL': |
| 30 raise ValueError('Expected CFBundlePackageType to be %s, got %s' % \ |
| 31 ('AAPL', package_type)) |
| 32 |
| 33 # The format of PkgInfo is eight characters, representing the bundle type |
| 34 # and bundle signature, each four characters. If that is missing, four |
| 35 # '?' characters are used instead. |
| 36 signature_code = plist.get('CFBundleSignature', '????') |
| 37 if len(signature_code) != 4: |
| 38 raise ValueError('CFBundleSignature should be exactly four characters, ' + |
| 39 'got %s' % signature_code) |
| 40 |
| 41 with open(args.output, 'w') as fp: |
| 42 fp.write('%s%s' % (package_type, signature_code)) |
| 43 return 0 |
| 44 |
| 45 |
| 46 if __name__ == '__main__': |
| 47 sys.exit(Main()) |
OLD | NEW |