blob: 9c79e30e09e8963950df4922ac9e7238f00d42a0 [file] [log] [blame]
Just van Rossumad33d722002-11-21 10:23:04 +00001#! /usr/bin/env python
2
3"""\
4bundlebuilder.py -- Tools to assemble MacOS X (application) bundles.
5
Just van Rossumceeb9622002-11-21 23:19:37 +00006This module contains two classes to build so called "bundles" for
Just van Rossumad33d722002-11-21 10:23:04 +00007MacOS X. BundleBuilder is a general tool, AppBuilder is a subclass
Just van Rossumceeb9622002-11-21 23:19:37 +00008specialized in building application bundles.
Just van Rossumad33d722002-11-21 10:23:04 +00009
Just van Rossumceeb9622002-11-21 23:19:37 +000010[Bundle|App]Builder objects are instantiated with a bunch of keyword
11arguments, and have a build() method that will do all the work. See
12the class doc strings for a description of the constructor arguments.
13
14The module contains a main program that can be used in two ways:
15
16 % python bundlebuilder.py [options] build
17 % python buildapp.py [options] build
18
19Where "buildapp.py" is a user-supplied setup.py-like script following
20this model:
21
22 from bundlebuilder import buildapp
23 buildapp(<lots-of-keyword-args>)
Just van Rossumad33d722002-11-21 10:23:04 +000024
25"""
26
Just van Rossumad33d722002-11-21 10:23:04 +000027
Just van Rossumcef32882002-11-26 00:34:52 +000028__all__ = ["BundleBuilder", "BundleBuilderError", "AppBuilder", "buildapp"]
Just van Rossumad33d722002-11-21 10:23:04 +000029
30
31import sys
32import os, errno, shutil
Just van Rossumcef32882002-11-26 00:34:52 +000033import imp, marshal
34import re
Just van Rossumda302da2002-11-23 22:26:44 +000035from copy import deepcopy
Just van Rossumceeb9622002-11-21 23:19:37 +000036import getopt
Just van Rossumad33d722002-11-21 10:23:04 +000037from plistlib import Plist
Just van Rossumda302da2002-11-23 22:26:44 +000038from types import FunctionType as function
Just van Rossumad33d722002-11-21 10:23:04 +000039
Just van Rossumcef32882002-11-26 00:34:52 +000040class BundleBuilderError(Exception): pass
41
42
Just van Rossumda302da2002-11-23 22:26:44 +000043class Defaults:
44
Jack Jansen0ae32202003-04-09 13:25:43 +000045 """Class attributes that don't start with an underscore and are
46 not functions or classmethods are (deep)copied to self.__dict__.
47 This allows for mutable default values.
48 """
Just van Rossumda302da2002-11-23 22:26:44 +000049
Jack Jansen0ae32202003-04-09 13:25:43 +000050 def __init__(self, **kwargs):
51 defaults = self._getDefaults()
52 defaults.update(kwargs)
53 self.__dict__.update(defaults)
Just van Rossumda302da2002-11-23 22:26:44 +000054
Jack Jansen0ae32202003-04-09 13:25:43 +000055 def _getDefaults(cls):
56 defaults = {}
57 for name, value in cls.__dict__.items():
58 if name[0] != "_" and not isinstance(value,
59 (function, classmethod)):
60 defaults[name] = deepcopy(value)
61 for base in cls.__bases__:
62 if hasattr(base, "_getDefaults"):
63 defaults.update(base._getDefaults())
64 return defaults
65 _getDefaults = classmethod(_getDefaults)
Just van Rossumad33d722002-11-21 10:23:04 +000066
67
Just van Rossumda302da2002-11-23 22:26:44 +000068class BundleBuilder(Defaults):
Just van Rossumad33d722002-11-21 10:23:04 +000069
Jack Jansen0ae32202003-04-09 13:25:43 +000070 """BundleBuilder is a barebones class for assembling bundles. It
71 knows nothing about executables or icons, it only copies files
72 and creates the PkgInfo and Info.plist files.
73 """
Just van Rossumad33d722002-11-21 10:23:04 +000074
Jack Jansen0ae32202003-04-09 13:25:43 +000075 # (Note that Defaults.__init__ (deep)copies these values to
76 # instance variables. Mutable defaults are therefore safe.)
Just van Rossumda302da2002-11-23 22:26:44 +000077
Jack Jansen0ae32202003-04-09 13:25:43 +000078 # Name of the bundle, with or without extension.
79 name = None
Just van Rossumda302da2002-11-23 22:26:44 +000080
Jack Jansen0ae32202003-04-09 13:25:43 +000081 # The property list ("plist")
82 plist = Plist(CFBundleDevelopmentRegion = "English",
83 CFBundleInfoDictionaryVersion = "6.0")
Just van Rossumda302da2002-11-23 22:26:44 +000084
Jack Jansen0ae32202003-04-09 13:25:43 +000085 # The type of the bundle.
86 type = "BNDL"
87 # The creator code of the bundle.
88 creator = None
Just van Rossumda302da2002-11-23 22:26:44 +000089
Jack Jansen0ae32202003-04-09 13:25:43 +000090 # List of files that have to be copied to <bundle>/Contents/Resources.
91 resources = []
Just van Rossumda302da2002-11-23 22:26:44 +000092
Jack Jansen0ae32202003-04-09 13:25:43 +000093 # List of (src, dest) tuples; dest should be a path relative to the bundle
94 # (eg. "Contents/Resources/MyStuff/SomeFile.ext).
95 files = []
Just van Rossumda302da2002-11-23 22:26:44 +000096
Jack Jansen0ae32202003-04-09 13:25:43 +000097 # List of shared libraries (dylibs, Frameworks) to bundle with the app
98 # will be placed in Contents/Frameworks
99 libs = []
Just van Rossum15624d82003-03-21 09:26:59 +0000100
Jack Jansen0ae32202003-04-09 13:25:43 +0000101 # Directory where the bundle will be assembled.
102 builddir = "build"
Just van Rossumda302da2002-11-23 22:26:44 +0000103
Jack Jansen0ae32202003-04-09 13:25:43 +0000104 # Make symlinks instead copying files. This is handy during debugging, but
105 # makes the bundle non-distributable.
106 symlink = 0
Just van Rossumda302da2002-11-23 22:26:44 +0000107
Jack Jansen0ae32202003-04-09 13:25:43 +0000108 # Verbosity level.
109 verbosity = 1
Just van Rossumad33d722002-11-21 10:23:04 +0000110
Jack Jansen0ae32202003-04-09 13:25:43 +0000111 def setup(self):
112 # XXX rethink self.name munging, this is brittle.
113 self.name, ext = os.path.splitext(self.name)
114 if not ext:
115 ext = ".bundle"
116 bundleextension = ext
117 # misc (derived) attributes
118 self.bundlepath = pathjoin(self.builddir, self.name + bundleextension)
Just van Rossumceeb9622002-11-21 23:19:37 +0000119
Jack Jansen0ae32202003-04-09 13:25:43 +0000120 plist = self.plist
121 plist.CFBundleName = self.name
122 plist.CFBundlePackageType = self.type
123 if self.creator is None:
124 if hasattr(plist, "CFBundleSignature"):
125 self.creator = plist.CFBundleSignature
126 else:
127 self.creator = "????"
128 plist.CFBundleSignature = self.creator
129 if not hasattr(plist, "CFBundleIdentifier"):
130 plist.CFBundleIdentifier = self.name
Just van Rossumceeb9622002-11-21 23:19:37 +0000131
Jack Jansen0ae32202003-04-09 13:25:43 +0000132 def build(self):
133 """Build the bundle."""
134 builddir = self.builddir
135 if builddir and not os.path.exists(builddir):
136 os.mkdir(builddir)
137 self.message("Building %s" % repr(self.bundlepath), 1)
138 if os.path.exists(self.bundlepath):
139 shutil.rmtree(self.bundlepath)
140 os.mkdir(self.bundlepath)
141 self.preProcess()
142 self._copyFiles()
143 self._addMetaFiles()
144 self.postProcess()
145 self.message("Done.", 1)
Just van Rossumad33d722002-11-21 10:23:04 +0000146
Jack Jansen0ae32202003-04-09 13:25:43 +0000147 def preProcess(self):
148 """Hook for subclasses."""
149 pass
150 def postProcess(self):
151 """Hook for subclasses."""
152 pass
Just van Rossumad33d722002-11-21 10:23:04 +0000153
Jack Jansen0ae32202003-04-09 13:25:43 +0000154 def _addMetaFiles(self):
155 contents = pathjoin(self.bundlepath, "Contents")
156 makedirs(contents)
157 #
158 # Write Contents/PkgInfo
159 assert len(self.type) == len(self.creator) == 4, \
160 "type and creator must be 4-byte strings."
161 pkginfo = pathjoin(contents, "PkgInfo")
162 f = open(pkginfo, "wb")
163 f.write(self.type + self.creator)
164 f.close()
165 #
166 # Write Contents/Info.plist
167 infoplist = pathjoin(contents, "Info.plist")
168 self.plist.write(infoplist)
Just van Rossumad33d722002-11-21 10:23:04 +0000169
Jack Jansen0ae32202003-04-09 13:25:43 +0000170 def _copyFiles(self):
171 files = self.files[:]
172 for path in self.resources:
173 files.append((path, pathjoin("Contents", "Resources",
Just van Rossumdc31dc02003-06-20 21:43:36 +0000174 os.path.basename(path))))
Jack Jansen0ae32202003-04-09 13:25:43 +0000175 for path in self.libs:
176 files.append((path, pathjoin("Contents", "Frameworks",
Just van Rossumdc31dc02003-06-20 21:43:36 +0000177 os.path.basename(path))))
Jack Jansen0ae32202003-04-09 13:25:43 +0000178 if self.symlink:
179 self.message("Making symbolic links", 1)
180 msg = "Making symlink from"
181 else:
182 self.message("Copying files", 1)
183 msg = "Copying"
184 files.sort()
185 for src, dst in files:
186 if os.path.isdir(src):
187 self.message("%s %s/ to %s/" % (msg, src, dst), 2)
188 else:
189 self.message("%s %s to %s" % (msg, src, dst), 2)
190 dst = pathjoin(self.bundlepath, dst)
191 if self.symlink:
192 symlink(src, dst, mkdirs=1)
193 else:
194 copy(src, dst, mkdirs=1)
Just van Rossumad33d722002-11-21 10:23:04 +0000195
Jack Jansen0ae32202003-04-09 13:25:43 +0000196 def message(self, msg, level=0):
197 if level <= self.verbosity:
198 indent = ""
199 if level > 1:
200 indent = (level - 1) * " "
201 sys.stderr.write(indent + msg + "\n")
Just van Rossumceeb9622002-11-21 23:19:37 +0000202
Jack Jansen0ae32202003-04-09 13:25:43 +0000203 def report(self):
204 # XXX something decent
205 pass
Just van Rossumad33d722002-11-21 10:23:04 +0000206
207
Just van Rossumcef32882002-11-26 00:34:52 +0000208if __debug__:
Jack Jansen0ae32202003-04-09 13:25:43 +0000209 PYC_EXT = ".pyc"
Just van Rossumcef32882002-11-26 00:34:52 +0000210else:
Jack Jansen0ae32202003-04-09 13:25:43 +0000211 PYC_EXT = ".pyo"
Just van Rossumcef32882002-11-26 00:34:52 +0000212
213MAGIC = imp.get_magic()
Just van Rossum109ecbf2003-01-02 13:13:01 +0000214USE_ZIPIMPORT = "zipimport" in sys.builtin_module_names
Just van Rossumcef32882002-11-26 00:34:52 +0000215
216# For standalone apps, we have our own minimal site.py. We don't need
217# all the cruft of the real site.py.
218SITE_PY = """\
219import sys
Just van Rossum762d2cc2003-06-29 21:54:12 +0000220if not %(semi_standalone)s:
221 del sys.path[1:] # sys.path[0] is Contents/Resources/
Just van Rossumcef32882002-11-26 00:34:52 +0000222"""
223
Just van Rossum109ecbf2003-01-02 13:13:01 +0000224if USE_ZIPIMPORT:
Jack Jansen0ae32202003-04-09 13:25:43 +0000225 ZIP_ARCHIVE = "Modules.zip"
226 SITE_PY += "sys.path.append(sys.path[0] + '/%s')\n" % ZIP_ARCHIVE
227 def getPycData(fullname, code, ispkg):
228 if ispkg:
229 fullname += ".__init__"
230 path = fullname.replace(".", os.sep) + PYC_EXT
231 return path, MAGIC + '\0\0\0\0' + marshal.dumps(code)
Just van Rossumcef32882002-11-26 00:34:52 +0000232
Just van Rossum8a3ed3f2003-02-25 20:53:12 +0000233#
234# Extension modules can't be in the modules zip archive, so a placeholder
235# is added instead, that loads the extension from a specified location.
236#
Just van Rossum535ffa22002-11-29 20:06:52 +0000237EXT_LOADER = """\
Just van Rossum109ecbf2003-01-02 13:13:01 +0000238def __load():
Jack Jansen0ae32202003-04-09 13:25:43 +0000239 import imp, sys, os
240 for p in sys.path:
241 path = os.path.join(p, "%(filename)s")
242 if os.path.exists(path):
243 break
244 else:
245 assert 0, "file not found: %(filename)s"
246 mod = imp.load_dynamic("%(name)s", path)
Just van Rossum109ecbf2003-01-02 13:13:01 +0000247
248__load()
249del __load
Just van Rossum535ffa22002-11-29 20:06:52 +0000250"""
251
Just van Rossumcef32882002-11-26 00:34:52 +0000252MAYMISS_MODULES = ['mac', 'os2', 'nt', 'ntpath', 'dos', 'dospath',
Jack Jansen0ae32202003-04-09 13:25:43 +0000253 'win32api', 'ce', '_winreg', 'nturl2path', 'sitecustomize',
254 'org.python.core', 'riscos', 'riscosenviron', 'riscospath'
Just van Rossumcef32882002-11-26 00:34:52 +0000255]
256
257STRIP_EXEC = "/usr/bin/strip"
258
Just van Rossum8a3ed3f2003-02-25 20:53:12 +0000259#
260# We're using a stock interpreter to run the app, yet we need
261# a way to pass the Python main program to the interpreter. The
262# bootstrapping script fires up the interpreter with the right
263# arguments. os.execve() is used as OSX doesn't like us to
264# start a real new process. Also, the executable name must match
265# the CFBundleExecutable value in the Info.plist, so we lie
266# deliberately with argv[0]. The actual Python executable is
267# passed in an environment variable so we can "repair"
268# sys.executable later.
269#
Just van Rossum74bdca82002-11-28 11:30:56 +0000270BOOTSTRAP_SCRIPT = """\
Just van Rossum0ff7a4e2003-02-26 11:27:56 +0000271#!%(hashbang)s
Just van Rossumad33d722002-11-21 10:23:04 +0000272
Just van Rossum7322b1a2003-02-25 20:15:40 +0000273import sys, os
274execdir = os.path.dirname(sys.argv[0])
275executable = os.path.join(execdir, "%(executable)s")
276resdir = os.path.join(os.path.dirname(execdir), "Resources")
Just van Rossum15624d82003-03-21 09:26:59 +0000277libdir = os.path.join(os.path.dirname(execdir), "Frameworks")
Just van Rossum7322b1a2003-02-25 20:15:40 +0000278mainprogram = os.path.join(resdir, "%(mainprogram)s")
279
280sys.argv.insert(1, mainprogram)
281os.environ["PYTHONPATH"] = resdir
Just van Rossum82ad32e2003-03-21 11:32:37 +0000282if %(standalone)s:
Jack Jansen0ae32202003-04-09 13:25:43 +0000283 os.environ["PYTHONHOME"] = resdir
Just van Rossum7322b1a2003-02-25 20:15:40 +0000284os.environ["PYTHONEXECUTABLE"] = executable
Just van Rossum15624d82003-03-21 09:26:59 +0000285os.environ["DYLD_LIBRARY_PATH"] = libdir
Just van Rossum3166f592003-06-20 18:56:10 +0000286os.environ["DYLD_FRAMEWORK_PATH"] = libdir
Just van Rossum7322b1a2003-02-25 20:15:40 +0000287os.execve(executable, sys.argv, os.environ)
Just van Rossumad33d722002-11-21 10:23:04 +0000288"""
289
Just van Rossum8a3ed3f2003-02-25 20:53:12 +0000290
291#
292# Optional wrapper that converts "dropped files" into sys.argv values.
293#
294ARGV_EMULATOR = """\
Jack Jansena03adde2003-02-18 23:29:46 +0000295import argvemulator, os
296
297argvemulator.ArgvCollector().mainloop()
298execfile(os.path.join(os.path.split(__file__)[0], "%(realmainprogram)s"))
299"""
Just van Rossumcef32882002-11-26 00:34:52 +0000300
Just van Rossum3166f592003-06-20 18:56:10 +0000301#
302# When building a standalone app with Python.framework, we need to copy
303# a subset from Python.framework to the bundle. The following list
304# specifies exactly what items we'll copy.
305#
306PYTHONFRAMEWORKGOODIES = [
307 "Python", # the Python core library
308 "Resources/English.lproj",
309 "Resources/Info.plist",
310 "Resources/version.plist",
311]
312
Just van Rossum79b0ae12003-06-29 22:20:26 +0000313def isFramework():
314 return sys.exec_prefix.find("Python.framework") > 0
315
Just van Rossum8a3ed3f2003-02-25 20:53:12 +0000316
Just van Rossum762d2cc2003-06-29 21:54:12 +0000317LIB = os.path.join(sys.prefix, "lib", "python" + sys.version[:3])
318SITE_PACKAGES = os.path.join(LIB, "site-packages")
319
320
Just van Rossumad33d722002-11-21 10:23:04 +0000321class AppBuilder(BundleBuilder):
322
Jack Jansen0ae32202003-04-09 13:25:43 +0000323 # Override type of the bundle.
324 type = "APPL"
Jack Jansencc81b802003-03-05 14:42:18 +0000325
Jack Jansen0ae32202003-04-09 13:25:43 +0000326 # platform, name of the subfolder of Contents that contains the executable.
327 platform = "MacOS"
Jack Jansencc81b802003-03-05 14:42:18 +0000328
Jack Jansen0ae32202003-04-09 13:25:43 +0000329 # A Python main program. If this argument is given, the main
330 # executable in the bundle will be a small wrapper that invokes
331 # the main program. (XXX Discuss why.)
332 mainprogram = None
Just van Rossumceeb9622002-11-21 23:19:37 +0000333
Jack Jansen0ae32202003-04-09 13:25:43 +0000334 # The main executable. If a Python main program is specified
335 # the executable will be copied to Resources and be invoked
336 # by the wrapper program mentioned above. Otherwise it will
337 # simply be used as the main executable.
338 executable = None
Just van Rossumceeb9622002-11-21 23:19:37 +0000339
Jack Jansen0ae32202003-04-09 13:25:43 +0000340 # The name of the main nib, for Cocoa apps. *Must* be specified
341 # when building a Cocoa app.
342 nibname = None
Just van Rossumad33d722002-11-21 10:23:04 +0000343
Jack Jansen0ae32202003-04-09 13:25:43 +0000344 # The name of the icon file to be copied to Resources and used for
345 # the Finder icon.
346 iconfile = None
Just van Rossum2aa09562003-02-01 08:34:46 +0000347
Jack Jansen0ae32202003-04-09 13:25:43 +0000348 # Symlink the executable instead of copying it.
349 symlink_exec = 0
Just van Rossumad33d722002-11-21 10:23:04 +0000350
Jack Jansen0ae32202003-04-09 13:25:43 +0000351 # If True, build standalone app.
352 standalone = 0
Just van Rossum3166f592003-06-20 18:56:10 +0000353
Just van Rossum762d2cc2003-06-29 21:54:12 +0000354 # If True, build semi-standalone app (only includes third-party modules).
355 semi_standalone = 0
356
Jack Jansen8ba0e802003-05-25 22:00:17 +0000357 # If set, use this for #! lines in stead of sys.executable
358 python = None
Just van Rossum3166f592003-06-20 18:56:10 +0000359
Jack Jansen0ae32202003-04-09 13:25:43 +0000360 # If True, add a real main program that emulates sys.argv before calling
361 # mainprogram
362 argv_emulation = 0
Just van Rossumcef32882002-11-26 00:34:52 +0000363
Jack Jansen0ae32202003-04-09 13:25:43 +0000364 # The following attributes are only used when building a standalone app.
Just van Rossumcef32882002-11-26 00:34:52 +0000365
Jack Jansen0ae32202003-04-09 13:25:43 +0000366 # Exclude these modules.
367 excludeModules = []
Just van Rossumcef32882002-11-26 00:34:52 +0000368
Jack Jansen0ae32202003-04-09 13:25:43 +0000369 # Include these modules.
370 includeModules = []
Just van Rossumcef32882002-11-26 00:34:52 +0000371
Jack Jansen0ae32202003-04-09 13:25:43 +0000372 # Include these packages.
373 includePackages = []
Just van Rossumcef32882002-11-26 00:34:52 +0000374
Just van Rossum00a0b972003-06-20 21:18:22 +0000375 # Strip binaries from debug info.
Jack Jansen0ae32202003-04-09 13:25:43 +0000376 strip = 0
Just van Rossumcef32882002-11-26 00:34:52 +0000377
Jack Jansen0ae32202003-04-09 13:25:43 +0000378 # Found Python modules: [(name, codeobject, ispkg), ...]
379 pymodules = []
Just van Rossumcef32882002-11-26 00:34:52 +0000380
Jack Jansen0ae32202003-04-09 13:25:43 +0000381 # Modules that modulefinder couldn't find:
382 missingModules = []
383 maybeMissingModules = []
Just van Rossumcef32882002-11-26 00:34:52 +0000384
Jack Jansen0ae32202003-04-09 13:25:43 +0000385 def setup(self):
Just van Rossum762d2cc2003-06-29 21:54:12 +0000386 if ((self.standalone or self.semi_standalone)
387 and self.mainprogram is None):
Jack Jansen0ae32202003-04-09 13:25:43 +0000388 raise BundleBuilderError, ("must specify 'mainprogram' when "
389 "building a standalone application.")
390 if self.mainprogram is None and self.executable is None:
391 raise BundleBuilderError, ("must specify either or both of "
392 "'executable' and 'mainprogram'")
Just van Rossumceeb9622002-11-21 23:19:37 +0000393
Jack Jansen0ae32202003-04-09 13:25:43 +0000394 self.execdir = pathjoin("Contents", self.platform)
Jack Jansencc81b802003-03-05 14:42:18 +0000395
Jack Jansen0ae32202003-04-09 13:25:43 +0000396 if self.name is not None:
397 pass
398 elif self.mainprogram is not None:
399 self.name = os.path.splitext(os.path.basename(self.mainprogram))[0]
400 elif executable is not None:
401 self.name = os.path.splitext(os.path.basename(self.executable))[0]
402 if self.name[-4:] != ".app":
403 self.name += ".app"
Just van Rossumceeb9622002-11-21 23:19:37 +0000404
Jack Jansen0ae32202003-04-09 13:25:43 +0000405 if self.executable is None:
Just van Rossum79b0ae12003-06-29 22:20:26 +0000406 if not self.standalone and not isFramework():
Jack Jansen0ae32202003-04-09 13:25:43 +0000407 self.symlink_exec = 1
Jack Jansenbbaa0832003-07-04 11:05:35 +0000408 if self.python:
409 self.executable = self.python
410 else:
411 self.executable = sys.executable
Just van Rossum74bdca82002-11-28 11:30:56 +0000412
Jack Jansen0ae32202003-04-09 13:25:43 +0000413 if self.nibname:
414 self.plist.NSMainNibFile = self.nibname
415 if not hasattr(self.plist, "NSPrincipalClass"):
416 self.plist.NSPrincipalClass = "NSApplication"
Just van Rossumceeb9622002-11-21 23:19:37 +0000417
Just van Rossum79b0ae12003-06-29 22:20:26 +0000418 if self.standalone and isFramework():
Just van Rossum3166f592003-06-20 18:56:10 +0000419 self.addPythonFramework()
420
Jack Jansen0ae32202003-04-09 13:25:43 +0000421 BundleBuilder.setup(self)
Just van Rossumceeb9622002-11-21 23:19:37 +0000422
Jack Jansen0ae32202003-04-09 13:25:43 +0000423 self.plist.CFBundleExecutable = self.name
Just van Rossumf7aba232002-11-22 00:31:50 +0000424
Just van Rossum762d2cc2003-06-29 21:54:12 +0000425 if self.standalone or self.semi_standalone:
Jack Jansen0ae32202003-04-09 13:25:43 +0000426 self.findDependencies()
Just van Rossumcef32882002-11-26 00:34:52 +0000427
Jack Jansen0ae32202003-04-09 13:25:43 +0000428 def preProcess(self):
429 resdir = "Contents/Resources"
430 if self.executable is not None:
431 if self.mainprogram is None:
432 execname = self.name
433 else:
434 execname = os.path.basename(self.executable)
435 execpath = pathjoin(self.execdir, execname)
436 if not self.symlink_exec:
437 self.files.append((self.executable, execpath))
Jack Jansen0ae32202003-04-09 13:25:43 +0000438 self.execpath = execpath
Just van Rossumad33d722002-11-21 10:23:04 +0000439
Jack Jansen0ae32202003-04-09 13:25:43 +0000440 if self.mainprogram is not None:
441 mainprogram = os.path.basename(self.mainprogram)
442 self.files.append((self.mainprogram, pathjoin(resdir, mainprogram)))
443 if self.argv_emulation:
444 # Change the main program, and create the helper main program (which
445 # does argv collection and then calls the real main).
446 # Also update the included modules (if we're creating a standalone
447 # program) and the plist
448 realmainprogram = mainprogram
449 mainprogram = '__argvemulator_' + mainprogram
450 resdirpath = pathjoin(self.bundlepath, resdir)
451 mainprogrampath = pathjoin(resdirpath, mainprogram)
452 makedirs(resdirpath)
453 open(mainprogrampath, "w").write(ARGV_EMULATOR % locals())
Just van Rossum762d2cc2003-06-29 21:54:12 +0000454 if self.standalone or self.semi_standalone:
Jack Jansen0ae32202003-04-09 13:25:43 +0000455 self.includeModules.append("argvemulator")
456 self.includeModules.append("os")
457 if not self.plist.has_key("CFBundleDocumentTypes"):
458 self.plist["CFBundleDocumentTypes"] = [
459 { "CFBundleTypeOSTypes" : [
460 "****",
461 "fold",
462 "disk"],
463 "CFBundleTypeRole": "Viewer"}]
464 # Write bootstrap script
465 executable = os.path.basename(self.executable)
466 execdir = pathjoin(self.bundlepath, self.execdir)
467 bootstrappath = pathjoin(execdir, self.name)
468 makedirs(execdir)
Just van Rossum762d2cc2003-06-29 21:54:12 +0000469 if self.standalone or self.semi_standalone:
Jack Jansen0ae32202003-04-09 13:25:43 +0000470 # XXX we're screwed when the end user has deleted
471 # /usr/bin/python
472 hashbang = "/usr/bin/python"
Jack Jansen8ba0e802003-05-25 22:00:17 +0000473 elif self.python:
474 hashbang = self.python
Jack Jansen0ae32202003-04-09 13:25:43 +0000475 else:
476 hashbang = os.path.realpath(sys.executable)
477 standalone = self.standalone
478 open(bootstrappath, "w").write(BOOTSTRAP_SCRIPT % locals())
479 os.chmod(bootstrappath, 0775)
Just van Rossumad33d722002-11-21 10:23:04 +0000480
Jack Jansen0ae32202003-04-09 13:25:43 +0000481 if self.iconfile is not None:
482 iconbase = os.path.basename(self.iconfile)
483 self.plist.CFBundleIconFile = iconbase
484 self.files.append((self.iconfile, pathjoin(resdir, iconbase)))
Just van Rossum2aa09562003-02-01 08:34:46 +0000485
Jack Jansen0ae32202003-04-09 13:25:43 +0000486 def postProcess(self):
Just van Rossum762d2cc2003-06-29 21:54:12 +0000487 if self.standalone or self.semi_standalone:
Jack Jansen0ae32202003-04-09 13:25:43 +0000488 self.addPythonModules()
489 if self.strip and not self.symlink:
490 self.stripBinaries()
Just van Rossumcef32882002-11-26 00:34:52 +0000491
Jack Jansen0ae32202003-04-09 13:25:43 +0000492 if self.symlink_exec and self.executable:
493 self.message("Symlinking executable %s to %s" % (self.executable,
494 self.execpath), 2)
495 dst = pathjoin(self.bundlepath, self.execpath)
496 makedirs(os.path.dirname(dst))
497 os.symlink(os.path.abspath(self.executable), dst)
Just van Rossum16aebf72002-11-22 11:43:10 +0000498
Jack Jansen0ae32202003-04-09 13:25:43 +0000499 if self.missingModules or self.maybeMissingModules:
500 self.reportMissing()
Just van Rossumcef32882002-11-26 00:34:52 +0000501
Just van Rossum3166f592003-06-20 18:56:10 +0000502 def addPythonFramework(self):
503 # If we're building a standalone app with Python.framework,
Just van Rossumdc31dc02003-06-20 21:43:36 +0000504 # include a minimal subset of Python.framework, *unless*
505 # Python.framework was specified manually in self.libs.
506 for lib in self.libs:
507 if os.path.basename(lib) == "Python.framework":
508 # a Python.framework was specified as a library
509 return
510
Just van Rossum3166f592003-06-20 18:56:10 +0000511 frameworkpath = sys.exec_prefix[:sys.exec_prefix.find(
512 "Python.framework") + len("Python.framework")]
Just van Rossumdc31dc02003-06-20 21:43:36 +0000513
Just van Rossum3166f592003-06-20 18:56:10 +0000514 version = sys.version[:3]
515 frameworkpath = pathjoin(frameworkpath, "Versions", version)
516 destbase = pathjoin("Contents", "Frameworks", "Python.framework",
517 "Versions", version)
518 for item in PYTHONFRAMEWORKGOODIES:
519 src = pathjoin(frameworkpath, item)
520 dst = pathjoin(destbase, item)
521 self.files.append((src, dst))
522
Just van Rossum762d2cc2003-06-29 21:54:12 +0000523 def _getSiteCode(self):
524 return compile(SITE_PY % {"semi_standalone": self.semi_standalone},
525 "<-bundlebuilder.py->", "exec")
526
Jack Jansen0ae32202003-04-09 13:25:43 +0000527 def addPythonModules(self):
528 self.message("Adding Python modules", 1)
Just van Rossumcef32882002-11-26 00:34:52 +0000529
Jack Jansen0ae32202003-04-09 13:25:43 +0000530 if USE_ZIPIMPORT:
531 # Create a zip file containing all modules as pyc.
532 import zipfile
533 relpath = pathjoin("Contents", "Resources", ZIP_ARCHIVE)
534 abspath = pathjoin(self.bundlepath, relpath)
535 zf = zipfile.ZipFile(abspath, "w", zipfile.ZIP_DEFLATED)
536 for name, code, ispkg in self.pymodules:
537 self.message("Adding Python module %s" % name, 2)
538 path, pyc = getPycData(name, code, ispkg)
539 zf.writestr(path, pyc)
540 zf.close()
541 # add site.pyc
542 sitepath = pathjoin(self.bundlepath, "Contents", "Resources",
543 "site" + PYC_EXT)
Just van Rossum762d2cc2003-06-29 21:54:12 +0000544 writePyc(self._getSiteCode(), sitepath)
Jack Jansen0ae32202003-04-09 13:25:43 +0000545 else:
546 # Create individual .pyc files.
547 for name, code, ispkg in self.pymodules:
548 if ispkg:
549 name += ".__init__"
550 path = name.split(".")
551 path = pathjoin("Contents", "Resources", *path) + PYC_EXT
Just van Rossumcef32882002-11-26 00:34:52 +0000552
Jack Jansen0ae32202003-04-09 13:25:43 +0000553 if ispkg:
554 self.message("Adding Python package %s" % path, 2)
555 else:
556 self.message("Adding Python module %s" % path, 2)
Just van Rossumcef32882002-11-26 00:34:52 +0000557
Jack Jansen0ae32202003-04-09 13:25:43 +0000558 abspath = pathjoin(self.bundlepath, path)
559 makedirs(os.path.dirname(abspath))
560 writePyc(code, abspath)
Just van Rossumcef32882002-11-26 00:34:52 +0000561
Jack Jansen0ae32202003-04-09 13:25:43 +0000562 def stripBinaries(self):
563 if not os.path.exists(STRIP_EXEC):
564 self.message("Error: can't strip binaries: no strip program at "
565 "%s" % STRIP_EXEC, 0)
566 else:
Just van Rossum00a0b972003-06-20 21:18:22 +0000567 import stat
Jack Jansen0ae32202003-04-09 13:25:43 +0000568 self.message("Stripping binaries", 1)
Just van Rossum00a0b972003-06-20 21:18:22 +0000569 def walk(top):
570 for name in os.listdir(top):
571 path = pathjoin(top, name)
572 if os.path.islink(path):
573 continue
574 if os.path.isdir(path):
575 walk(path)
576 else:
577 mod = os.stat(path)[stat.ST_MODE]
578 if not (mod & 0100):
579 continue
580 relpath = path[len(self.bundlepath):]
581 self.message("Stripping %s" % relpath, 2)
582 inf, outf = os.popen4("%s -S \"%s\"" %
583 (STRIP_EXEC, path))
584 output = outf.read().strip()
585 if output:
586 # usually not a real problem, like when we're
587 # trying to strip a script
588 self.message("Problem stripping %s:" % relpath, 3)
589 self.message(output, 3)
590 walk(self.bundlepath)
Just van Rossumcef32882002-11-26 00:34:52 +0000591
Jack Jansen0ae32202003-04-09 13:25:43 +0000592 def findDependencies(self):
593 self.message("Finding module dependencies", 1)
594 import modulefinder
595 mf = modulefinder.ModuleFinder(excludes=self.excludeModules)
596 if USE_ZIPIMPORT:
597 # zipimport imports zlib, must add it manually
598 mf.import_hook("zlib")
599 # manually add our own site.py
600 site = mf.add_module("site")
Just van Rossum762d2cc2003-06-29 21:54:12 +0000601 site.__code__ = self._getSiteCode()
602 mf.scan_code(site.__code__, site)
Just van Rossumcef32882002-11-26 00:34:52 +0000603
Jack Jansen0ae32202003-04-09 13:25:43 +0000604 # warnings.py gets imported implicitly from C
605 mf.import_hook("warnings")
Just van Rossum7322b1a2003-02-25 20:15:40 +0000606
Jack Jansen0ae32202003-04-09 13:25:43 +0000607 includeModules = self.includeModules[:]
608 for name in self.includePackages:
609 includeModules.extend(findPackageContents(name).keys())
610 for name in includeModules:
611 try:
612 mf.import_hook(name)
613 except ImportError:
614 self.missingModules.append(name)
Just van Rossumcef32882002-11-26 00:34:52 +0000615
Jack Jansen0ae32202003-04-09 13:25:43 +0000616 mf.run_script(self.mainprogram)
617 modules = mf.modules.items()
618 modules.sort()
619 for name, mod in modules:
Just van Rossum762d2cc2003-06-29 21:54:12 +0000620 path = mod.__file__
621 if path and self.semi_standalone:
622 # skip the standard library
623 if path.startswith(LIB) and not path.startswith(SITE_PACKAGES):
624 continue
625 if path and mod.__code__ is None:
Jack Jansen0ae32202003-04-09 13:25:43 +0000626 # C extension
Jack Jansen0ae32202003-04-09 13:25:43 +0000627 filename = os.path.basename(path)
Just van Rossum79b0ae12003-06-29 22:20:26 +0000628 pathitems = name.split(".")[:-1] + [filename]
629 dstpath = pathjoin(*pathitems)
Jack Jansen0ae32202003-04-09 13:25:43 +0000630 if USE_ZIPIMPORT:
Just van Rossum79b0ae12003-06-29 22:20:26 +0000631 if name != "zlib":
632 # neatly pack all extension modules in a subdirectory,
633 # except zlib, since it's neccesary for bootstrapping.
634 dstpath = pathjoin("ExtensionModules", dstpath)
Jack Jansen0ae32202003-04-09 13:25:43 +0000635 # Python modules are stored in a Zip archive, but put
Just van Rossum762d2cc2003-06-29 21:54:12 +0000636 # extensions in Contents/Resources/. Add a tiny "loader"
Jack Jansen0ae32202003-04-09 13:25:43 +0000637 # program in the Zip archive. Due to Thomas Heller.
Just van Rossum762d2cc2003-06-29 21:54:12 +0000638 source = EXT_LOADER % {"name": name, "filename": dstpath}
Jack Jansen0ae32202003-04-09 13:25:43 +0000639 code = compile(source, "<dynloader for %s>" % name, "exec")
640 mod.__code__ = code
Just van Rossum762d2cc2003-06-29 21:54:12 +0000641 self.files.append((path, pathjoin("Contents", "Resources", dstpath)))
Jack Jansen0ae32202003-04-09 13:25:43 +0000642 if mod.__code__ is not None:
643 ispkg = mod.__path__ is not None
644 if not USE_ZIPIMPORT or name != "site":
645 # Our site.py is doing the bootstrapping, so we must
646 # include a real .pyc file if USE_ZIPIMPORT is True.
647 self.pymodules.append((name, mod.__code__, ispkg))
Just van Rossumcef32882002-11-26 00:34:52 +0000648
Jack Jansen0ae32202003-04-09 13:25:43 +0000649 if hasattr(mf, "any_missing_maybe"):
650 missing, maybe = mf.any_missing_maybe()
651 else:
652 missing = mf.any_missing()
653 maybe = []
654 self.missingModules.extend(missing)
655 self.maybeMissingModules.extend(maybe)
Just van Rossumcef32882002-11-26 00:34:52 +0000656
Jack Jansen0ae32202003-04-09 13:25:43 +0000657 def reportMissing(self):
658 missing = [name for name in self.missingModules
659 if name not in MAYMISS_MODULES]
660 if self.maybeMissingModules:
661 maybe = self.maybeMissingModules
662 else:
663 maybe = [name for name in missing if "." in name]
664 missing = [name for name in missing if "." not in name]
665 missing.sort()
666 maybe.sort()
667 if maybe:
668 self.message("Warning: couldn't find the following submodules:", 1)
669 self.message(" (Note that these could be false alarms -- "
670 "it's not always", 1)
671 self.message(" possible to distinguish between \"from package "
672 "import submodule\" ", 1)
673 self.message(" and \"from package import name\")", 1)
674 for name in maybe:
675 self.message(" ? " + name, 1)
676 if missing:
677 self.message("Warning: couldn't find the following modules:", 1)
678 for name in missing:
679 self.message(" ? " + name, 1)
Just van Rossum74bdca82002-11-28 11:30:56 +0000680
Jack Jansen0ae32202003-04-09 13:25:43 +0000681 def report(self):
682 # XXX something decent
683 import pprint
684 pprint.pprint(self.__dict__)
Just van Rossum762d2cc2003-06-29 21:54:12 +0000685 if self.standalone or self.semi_standalone:
Jack Jansen0ae32202003-04-09 13:25:43 +0000686 self.reportMissing()
Just van Rossumcef32882002-11-26 00:34:52 +0000687
688#
689# Utilities.
690#
691
692SUFFIXES = [_suf for _suf, _mode, _tp in imp.get_suffixes()]
693identifierRE = re.compile(r"[_a-zA-z][_a-zA-Z0-9]*$")
694
695def findPackageContents(name, searchpath=None):
Jack Jansen0ae32202003-04-09 13:25:43 +0000696 head = name.split(".")[-1]
697 if identifierRE.match(head) is None:
698 return {}
699 try:
700 fp, path, (ext, mode, tp) = imp.find_module(head, searchpath)
701 except ImportError:
702 return {}
703 modules = {name: None}
704 if tp == imp.PKG_DIRECTORY and path:
705 files = os.listdir(path)
706 for sub in files:
707 sub, ext = os.path.splitext(sub)
708 fullname = name + "." + sub
709 if sub != "__init__" and fullname not in modules:
710 modules.update(findPackageContents(fullname, [path]))
711 return modules
Just van Rossumcef32882002-11-26 00:34:52 +0000712
713def writePyc(code, path):
Jack Jansen0ae32202003-04-09 13:25:43 +0000714 f = open(path, "wb")
715 f.write(MAGIC)
716 f.write("\0" * 4) # don't bother about a time stamp
717 marshal.dump(code, f)
718 f.close()
Just van Rossumad33d722002-11-21 10:23:04 +0000719
Just van Rossumad33d722002-11-21 10:23:04 +0000720def copy(src, dst, mkdirs=0):
Jack Jansen0ae32202003-04-09 13:25:43 +0000721 """Copy a file or a directory."""
722 if mkdirs:
723 makedirs(os.path.dirname(dst))
724 if os.path.isdir(src):
Just van Rossumdc31dc02003-06-20 21:43:36 +0000725 shutil.copytree(src, dst, symlinks=1)
Jack Jansen0ae32202003-04-09 13:25:43 +0000726 else:
727 shutil.copy2(src, dst)
Just van Rossumad33d722002-11-21 10:23:04 +0000728
729def copytodir(src, dstdir):
Jack Jansen0ae32202003-04-09 13:25:43 +0000730 """Copy a file or a directory to an existing directory."""
731 dst = pathjoin(dstdir, os.path.basename(src))
732 copy(src, dst)
Just van Rossumad33d722002-11-21 10:23:04 +0000733
734def makedirs(dir):
Jack Jansen0ae32202003-04-09 13:25:43 +0000735 """Make all directories leading up to 'dir' including the leaf
736 directory. Don't moan if any path element already exists."""
737 try:
738 os.makedirs(dir)
739 except OSError, why:
740 if why.errno != errno.EEXIST:
741 raise
Just van Rossumad33d722002-11-21 10:23:04 +0000742
743def symlink(src, dst, mkdirs=0):
Jack Jansen0ae32202003-04-09 13:25:43 +0000744 """Copy a file or a directory."""
745 if not os.path.exists(src):
746 raise IOError, "No such file or directory: '%s'" % src
747 if mkdirs:
748 makedirs(os.path.dirname(dst))
749 os.symlink(os.path.abspath(src), dst)
Just van Rossumad33d722002-11-21 10:23:04 +0000750
751def pathjoin(*args):
Jack Jansen0ae32202003-04-09 13:25:43 +0000752 """Safe wrapper for os.path.join: asserts that all but the first
753 argument are relative paths."""
754 for seg in args[1:]:
755 assert seg[0] != "/"
756 return os.path.join(*args)
Just van Rossumad33d722002-11-21 10:23:04 +0000757
758
Just van Rossumceeb9622002-11-21 23:19:37 +0000759cmdline_doc = """\
760Usage:
Just van Rossumf7aba232002-11-22 00:31:50 +0000761 python bundlebuilder.py [options] command
Just van Rossumceeb9622002-11-21 23:19:37 +0000762 python mybuildscript.py [options] command
763
764Commands:
765 build build the application
766 report print a report
767
768Options:
769 -b, --builddir=DIR the build directory; defaults to "build"
770 -n, --name=NAME application name
771 -r, --resource=FILE extra file or folder to be copied to Resources
Just van Rossum7215e082003-02-25 21:00:55 +0000772 -f, --file=SRC:DST extra file or folder to be copied into the bundle;
773 DST must be a path relative to the bundle root
Just van Rossumceeb9622002-11-21 23:19:37 +0000774 -e, --executable=FILE the executable to be used
775 -m, --mainprogram=FILE the Python main program
Jack Jansena03adde2003-02-18 23:29:46 +0000776 -a, --argv add a wrapper main program to create sys.argv
Just van Rossumceeb9622002-11-21 23:19:37 +0000777 -p, --plist=FILE .plist file (default: generate one)
778 --nib=NAME main nib name
779 -c, --creator=CCCC 4-char creator code (default: '????')
Just van Rossum9af69682003-02-02 18:56:37 +0000780 --iconfile=FILE filename of the icon (an .icns file) to be used
Just van Rossum2aa09562003-02-01 08:34:46 +0000781 as the Finder icon
Just van Rossumceeb9622002-11-21 23:19:37 +0000782 -l, --link symlink files/folder instead of copying them
Just van Rossum16aebf72002-11-22 11:43:10 +0000783 --link-exec symlink the executable instead of copying it
Just van Rossumcef32882002-11-26 00:34:52 +0000784 --standalone build a standalone application, which is fully
785 independent of a Python installation
Just van Rossum762d2cc2003-06-29 21:54:12 +0000786 --semi-standalone build a standalone application, which depends on
787 an installed Python, yet includes all third-party
788 modules.
Jack Jansen8ba0e802003-05-25 22:00:17 +0000789 --python=FILE Python to use in #! line in stead of current Python
Just van Rossum15624d82003-03-21 09:26:59 +0000790 --lib=FILE shared library or framework to be copied into
791 the bundle
Just van Rossum762d2cc2003-06-29 21:54:12 +0000792 -x, --exclude=MODULE exclude module (with --(semi-)standalone)
793 -i, --include=MODULE include module (with --(semi-)standalone)
794 --package=PACKAGE include a whole package (with --(semi-)standalone)
Just van Rossumcef32882002-11-26 00:34:52 +0000795 --strip strip binaries (remove debug info)
Just van Rossumceeb9622002-11-21 23:19:37 +0000796 -v, --verbose increase verbosity level
797 -q, --quiet decrease verbosity level
798 -h, --help print this message
799"""
800
801def usage(msg=None):
Jack Jansen0ae32202003-04-09 13:25:43 +0000802 if msg:
803 print msg
804 print cmdline_doc
805 sys.exit(1)
Just van Rossumceeb9622002-11-21 23:19:37 +0000806
807def main(builder=None):
Jack Jansen0ae32202003-04-09 13:25:43 +0000808 if builder is None:
809 builder = AppBuilder(verbosity=1)
Just van Rossumceeb9622002-11-21 23:19:37 +0000810
Jack Jansen0ae32202003-04-09 13:25:43 +0000811 shortopts = "b:n:r:f:e:m:c:p:lx:i:hvqa"
812 longopts = ("builddir=", "name=", "resource=", "file=", "executable=",
813 "mainprogram=", "creator=", "nib=", "plist=", "link",
814 "link-exec", "help", "verbose", "quiet", "argv", "standalone",
815 "exclude=", "include=", "package=", "strip", "iconfile=",
Just van Rossum762d2cc2003-06-29 21:54:12 +0000816 "lib=", "python=", "semi-standalone")
Just van Rossumceeb9622002-11-21 23:19:37 +0000817
Jack Jansen0ae32202003-04-09 13:25:43 +0000818 try:
819 options, args = getopt.getopt(sys.argv[1:], shortopts, longopts)
820 except getopt.error:
821 usage()
Just van Rossumceeb9622002-11-21 23:19:37 +0000822
Jack Jansen0ae32202003-04-09 13:25:43 +0000823 for opt, arg in options:
824 if opt in ('-b', '--builddir'):
825 builder.builddir = arg
826 elif opt in ('-n', '--name'):
827 builder.name = arg
828 elif opt in ('-r', '--resource'):
Just van Rossumdc31dc02003-06-20 21:43:36 +0000829 builder.resources.append(os.path.normpath(arg))
Jack Jansen0ae32202003-04-09 13:25:43 +0000830 elif opt in ('-f', '--file'):
831 srcdst = arg.split(':')
832 if len(srcdst) != 2:
833 usage("-f or --file argument must be two paths, "
834 "separated by a colon")
835 builder.files.append(srcdst)
836 elif opt in ('-e', '--executable'):
837 builder.executable = arg
838 elif opt in ('-m', '--mainprogram'):
839 builder.mainprogram = arg
840 elif opt in ('-a', '--argv'):
841 builder.argv_emulation = 1
842 elif opt in ('-c', '--creator'):
843 builder.creator = arg
844 elif opt == '--iconfile':
845 builder.iconfile = arg
846 elif opt == "--lib":
Just van Rossumdc31dc02003-06-20 21:43:36 +0000847 builder.libs.append(os.path.normpath(arg))
Jack Jansen0ae32202003-04-09 13:25:43 +0000848 elif opt == "--nib":
849 builder.nibname = arg
850 elif opt in ('-p', '--plist'):
851 builder.plist = Plist.fromFile(arg)
852 elif opt in ('-l', '--link'):
853 builder.symlink = 1
854 elif opt == '--link-exec':
855 builder.symlink_exec = 1
856 elif opt in ('-h', '--help'):
857 usage()
858 elif opt in ('-v', '--verbose'):
859 builder.verbosity += 1
860 elif opt in ('-q', '--quiet'):
861 builder.verbosity -= 1
862 elif opt == '--standalone':
863 builder.standalone = 1
Just van Rossum762d2cc2003-06-29 21:54:12 +0000864 elif opt == '--semi-standalone':
865 builder.semi_standalone = 1
Jack Jansen8ba0e802003-05-25 22:00:17 +0000866 elif opt == '--python':
867 builder.python = arg
Jack Jansen0ae32202003-04-09 13:25:43 +0000868 elif opt in ('-x', '--exclude'):
869 builder.excludeModules.append(arg)
870 elif opt in ('-i', '--include'):
871 builder.includeModules.append(arg)
872 elif opt == '--package':
873 builder.includePackages.append(arg)
874 elif opt == '--strip':
875 builder.strip = 1
Just van Rossumceeb9622002-11-21 23:19:37 +0000876
Jack Jansen0ae32202003-04-09 13:25:43 +0000877 if len(args) != 1:
878 usage("Must specify one command ('build', 'report' or 'help')")
879 command = args[0]
Just van Rossumceeb9622002-11-21 23:19:37 +0000880
Jack Jansen0ae32202003-04-09 13:25:43 +0000881 if command == "build":
882 builder.setup()
883 builder.build()
884 elif command == "report":
885 builder.setup()
886 builder.report()
887 elif command == "help":
888 usage()
889 else:
890 usage("Unknown command '%s'" % command)
Just van Rossumceeb9622002-11-21 23:19:37 +0000891
892
Just van Rossumad33d722002-11-21 10:23:04 +0000893def buildapp(**kwargs):
Jack Jansen0ae32202003-04-09 13:25:43 +0000894 builder = AppBuilder(**kwargs)
895 main(builder)
Just van Rossumad33d722002-11-21 10:23:04 +0000896
897
898if __name__ == "__main__":
Jack Jansen0ae32202003-04-09 13:25:43 +0000899 main()