diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 2003-02-18 23:29:46 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 2003-02-18 23:29:46 (GMT) |
commit | a03adde31b148fee3f3c1a5b24e99d66e7ee750d (patch) | |
tree | 12f5d3035be2493649a81d8a1b30ecfa59dfef68 /Lib/plat-mac | |
parent | b135548d0d6fb390d2b1c64e9a0b3db6c2043346 (diff) | |
download | cpython-a03adde31b148fee3f3c1a5b24e99d66e7ee750d.zip cpython-a03adde31b148fee3f3c1a5b24e99d66e7ee750d.tar.gz cpython-a03adde31b148fee3f3c1a5b24e99d66e7ee750d.tar.bz2 |
Added an argv_emulation option (command line option: --argv or -a) which
creates the sys.argv emulation wrapper for droplets. Also updates
the plist, if needed, and the includedModules (but this last is untested).
Diffstat (limited to 'Lib/plat-mac')
-rwxr-xr-x | Lib/plat-mac/bundlebuilder.py | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/Lib/plat-mac/bundlebuilder.py b/Lib/plat-mac/bundlebuilder.py index 9959c95..50320f4 100755 --- a/Lib/plat-mac/bundlebuilder.py +++ b/Lib/plat-mac/bundlebuilder.py @@ -266,6 +266,12 @@ export PYTHONPATH exec "${executable}" "${main}" "$@" """ +ARGVEMULATOR="""\ +import argvemulator, os + +argvemulator.ArgvCollector().mainloop() +execfile(os.path.join(os.path.split(__file__)[0], "%(realmainprogram)s")) +""" class AppBuilder(BundleBuilder): @@ -293,6 +299,10 @@ class AppBuilder(BundleBuilder): # If True, build standalone app. standalone = 0 + + # If True, add a real main program that emulates sys.argv before calling + # mainprogram + argv_emulation = 0 # The following attributes are only used when building a standalone app. @@ -368,6 +378,27 @@ class AppBuilder(BundleBuilder): if self.mainprogram is not None: mainprogram = os.path.basename(self.mainprogram) self.files.append((self.mainprogram, pathjoin(resdir, mainprogram))) + if self.argv_emulation: + # Change the main program, and create the helper main program (which + # does argv collection and then calls the real main). + # Also update the included modules (if we're creating a standalone + # program) and the plist + realmainprogram = mainprogram + mainprogram = '__argvemulator_' + mainprogram + resdirpath = pathjoin(self.bundlepath, resdir) + mainprogrampath = pathjoin(resdirpath, mainprogram) + makedirs(resdirpath) + open(mainprogrampath, "w").write(ARGVEMULATOR % locals()) + if self.standalone: + self.includeModules.append("argvemulator") + self.includeModules.append("os") + if not self.plist.has_key("CFBundleDocumentTypes"): + self.plist["CFBundleDocumentTypes"] = [ + { "CFBundleTypeOSTypes" : [ + "****", + "fold", + "disk"], + "CFBundleTypeRole": "Viewer"}] # Write bootstrap script executable = os.path.basename(self.executable) execdir = pathjoin(self.bundlepath, self.execdir) @@ -619,6 +650,7 @@ Options: -r, --resource=FILE extra file or folder to be copied to Resources -e, --executable=FILE the executable to be used -m, --mainprogram=FILE the Python main program + -a, --argv add a wrapper main program to create sys.argv -p, --plist=FILE .plist file (default: generate one) --nib=NAME main nib name -c, --creator=CCCC 4-char creator code (default: '????') @@ -647,10 +679,10 @@ def main(builder=None): if builder is None: builder = AppBuilder(verbosity=1) - shortopts = "b:n:r:e:m:c:p:lx:i:hvq" + shortopts = "b:n:r:e:m:c:p:lx:i:hvqa" longopts = ("builddir=", "name=", "resource=", "executable=", "mainprogram=", "creator=", "nib=", "plist=", "link", - "link-exec", "help", "verbose", "quiet", "standalone", + "link-exec", "help", "verbose", "quiet", "argv", "standalone", "exclude=", "include=", "package=", "strip", "iconfile=") try: @@ -669,6 +701,8 @@ def main(builder=None): builder.executable = arg elif opt in ('-m', '--mainprogram'): builder.mainprogram = arg + elif opt in ('-a', '--argv'): + builder.argv_emulation = 1 elif opt in ('-c', '--creator'): builder.creator = arg elif opt == '--iconfile': |