summaryrefslogtreecommitdiffstats
path: root/Mac/scripts/PackLibDir.py
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>1996-05-31 13:02:52 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>1996-05-31 13:02:52 (GMT)
commiteaa1959c07893aa96dbb016a02a846ece99cd14f (patch)
tree3db04ead9732e557350bd5069a4b89b953656013 /Mac/scripts/PackLibDir.py
parent0acb7f7a57b6bf74cf46bffecf3a54e6c3216444 (diff)
downloadcpython-eaa1959c07893aa96dbb016a02a846ece99cd14f.zip
cpython-eaa1959c07893aa96dbb016a02a846ece99cd14f.tar.gz
cpython-eaa1959c07893aa96dbb016a02a846ece99cd14f.tar.bz2
Use py_resource module
Diffstat (limited to 'Mac/scripts/PackLibDir.py')
-rw-r--r--Mac/scripts/PackLibDir.py56
1 files changed, 10 insertions, 46 deletions
diff --git a/Mac/scripts/PackLibDir.py b/Mac/scripts/PackLibDir.py
index 2afb26f..1180318 100644
--- a/Mac/scripts/PackLibDir.py
+++ b/Mac/scripts/PackLibDir.py
@@ -6,69 +6,33 @@ from Resources import *
import os
import macfs
import sys
-
-READ = 1
-WRITE = 2
-smAllScripts = -3
+import py_resource
error = 'mkpycresourcefile.error'
-def Pstring(str):
- if len(str) > 255:
- raise ValueError, 'String too large'
- return chr(len(str))+str
-
-def createoutput(dst):
- """Create output file. Return handle and first id to use."""
-
-
- FSpCreateResFile(dst, 'Pyth', 'rsrc', smAllScripts)
- output = FSpOpenResFile(dst, WRITE)
- UseResFile(output)
- num = 128
- return output, num
-
-def writemodule(name, id, data):
- """Write pyc code to a PYC resource with given name and id."""
- # XXXX Check that it doesn't exist
- res = Resource(data)
- res.AddResource('PYC ', id, name)
- res.WriteResource()
- res.ReleaseResource()
-
def mkpycresourcefile(src, dst):
"""Copy pyc file/dir src to resource file dst."""
if not os.path.isdir(src) and src[-4:] <> '.pyc':
raise error, 'I can only handle .pyc files or directories'
- handle, oid = createoutput(dst)
+ fsid = py_resource.create(dst)
if os.path.isdir(src):
- id = handlesubdir(handle, oid, src)
+ handlesubdir(src)
else:
- id = handleonepycfile(handle, oid, src)
- print 'Wrote',id-oid,'PYC resources to', dst
- CloseResFile(handle)
+ id, name = py_resource.frompycfile(src)
+ print 'Wrote %d: %s %s'%(id, name, src)
+ CloseResFile(fsid)
-def handleonepycfile(handle, id, file):
- """Copy one pyc file to the open resource file"""
- d, name = os.path.split(file)
- name = name[:-4]
- print ' module', name
- writemodule(name, id, open(file, 'rb').read())
- return id+1
-
-def handlesubdir(handle, id, srcdir):
+def handlesubdir(srcdir):
"""Recursively scan a directory for pyc files and copy to resources"""
- print 'Directory', srcdir
src = os.listdir(srcdir)
for file in src:
file = os.path.join(srcdir, file)
if os.path.isdir(file):
- id = handlesubdir(handle, id, file)
+ handlesubdir(file)
elif file[-4:] == '.pyc':
- id = handleonepycfile(handle, id, file)
- return id
-
+ id, name = py_resource.frompycfile(file)
+ print 'Wrote %d: %s %s'%(id, name, file)
if __name__ == '__main__':
args = sys.argv[1:]