diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 2003-02-17 16:47:12 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 2003-02-17 16:47:12 (GMT) |
commit | 946c19445c902d68ccd75452b97a8098e9b212e5 (patch) | |
tree | cbde05778e214aceabafc1453b704a4d58a58aaf /Lib/plat-mac/macresource.py | |
parent | 3d3b74677a440b00d94b6b4e71e7f2f97800c427 (diff) | |
download | cpython-946c19445c902d68ccd75452b97a8098e9b212e5.zip cpython-946c19445c902d68ccd75452b97a8098e9b212e5.tar.gz cpython-946c19445c902d68ccd75452b97a8098e9b212e5.tar.bz2 |
When installing resource files whose name ends in .rsrc use the
"copy anything to a data fork based resource file" trick of macresource.
Fixes #688007.
Diffstat (limited to 'Lib/plat-mac/macresource.py')
-rw-r--r-- | Lib/plat-mac/macresource.py | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/Lib/plat-mac/macresource.py b/Lib/plat-mac/macresource.py index 7e99c00..16eed00 100644 --- a/Lib/plat-mac/macresource.py +++ b/Lib/plat-mac/macresource.py @@ -3,6 +3,8 @@ from Carbon import Res import os import sys +import MacOS +import macostools class ArgumentError(TypeError): pass class ResourceFileNotFoundError(ImportError): pass @@ -99,16 +101,51 @@ def open_error_resource(): mapping.""" need('Estr', 1, filename="errors.rsrc", modname=__name__) -def _decode(pathname, verbose=0): +def _decode(pathname, verbose=0, newpathname=None): # Decode an AppleSingle resource file, return the new pathname. - newpathname = pathname + '.df.rsrc' - if os.path.exists(newpathname) and \ + if not newpathname: + newpathname = pathname + '.df.rsrc' + if os.path.exists(newpathname) and \ os.stat(newpathname).st_mtime >= os.stat(pathname).st_mtime: - return newpathname + return newpathname if verbose: print 'Decoding', pathname import applesingle applesingle.decode(pathname, newpathname, resonly=1) return newpathname -
\ No newline at end of file +def install(src, dst, mkdirs=0): + """Copy a resource file. The result will always be a datafork-based + resource file, whether the source is datafork-based, resource-fork + based or AppleSingle-encoded.""" + if mkdirs: + macostools.mkdirs(os.path.split(dst)[0]) + try: + refno = Res.FSOpenResourceFile(src, u'', 1) + except Res.Error, arg: + if arg[0] != -199: + # -199 is "bad resource map" + raise + else: + # Resource-fork based. Simply copy. + Res.CloseResFile(refno) + macostools.copy(src, dst) + + try: + refno = Res.FSpOpenResFile(src, 1) + except Res.Error, arg: + if not arg[0] in (-37, -39): + raise + else: + Res.CloseResFile(refno) + BUFSIZ=0x80000 # Copy in 0.5Mb chunks + ifp = MacOS.openrf(src, '*rb') + ofp = open(dst, 'wb') + d = ifp.read(BUFSIZ) + while d: + ofp.write(d) + d = ifp.read(BUFSIZ) + ifp.close() + ofp.close() + + _decode(src, newpathname=dst) |