blob: 11803186ca2a008ca7c5b49f78b96572e241a873 [file] [log] [blame]
Jack Jansen7571f301995-07-29 13:48:41 +00001#
2# Turn a pyc file into a resource file containing it in 'PYC ' resource form
Jack Jansen7571f301995-07-29 13:48:41 +00003from Res import *
4import Res
5from Resources import *
6import os
7import macfs
8import sys
Jack Janseneaa19591996-05-31 13:02:52 +00009import py_resource
Jack Jansen7571f301995-07-29 13:48:41 +000010
11error = 'mkpycresourcefile.error'
12
Jack Jansen7571f301995-07-29 13:48:41 +000013def mkpycresourcefile(src, dst):
14 """Copy pyc file/dir src to resource file dst."""
15
16 if not os.path.isdir(src) and src[-4:] <> '.pyc':
17 raise error, 'I can only handle .pyc files or directories'
Jack Janseneaa19591996-05-31 13:02:52 +000018 fsid = py_resource.create(dst)
Jack Jansen7571f301995-07-29 13:48:41 +000019 if os.path.isdir(src):
Jack Janseneaa19591996-05-31 13:02:52 +000020 handlesubdir(src)
Jack Jansen7571f301995-07-29 13:48:41 +000021 else:
Jack Janseneaa19591996-05-31 13:02:52 +000022 id, name = py_resource.frompycfile(src)
23 print 'Wrote %d: %s %s'%(id, name, src)
24 CloseResFile(fsid)
Jack Jansen7571f301995-07-29 13:48:41 +000025
Jack Janseneaa19591996-05-31 13:02:52 +000026def handlesubdir(srcdir):
Jack Jansen7571f301995-07-29 13:48:41 +000027 """Recursively scan a directory for pyc files and copy to resources"""
Jack Jansen7571f301995-07-29 13:48:41 +000028 src = os.listdir(srcdir)
29 for file in src:
30 file = os.path.join(srcdir, file)
31 if os.path.isdir(file):
Jack Janseneaa19591996-05-31 13:02:52 +000032 handlesubdir(file)
Jack Jansen7571f301995-07-29 13:48:41 +000033 elif file[-4:] == '.pyc':
Jack Janseneaa19591996-05-31 13:02:52 +000034 id, name = py_resource.frompycfile(file)
35 print 'Wrote %d: %s %s'%(id, name, file)
Jack Jansen7571f301995-07-29 13:48:41 +000036
37if __name__ == '__main__':
38 args = sys.argv[1:]
39 if not args:
Jack Jansen9062fa21995-08-14 12:21:12 +000040 ifss, ok = macfs.GetDirectory('Select root of tree to pack:')
41 if not ok:
42 sys.exit(0)
43 args = [ifss.as_pathname()]
Jack Jansen7571f301995-07-29 13:48:41 +000044 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...