This commit was manufactured by cvs2svn to create tag 'r234c1'.
[python/dscho.git] / Mac / scripts / buildappbundle.py
blob281c6fea6dd79fd67bf90ec5f339284d21612ba7
1 #! /usr/bin/env python
3 # XXX This will be replaced by a main program in Mac/Lib/bundlebuilder.py,
4 # but for now this is kept so Jack won't need to change his scripts...
7 """\
8 buildappbundle creates an application bundle
9 Usage:
10 buildappbundle [options] executable
11 Options:
12 --output o Output file; default executable with .app appended, short -o
13 --link Symlink the executable instead of copying it, short -l
14 --plist file Plist file (default: generate one), short -p
15 --nib file Main nib file or lproj folder for Cocoa program, short -n
16 --resource r Extra resource file to be copied to Resources, short -r
17 --creator c 4-char creator code (default: '????'), short -c
18 --verbose increase verbosity level (default: quiet), short -v
19 --help This message, short -? or -h
20 """
23 import sys
24 import os
25 import getopt
26 from bundlebuilder import AppBuilder
27 from plistlib import Plist
30 def usage():
31 print __doc__
32 sys.exit(1)
35 def main():
36 output = None
37 symlink = 0
38 creator = "????"
39 plist = None
40 nib = None
41 resources = []
42 verbosity = 0
43 SHORTOPTS = "o:ln:r:p:c:v?h"
44 LONGOPTS=("output=", "link", "nib=", "resource=", "plist=", "creator=", "help",
45 "verbose")
46 try:
47 options, args = getopt.getopt(sys.argv[1:], SHORTOPTS, LONGOPTS)
48 except getopt.error:
49 usage()
50 if len(args) != 1:
51 usage()
52 executable = args[0]
53 for opt, arg in options:
54 if opt in ('-o', '--output'):
55 output = arg
56 elif opt in ('-l', '--link'):
57 symlink = 1
58 elif opt in ('-n', '--nib'):
59 nib = arg
60 elif opt in ('-r', '--resource'):
61 resources.append(arg)
62 elif opt in ('-c', '--creator'):
63 creator = arg
64 elif opt in ('-p', '--plist'):
65 plist = arg
66 elif opt in ('-v', '--verbose'):
67 verbosity += 1
68 elif opt in ('-?', '-h', '--help'):
69 usage()
70 if output is not None:
71 builddir, bundlename = os.path.split(output)
72 else:
73 builddir = os.curdir
74 bundlename = None # will be derived from executable
75 if plist is not None:
76 plist = Plist.fromFile(plist)
78 builder = AppBuilder(name=bundlename, executable=executable,
79 builddir=builddir, creator=creator, plist=plist, resources=resources,
80 symlink_exec=symlink, verbosity=verbosity)
82 if nib is not None:
83 resources.append(nib)
84 nibname, ext = os.path.splitext(os.path.basename(nib))
85 if ext == '.lproj':
86 # Special case: if the main nib is a .lproj we assum a directory
87 # and use the first nib from there. XXX Look: an arbitrary pick ;-)
88 files = os.listdir(nib)
89 for f in files:
90 if f[-4:] == '.nib':
91 nibname = os.path.split(f)[1][:-4]
92 break
93 else:
94 nibname = ""
95 if nibname:
96 builder.plist.NSMainNibFile = nibname
97 if not hasattr(builder.plist, "NSPrincipalClass"):
98 builder.plist.NSPrincipalClass = "NSApplication"
99 builder.setup()
100 builder.build()
103 if __name__ == '__main__':
104 main()