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.
This commit is contained in:
Jack Jansen 2002-08-02 14:11:24 +00:00
parent 94416e55d3
commit 21ed16acbe
5 changed files with 132 additions and 45 deletions

View file

@ -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)