summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>2002-08-02 14:11:24 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>2002-08-02 14:11:24 (GMT)
commit21ed16acbe0a8870f6833b7976f8b7e79452d21c (patch)
tree3c2459f9d7dcbd73d633cbac0af301099da288d4 /Python
parent94416e55d35e121a908fec30115a091f707c99e9 (diff)
downloadcpython-21ed16acbe0a8870f6833b7976f8b7e79452d21c.zip
cpython-21ed16acbe0a8870f6833b7976f8b7e79452d21c.tar.gz
cpython-21ed16acbe0a8870f6833b7976f8b7e79452d21c.tar.bz2
Added one call to Py_Main(), for OSX framework builds only, that will get the
actual script to run in case we are running from an applet. If we are indeed running an applet we skip the normal option processing leaving it all to the applet code. This allows us to get use the normal python binary in the Python.app bundle, giving us all the normal command line options through PythonLauncher while still allowing Python.app to be used as the template for building applets. Consequently, pythonforbundle is gone, and Mac/Python/macmain.c isn't used on OSX anymore.
Diffstat (limited to 'Python')
-rw-r--r--Python/mactoolboxglue.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/Python/mactoolboxglue.c b/Python/mactoolboxglue.c
index 2852fde..68876eb 100644
--- a/Python/mactoolboxglue.c
+++ b/Python/mactoolboxglue.c
@@ -175,6 +175,94 @@ PyMac_GetFullPathname(FSSpec *fss, char *path, int len)
}
#endif /* TARGET_API_MAC_OSX */
+
+#ifdef WITH_NEXT_FRAMEWORK
+/*
+** In a bundle, find a file "resourceName" of type "resourceType". Return the
+** full pathname in "resourceURLCstr".
+*/
+static int
+locateResourcePy(CFStringRef resourceType, CFStringRef resourceName, char *resourceURLCStr, int length)
+{
+ CFBundleRef mainBundle = NULL;
+ CFURLRef URL, absoluteURL;
+ CFStringRef filenameString, filepathString;
+ CFIndex size, i;
+ CFArrayRef arrayRef = NULL;
+ int success = 0;
+
+#if TARGET_API_MAC_OSX
+ CFURLPathStyle thePathStyle = kCFURLPOSIXPathStyle;
+#else
+ CFURLPathStyle thePathStyle = kCFURLHFSPathStyle;
+#endif
+
+ /* Get a reference to our main bundle */
+ mainBundle = CFBundleGetMainBundle();
+
+ /* If we are running inside a bundle, look through it. Otherwise, do nothing. */
+ if (mainBundle) {
+
+ /* Look for py files in the main bundle by type */
+ arrayRef = CFBundleCopyResourceURLsOfType( mainBundle,
+ resourceType,
+ NULL );
+
+ /* See if there are any filename matches */
+ size = CFArrayGetCount(arrayRef);
+ for (i = 0; i < size; i++) {
+ URL = CFArrayGetValueAtIndex(arrayRef, i);
+ filenameString = CFURLCopyLastPathComponent(URL);
+ if (CFStringCompare(filenameString, resourceName, 0) == kCFCompareEqualTo) {
+ /* We found a match, get the file's full path */
+ absoluteURL = CFURLCopyAbsoluteURL(URL);
+ filepathString = CFURLCopyFileSystemPath(absoluteURL, thePathStyle);
+ CFRelease(absoluteURL);
+
+ /* Copy the full path into the caller's character buffer */
+ success = CFStringGetCString(filepathString, resourceURLCStr, length,
+ kCFStringEncodingMacRoman);
+
+ CFRelease(filepathString);
+ }
+ CFRelease(filenameString);
+ }
+ CFRelease(arrayRef);
+ }
+ return success;
+}
+
+/*
+** iff we are running in a .app framework then we could be
+** the main program for an applet. In that case, return the
+** script filename for the applet.
+** Otherwise return NULL.
+*/
+char *
+PyMac_GetAppletScriptFile(void)
+{
+ static char scriptpath[1024];
+
+ /* First we see whether we have __rawmain__.py and run that if it
+ ** is there. This is used for applets that want sys.argv to be
+ ** unix-like: __rawmain__ will construct it (from the initial appleevent)
+ ** and then call __main__.py.
+ */
+ if (locateResourcePy(CFSTR("py"), CFSTR("__rawmain__.py"), scriptpath, 1024)) {
+ return scriptpath;
+ } else if (locateResourcePy(CFSTR("pyc"), CFSTR("__rawmain__.pyc"), scriptpath, 1024)) {
+ return scriptpath;
+ } else if (locateResourcePy(CFSTR("py"), CFSTR("__main__.py"), scriptpath, 1024)) {
+ return scriptpath;
+ } else if (locateResourcePy(CFSTR("pyc"), CFSTR("__main__.pyc"), scriptpath, 1024)) {
+ return scriptpath;
+ }
+ return NULL;
+}
+
+#endif
+
+
/* Convert a 4-char string object argument to an OSType value */
int
PyMac_GetOSType(PyObject *v, OSType *pr)