Skip to content

Commit dde800e

Browse files
committed
Got rid of the python.rsrc resource file. The error message strings and
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.
1 parent 430b156 commit dde800e

7 files changed

Lines changed: 74 additions & 76 deletions

File tree

‎Mac/Lib/EasyDialogs.py‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@
2727
import string
2828
from Carbon.ControlAccessor import * # Also import Controls constants
2929
import macfs
30+
import macresource
31+
32+
_initialized = 0
33+
34+
def _initialize():
35+
global _initialized
36+
if _initialized: return
37+
macresource.need("DLOG", 260, "dialogs.rsrc", __name__)
38+
3039

3140
def cr2lf(text):
3241
if '\r' in text:
@@ -47,7 +56,7 @@ def Message(msg, id=260, ok=None):
4756
4857
The MESSAGE string can be at most 255 characters long.
4958
"""
50-
59+
_initialize()
5160
d = GetNewDialog(id, -1)
5261
if not d:
5362
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):
7988
can be at most 255 characters long.
8089
"""
8190

91+
_initialize()
8292
d = GetNewDialog(id, -1)
8393
if not d:
8494
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):
119129
The PROMPT and DEFAULT strings, as well as the return value,
120130
can be at most 255 characters long.
121131
"""
132+
_initialize()
122133
d = GetNewDialog(id, -1)
123134
if not d:
124135
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
161172
The QUESTION string can be at most 255 characters.
162173
"""
163174

175+
_initialize()
164176
d = GetNewDialog(id, -1)
165177
if not d:
166178
print "EasyDialogs: Can't get DLOG resource with id =", id, " (missing resource file?)"
@@ -221,6 +233,7 @@ class ProgressBar:
221233
def __init__(self, title="Working...", maxval=0, label="", id=263):
222234
self.w = None
223235
self.d = None
236+
_initialize()
224237
self.d = GetNewDialog(id, -1)
225238
self.w = self.d.GetDialogWindow()
226239
self.label(label)
@@ -391,6 +404,7 @@ def _selectoption(d, optionlist, idx):
391404

392405

393406
def GetArgv(optionlist=None, commandlist=None, addoldfile=1, addnewfile=1, addfolder=1, id=ARGV_ID):
407+
_initialize()
394408
d = GetNewDialog(id, -1)
395409
if not d:
396410
print "EasyDialogs: Can't get DLOG resource with id =", id, " (missing resource file?)"

