Oops -- Lib/Test should be Lib/test, of course!
[python/dscho.git] / Mac / scripts / PackLibDir.py
blob11803186ca2a008ca7c5b49f78b96572e241a873
2 # Turn a pyc file into a resource file containing it in 'PYC ' resource form
3 from Res import *
4 import Res
5 from Resources import *
6 import os
7 import macfs
8 import sys
9 import py_resource
11 error = 'mkpycresourcefile.error'
13 def mkpycresourcefile(src, dst):
14 """Copy pyc file/dir src to resource file dst."""
16 if not os.path.isdir(src) and src[-4:] <> '.pyc':
17 raise error, 'I can only handle .pyc files or directories'
18 fsid = py_resource.create(dst)
19 if os.path.isdir(src):
20 handlesubdir(src)
21 else:
22 id, name = py_resource.frompycfile(src)
23 print 'Wrote %d: %s %s'%(id, name, src)
24 CloseResFile(fsid)
26 def handlesubdir(srcdir):
27 """Recursively scan a directory for pyc files and copy to resources"""
28 src = os.listdir(srcdir)
29 for file in src:
30 file = os.path.join(srcdir, file)
31 if os.path.isdir(file):
32 handlesubdir(file)
33 elif file[-4:] == '.pyc':
34 id, name = py_resource.frompycfile(file)
35 print 'Wrote %d: %s %s'%(id, name, file)
37 if __name__ == '__main__':
38 args = sys.argv[1:]
39 if not args:
40 ifss, ok = macfs.GetDirectory('Select root of tree to pack:')
41 if not ok:
42 sys.exit(0)
43 args = [ifss.as_pathname()]
44 for ifn in args:
45 ofss, ok = macfs.StandardPutFile('Output for '+os.path.split(ifn)[1])
46 if not ok:
47 sys.exit(0)
48 mkpycresourcefile(ifn, ofss.as_pathname())
49 sys.exit(1) # So we can see something...