[Python-checkins] python/dist/src/Python mactoolboxglue.c,1.9,1.10

jackjansen@users.sourceforge.net jackjansen@users.sourceforge.net
Fri, 02 Aug 2002 07:11:26 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv4439/Python

Modified Files:
	mactoolboxglue.c 
Log Message:
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.


Index: mactoolboxglue.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/mactoolboxglue.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** mactoolboxglue.c	4 Dec 2001 01:11:32 -0000	1.9
--- mactoolboxglue.c	2 Aug 2002 14:11:23 -0000	1.10
***************
*** 176,179 ****
--- 176,267 ----
  
  #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