‎Mac/Lib/buildtools.py‎

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -353,58 +353,31 @@ def process_common_macho(template, progress, code, rsrcname, destname, is_update
353353
ofp.close()
354354

355355

356-
if progress:
357-
progress.label("Copy resources...")
358-
progress.set(20)
359-
resfilename = 'python.rsrc' # XXXX later: '%s.rsrc' % shortname
360-
try:
361-
output = Res.FSOpenResourceFile(
362-
os.path.join(destname, 'Contents', 'Resources', resfilename),
363-
u'', WRITE)
364-
except MacOS.Error:
365-
fsr, dummy = Res.FSCreateResourceFile(
366-
os.path.join(destname, 'Contents', 'Resources'),
367-
unicode(resfilename), '')
368-
output = Res.FSOpenResourceFile(fsr, u'', WRITE)
369-
370356
# Copy the resources from the target specific resource template, if any
371357
typesfound, ownertype = [], None
372358
try:
373359
input = macresource.open_pathname(rsrcname)
374360
except (MacOS.Error, ValueError):
375-
pass
376361
if progress:
377362
progress.inc(50)
378363
else:
364+
if progress:
365+
progress.label("Copy resources...")
366+
progress.set(20)
367+
resfilename = 'python.rsrc' # XXXX later: '%s.rsrc' % shortname
368+
try:
369+
output = Res.FSOpenResourceFile(
370+
os.path.join(destname, 'Contents', 'Resources', resfilename),
371+
u'', WRITE)
372+
except MacOS.Error:
373+
fsr, dummy = Res.FSCreateResourceFile(
374+
os.path.join(destname, 'Contents', 'Resources'),
375+
unicode(resfilename), '')
376+
output = Res.FSOpenResourceFile(fsr, u'', WRITE)
377+
379378
typesfound, ownertype = copyres(input, output, [], 0, progress)
380379
Res.CloseResFile(input)
381-
382-
# Check which resource-types we should not copy from the template
383-
skiptypes = []
384-
## if 'vers' in typesfound: skiptypes.append('vers')
385-
## if 'SIZE' in typesfound: skiptypes.append('SIZE')
386-
## if 'BNDL' in typesfound: skiptypes = skiptypes + ['BNDL', 'FREF', 'icl4',
387-
## 'icl8', 'ics4', 'ics8', 'ICN#', 'ics#']
388-
## if not copy_codefragment:
389-
## skiptypes.append('cfrg')
390-
## skipowner = (ownertype <> None)
391-
392-
# Copy the resources from the template
393-
394-
input = Res.FSOpenResourceFile(
395-
os.path.join(template, 'Contents', 'Resources', 'python.rsrc'), u'', READ)
396-
if progress:
397-
progress.label("Copy standard resources...")
398-
progress.inc(0)
399-
## dummy, tmplowner = copyres(input, output, skiptypes, 1, progress)
400-
dummy, tmplowner = copyres(input, output, skiptypes, 1, None)
401-
402-
Res.CloseResFile(input)
403-
## if ownertype == None:
404-
## raise BuildError, "No owner resource found in either resource file or template"
405-
# Make sure we're manipulating the output resource file now
406-
407-
Res.CloseResFile(output)
380+
Res.CloseResFile(output)
408381

409382
if code:
410383
if raw:

‎Mac/Lib/dialogs.rsrc‎

18.6 KB
Binary file not shown.

‎Mac/Lib/errors.rsrc‎

84.8 KB
Binary file not shown.

‎Mac/Lib/macresource.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ def open_pathname(pathname, verbose=0):
9595
raise
9696
return refno
9797

98+
def open_error_resource():
99+
"""Open the resource file containing the error code to error message
100+
mapping."""
101+
need('Estr', 1, filename="errors.rsrc", modname=__name__)
102+
98103
def _decode(pathname, verbose=0):
99104
# Decode an AppleSingle resource file, return the new pathname.
100105
newpathname = pathname + '.df.rsrc'

‎Mac/OSX/Makefile‎

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,11 @@ LDFLAGS=-F$(builddir) -framework System -framework Python -framework Carbon \
3737
-framework Foundation
3838
CC=cc
3939
LD=cc
40-
REZ=/Developer/Tools/Rez
41-
DEREZ=/Developer/Tools/DeRez
4240
CPMAC=/Developer/Tools/CpMac
4341

4442
PYTHON=$(builddir)/python.exe
4543
APPTEMPLATE=$(srcdir)/Mac/OSXResources/app
4644
APPSUBDIRS=MacOS Resources Resources/English.lproj
47-
RESOURCEDIR=$(srcdir)/Mac/Resources
48-
RESOURCEFILE=python.rsrc
49-
RFCONVERTER=$(srcdir)/Mac/Lib/applesingle.py
5045
CACHERSRC=$(srcdir)/Mac/scripts/cachersrc.py
5146

5247
installapps: install_PythonLauncher install_Python install_BuildApplet install_IDE install_IDLE
@@ -94,29 +89,6 @@ install_Python: $(PYTHON)
9489
done; \
9590
done
9691
$(INSTALL_PROGRAM) $(STRIPFLAG) $(PYTHON) $(APPINSTALLDIR)/Contents/MacOS/python
97-
# Create a temporary version of the resources here
98-
# Note that the resource files can either be real 2-fork resource files
99-
# or AppleSingle encoded files.
100-
@if test -s $(RESOURCEDIR)/dialogs.rsrc; then \
101-
echo $(PYTHON) $(RFCONVERTER) -r $(RESOURCEDIR)/dialogs.rsrc dialogs.rsrc ;\
102-
$(PYTHON) $(RFCONVERTER) -r $(RESOURCEDIR)/dialogs.rsrc dialogs.rsrc ; \
103-
echo $(DEREZ) -useDF -skip ckid dialogs.rsrc > dialogs.r ; \
104-
$(DEREZ) -useDF -skip ckid dialogs.rsrc > dialogs.r ; \
105-
else \
106-
echo $(DEREZ) -skip ckid $(RESOURCEDIR)/dialogs.rsrc > dialogs.r ; \
107-
$(DEREZ) -skip ckid $(RESOURCEDIR)/dialogs.rsrc > dialogs.r ; \
108-
fi
109-
@if test -s $(RESOURCEDIR)/errors.rsrc; then \
110-
echo $(PYTHON) $(RFCONVERTER) -r $(RESOURCEDIR)/errors.rsrc errors.rsrc ;\
111-
$(PYTHON) $(RFCONVERTER) -r $(RESOURCEDIR)/errors.rsrc errors.rsrc ; \
112-
echo $(DEREZ) -useDF -skip ckid errors.rsrc > errors.r ; \
113-
$(DEREZ) -useDF -skip ckid errors.rsrc > errors.r ; \
114-
else \
115-
echo $(DEREZ) -skip ckid $(RESOURCEDIR)/errors.rsrc > errors.r ; \
116-
$(DEREZ) -skip ckid $(RESOURCEDIR)/errors.rsrc > errors.r ; \
117-
fi
118-
$(REZ) -useDF -o $(RESOURCEFILE) dialogs.r errors.r
119-
$(INSTALL_DATA) $(RESOURCEFILE) $(APPINSTALLDIR)/Contents/Resources/$(RESOURCEFILE)
12092
# Finally create the documentation symlink
12193
$(LN) -fsn ../../../../English.lproj/Documentation $(APPINSTALLDIR)/Contents/Resources/English.lproj/Documentation
12294

@@ -205,11 +177,11 @@ installmacsubtree:
205177
echo $(INSTALL_DATA) $$i $(MACLIBDEST); \
206178
fi; \
207179
done
208-
## @for i in $(MACLIBSRC)/*.rsrc; \
209-
## do \
210-
## echo $(CPMAC) $$i $$b ; \
211-
## $(CPMAC) $$i $$b ; \
212-
## done
180+
@for i in $(MACLIBSRC)/*.rsrc; \
181+
do \
182+
echo $(CPMAC) $$i $(MACLIBDEST) ; \
183+
$(CPMAC) $$i $(MACLIBDEST) ; \
184+
done
213185
@for d in $(MACLIBSUBDIRS); \
214186
do \
215187
a=$(MACLIBSRC)/$$d; \

‎Python/mactoolboxglue.c‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,42 @@ char *PyMac_StrError(int err)
8181
static char buf[256];
8282
Handle h;
8383
char *str;
84+
static int errors_loaded;
8485

8586
h = GetResource('Estr', err);
87+
if (!h && !errors_loaded) {
88+
/*
89+
** Attempt to open the resource file containing the
90+
** Estr resources. We ignore all errors. We also try
91+
** this only once.
92+
*/
93+
errors_loaded = 1;
94+
PyObject *m, *rv;
95+
96+
m = PyImport_ImportModule("macresource");
97+
if (!m) {
98+
if (Py_VerboseFlag)
99+
PyErr_Print();
100+
PyErr_Clear();
101+
} else {
102+
rv = PyObject_CallMethod(m, "open_error_resource", "");
103+
if (!rv) {
104+
if (Py_VerboseFlag)
105+
PyErr_Print();
106+
PyErr_Clear();
107+
} else {
108+
Py_DECREF(rv);
109+
/* And try again... */
110+
h = GetResource('Estr', err);
111+
}
112+
}
113+
}
114+
/*
115+
** Whether the code above succeeded or not, we won't try
116+
** again.
117+
*/
118+
errors_loaded = 1;
119+
86120
if ( h ) {
87121
HLock(h);
88122
str = (char *)*h;

0 commit comments

Comments
 (0)