]> granicus.if.org Git - python/commitdiff
Got rid of the python.rsrc resource file. The error message strings and
authorJack Jansen <jack.jansen@cwi.nl>
Thu, 7 Nov 2002 23:07:05 +0000 (23:07 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Thu, 7 Nov 2002 23:07:05 +0000 (23:07 +0000)
dialogs are now stored in Mac/Lib, and loaded on demand through macresource.
Not only does this simplify a MacPython based on Apple's Python, but
it also makes Mac error codes come out symbolically when running command
line python (if you have Mac/Lib in your path).

The resource files are copied from Mac/Resources. The old ones will disappear
after the OS9 build procedure has been adjusted.

Mac/Lib/EasyDialogs.py
Mac/Lib/buildtools.py
Mac/Lib/dialogs.rsrc [new file with mode: 0644]
Mac/Lib/errors.rsrc [new file with mode: 0644]
Mac/Lib/macresource.py
Mac/OSX/Makefile
Python/mactoolboxglue.c

index 52aad9791d9efdb1c85df5bd00bbe3e0dd78a284..8b810635ca0a090646e59f325d00aa2fa8182f6f 100644 (file)
@@ -27,6 +27,15 @@ import MacOS
 import string
 from Carbon.ControlAccessor import *   # Also import Controls constants
 import macfs
+import macresource
+
+_initialized = 0
+
+def _initialize():
+       global _initialized
+       if _initialized: return
+       macresource.need("DLOG", 260, "dialogs.rsrc", __name__)
+
 
 def cr2lf(text):
        if '\r' in text:
@@ -47,7 +56,7 @@ def Message(msg, id=260, ok=None):
        
        The MESSAGE string can be at most 255 characters long.
        """
-       
+       _initialize()
        d = GetNewDialog(id, -1)
        if not d:
                print "EasyDialogs: Can't get DLOG resource with id =", id, " (missing resource file?)"
@@ -79,6 +88,7 @@ def AskString(prompt, default = "", id=261, ok=None, cancel=None):
        can be at most 255 characters long.
        """
        
+       _initialize()
        d = GetNewDialog(id, -1)
        if not d:
                print "EasyDialogs: Can't get DLOG resource with id =", id, " (missing resource file?)"
@@ -119,6 +129,7 @@ def AskPassword(prompt,      default='', id=264, ok=None, cancel=None):
        The PROMPT and DEFAULT strings, as well as the return value,
        can be at most 255 characters long.
        """
+       _initialize()
        d = GetNewDialog(id, -1)
        if not d:
                print "EasyDialogs: Can't get DLOG resource with id =", id, " (missing resource file?)"
@@ -161,6 +172,7 @@ def AskYesNoCancel(question, default = 0, yes=None, no=None, cancel=None, id=262
        The QUESTION string can be at most 255 characters.
        """
        
+       _initialize()
        d = GetNewDialog(id, -1)
        if not d:
                print "EasyDialogs: Can't get DLOG resource with id =", id, " (missing resource file?)"
@@ -221,6 +233,7 @@ class ProgressBar:
        def __init__(self, title="Working...", maxval=0, label="", id=263):
                self.w = None
                self.d = None
+               _initialize()
                self.d = GetNewDialog(id, -1)
                self.w = self.d.GetDialogWindow()
                self.label(label)
@@ -391,6 +404,7 @@ def _selectoption(d, optionlist, idx):
 
 
 def GetArgv(optionlist=None, commandlist=None, addoldfile=1, addnewfile=1, addfolder=1, id=ARGV_ID):
+       _initialize()
        d = GetNewDialog(id, -1)
        if not d:
                print "EasyDialogs: Can't get DLOG resource with id =", id, " (missing resource file?)"
index a02c609901baea45d5e622e1f62cd5a5b08c2cdc..163f19a0cf0520795fdaff362c8b9e3fc18f716a 100644 (file)
@@ -353,58 +353,31 @@ def process_common_macho(template, progress, code, rsrcname, destname, is_update
        ofp.close()
                
        
-       if progress:
-               progress.label("Copy resources...")
-               progress.set(20)
-       resfilename = 'python.rsrc'  # XXXX later: '%s.rsrc' % shortname
-       try:
-               output = Res.FSOpenResourceFile(
-                               os.path.join(destname, 'Contents', 'Resources', resfilename), 
-                               u'', WRITE)
-       except MacOS.Error:
-               fsr, dummy = Res.FSCreateResourceFile(
-                               os.path.join(destname, 'Contents', 'Resources'), 
-                               unicode(resfilename), '')
-               output = Res.FSOpenResourceFile(fsr, u'', WRITE)
-       
        # Copy the resources from the target specific resource template, if any
        typesfound, ownertype = [], None
        try:
                input = macresource.open_pathname(rsrcname)
        except (MacOS.Error, ValueError):
-               pass
                if progress:
                        progress.inc(50)
        else:
+               if progress:
+                       progress.label("Copy resources...")
+                       progress.set(20)
+               resfilename = 'python.rsrc'  # XXXX later: '%s.rsrc' % shortname
+               try:
+                       output = Res.FSOpenResourceFile(
+                                       os.path.join(destname, 'Contents', 'Resources', resfilename), 
+                                       u'', WRITE)
+               except MacOS.Error:
+                       fsr, dummy = Res.FSCreateResourceFile(
+                                       os.path.join(destname, 'Contents', 'Resources'), 
+                                       unicode(resfilename), '')
+                       output = Res.FSOpenResourceFile(fsr, u'', WRITE)
+               
                typesfound, ownertype = copyres(input, output, [], 0, progress)
                Res.CloseResFile(input)
-       
-       # Check which resource-types we should not copy from the template
-       skiptypes = []
-##     if 'vers' in typesfound: skiptypes.append('vers')
-##     if 'SIZE' in typesfound: skiptypes.append('SIZE')
-##     if 'BNDL' in typesfound: skiptypes = skiptypes + ['BNDL', 'FREF', 'icl4', 
-##                     'icl8', 'ics4', 'ics8', 'ICN#', 'ics#']
-##     if not copy_codefragment:
-##             skiptypes.append('cfrg')
-##     skipowner = (ownertype <> None)
-       
-       # Copy the resources from the template
-       
-       input = Res.FSOpenResourceFile(
-                       os.path.join(template, 'Contents', 'Resources', 'python.rsrc'), u'', READ)
-       if progress:
-               progress.label("Copy standard resources...")
-               progress.inc(0)
-##     dummy, tmplowner = copyres(input, output, skiptypes, 1, progress)
-       dummy, tmplowner = copyres(input, output, skiptypes, 1, None)
-               
-       Res.CloseResFile(input)
-##     if ownertype == None:
-##             raise BuildError, "No owner resource found in either resource file or template"
-       # Make sure we're manipulating the output resource file now
-       
-       Res.CloseResFile(output)
+               Res.CloseResFile(output)
 
        if code:
                if raw:
diff --git a/Mac/Lib/dialogs.rsrc b/Mac/Lib/dialogs.rsrc
new file mode 100644 (file)
index 0000000..711bd5b
Binary files /dev/null and b/Mac/Lib/dialogs.rsrc differ
diff --git a/Mac/Lib/errors.rsrc b/Mac/Lib/errors.rsrc
new file mode 100644 (file)
index 0000000..61c487e
Binary files /dev/null and b/Mac/Lib/errors.rsrc differ
index 3a1161b8ecc6ab10c12640d6f3f3ebf10277d332..26f909409faa4c30d5a23dccdce908fbf550d541 100644 (file)
@@ -95,6 +95,11 @@ def open_pathname(pathname, verbose=0):
                        raise
        return refno
        
+def open_error_resource():
+       """Open the resource file containing the error code to error message
+       mapping."""
+       need('Estr', 1, filename="errors.rsrc", modname=__name__)
+       
 def _decode(pathname, verbose=0):
        # Decode an AppleSingle resource file, return the new pathname.
        newpathname = pathname + '.df.rsrc'
index b28d9f29388001ea9e6747a7c057f28eda94aac0..c8d584090e52faaa9cd83d5768156996cb97a28c 100644 (file)
@@ -37,16 +37,11 @@ LDFLAGS=-F$(builddir) -framework System -framework Python -framework Carbon \
        -framework Foundation
 CC=cc
 LD=cc
-REZ=/Developer/Tools/Rez
-DEREZ=/Developer/Tools/DeRez
 CPMAC=/Developer/Tools/CpMac
 
 PYTHON=$(builddir)/python.exe
 APPTEMPLATE=$(srcdir)/Mac/OSXResources/app
 APPSUBDIRS=MacOS Resources Resources/English.lproj
-RESOURCEDIR=$(srcdir)/Mac/Resources
-RESOURCEFILE=python.rsrc
-RFCONVERTER=$(srcdir)/Mac/Lib/applesingle.py
 CACHERSRC=$(srcdir)/Mac/scripts/cachersrc.py
 
 installapps: install_PythonLauncher install_Python install_BuildApplet install_IDE install_IDLE
@@ -94,29 +89,6 @@ install_Python: $(PYTHON)
                done; \
        done
        $(INSTALL_PROGRAM) $(STRIPFLAG) $(PYTHON) $(APPINSTALLDIR)/Contents/MacOS/python
-# Create a temporary version of the resources here
-# Note that the resource files can either be real 2-fork resource files
-# or AppleSingle encoded files.
-       @if test -s $(RESOURCEDIR)/dialogs.rsrc; then \
-               echo $(PYTHON) $(RFCONVERTER) -r $(RESOURCEDIR)/dialogs.rsrc dialogs.rsrc ;\
-               $(PYTHON) $(RFCONVERTER) -r $(RESOURCEDIR)/dialogs.rsrc dialogs.rsrc ; \
-               echo $(DEREZ) -useDF -skip ckid dialogs.rsrc > dialogs.r ; \
-               $(DEREZ) -useDF -skip ckid dialogs.rsrc > dialogs.r ; \
-       else \
-               echo $(DEREZ) -skip ckid $(RESOURCEDIR)/dialogs.rsrc > dialogs.r ; \
-               $(DEREZ) -skip ckid $(RESOURCEDIR)/dialogs.rsrc > dialogs.r ; \
-       fi
-       @if test -s $(RESOURCEDIR)/errors.rsrc; then \
-               echo $(PYTHON) $(RFCONVERTER) -r $(RESOURCEDIR)/errors.rsrc errors.rsrc ;\
-               $(PYTHON) $(RFCONVERTER) -r $(RESOURCEDIR)/errors.rsrc errors.rsrc ; \
-               echo $(DEREZ) -useDF -skip ckid errors.rsrc > errors.r ; \
-               $(DEREZ) -useDF -skip ckid errors.rsrc > errors.r ; \
-       else \
-               echo $(DEREZ) -skip ckid $(RESOURCEDIR)/errors.rsrc > errors.r ; \
-               $(DEREZ) -skip ckid $(RESOURCEDIR)/errors.rsrc > errors.r ; \
-       fi
-       $(REZ) -useDF -o $(RESOURCEFILE) dialogs.r errors.r 
-       $(INSTALL_DATA) $(RESOURCEFILE) $(APPINSTALLDIR)/Contents/Resources/$(RESOURCEFILE)
 # Finally create the documentation symlink
        $(LN) -fsn ../../../../English.lproj/Documentation $(APPINSTALLDIR)/Contents/Resources/English.lproj/Documentation
        
@@ -205,11 +177,11 @@ installmacsubtree:
                        echo $(INSTALL_DATA) $$i $(MACLIBDEST); \
                fi; \
        done
-##     @for i in $(MACLIBSRC)/*.rsrc; \
-##     do \
-##             echo $(CPMAC) $$i $$b ; \
-##             $(CPMAC) $$i $$b ; \
-##     done
+       @for i in $(MACLIBSRC)/*.rsrc; \
+       do \
+               echo $(CPMAC) $$i $(MACLIBDEST) ; \
+               $(CPMAC) $$i $(MACLIBDEST) ; \
+       done
        @for d in $(MACLIBSUBDIRS); \
        do \
                a=$(MACLIBSRC)/$$d; \
index 13e7afa6be5a747f91434f41503aacc46998d5d6..dd42f07d1e6e409858d7026d1c3e30c3ee5e2576 100644 (file)
@@ -81,8 +81,42 @@ char *PyMac_StrError(int err)
        static char buf[256];
        Handle h;
        char *str;
+       static int errors_loaded;
        
        h = GetResource('Estr', err);
+       if (!h && !errors_loaded) {
+               /*
+               ** Attempt to open the resource file containing the
+               ** Estr resources. We ignore all errors. We also try
+               ** this only once.
+               */
+               errors_loaded = 1;
+               PyObject *m, *rv;
+               
+               m = PyImport_ImportModule("macresource");
+               if (!m) {
+                       if (Py_VerboseFlag)
+                               PyErr_Print();
+                       PyErr_Clear();
+               } else {
+                       rv = PyObject_CallMethod(m, "open_error_resource", "");
+                       if (!rv) {
+                               if (Py_VerboseFlag)
+                                       PyErr_Print();
+                               PyErr_Clear();
+                       } else {
+                               Py_DECREF(rv);
+                               /* And try again... */
+                               h = GetResource('Estr', err);
+                       }
+               }
+       }
+       /*
+       ** Whether the code above succeeded or not, we won't try
+       ** again.
+       */
+       errors_loaded = 1;
+               
        if ( h ) {
                HLock(h);
                str = (char *)*h;