blob: fa95af7e64c8353ff3ab5e5a4404aca21c613aec [file] [log] [blame]
Jack Jansen3050a2d1995-08-14 12:19:20 +00001#
2# hexbintree - Recursively descend a directory and
3# pack all resource files.
4#
5# Jack Jansen, CWI, August 1995.
6#
7# To do:
8# - Also do project files (.µ and .¹), after using AppleEvents to the
9# various builders to clean the projects
10# - Don't hexbin (and clean) if there exists a .hqx file that is newer.
11#
12
13import os
14import binhex
15import sys
Jack Jansen8094f0d1995-08-31 13:47:14 +000016import macostools
17import macfs
Jack Jansen3050a2d1995-08-14 12:19:20 +000018
Jack Jansen8094f0d1995-08-31 13:47:14 +000019import addpack
20addpack.addpack('Tools')
21addpack.addpack('bgen')
22addpack.addpack('AE')
23import aetools
24from Metrowerks_Shell_Suite import Metrowerks_Shell_Suite
25from Required_Suite import Required_Suite
26
27class MwShell(aetools.TalkTo, Metrowerks_Shell_Suite, Required_Suite):
28 pass
29
30# Top-level directory
31TOP=''
32
33# Where to put CW projects, relative to TOP
34CWDIR=':Mac:mwerks:projects'
35
36# Helper routines
37def binhexit(path, name):
38 dstfile = path + '.hqx'
39 if os.path.exists(dstfile) and \
40 os.stat(dstfile)[8] > os.stat(path)[8]:
41 print 'Skip', path,'- Up-to-date'
42 return
43 print 'Binhexing', path
44 binhex.binhex(path, dstfile)
45
46# Project files to handle
47project_files = {}
48
49def hexbincwprojects(creator):
50 """Compact and hexbin all files remembered with a given creator"""
51 print 'Please start project mgr with signature', creator,'-'
52 sys.stdin.readline()
53 try:
54 mgr = MwShell(creator)
55 except 'foo':
56 print 'Not handled:', creator
57 return
58 for fss in project_files[creator]:
59 srcfile = fss.as_pathname()
60 dstfile = srcfile + '.hqx'
61 if os.path.exists(dstfile) and \
62 os.stat(dstfile)[8] > os.stat(srcfile)[8]:
63 print 'Skip', path,'- Up-to-date'
64 continue
65 print 'Compacting', dstfile
66 mgr.open(fss)
67 mgr.Reset_File_Paths()
68 mgr.Remove_Binaries()
69 mgr.Close_Project()
70
71 print 'Binhexing', dstfile
72 binhex.binhex(srcfile, dstfile)
73 mgr.quit()
74
75def copycwproject(path, name):
76 """Copy CW project (if needed) and remember for hexbinning"""
77 global project_files
78
79 dstdir = os.path.join(TOP, CWDIR)
80 if not os.path.exists(dstdir):
81 print dstdir
82 print 'No CW-project dir, skip', name
83 return
84 dstfile = os.path.join(dstdir, name)
85 # Check that we're not in the dest directory
86 if dstfile == path:
87 return
88
89 # If the destination doesn't exists or is older that the source
90 # we copy and remember it
91
92 if os.path.exists(dstfile) and \
93 os.stat(dstfile)[8] > os.stat(path)[8]:
94 print 'Not copying', path,'- Up-to-date'
95 else:
96 print 'Copy', path
97 macostools.copy(path, dstfile)
98
99 fss = macfs.FSSpec(dstfile)
100 creator = fss.GetCreatorType()[0]
101
102 if project_files.has_key(creator):
103 project_files[creator].append(fss)
104 else:
105 project_files[creator] = [fss]
106
107
108extensions = [
109 ('.rsrc', binhexit),
110 ('.µ', copycwproject)
111 ]
Jack Jansen3050a2d1995-08-14 12:19:20 +0000112
113def walker(arg, top, names):
114 for n in names:
Jack Jansen8094f0d1995-08-31 13:47:14 +0000115 for ext, handler in extensions:
Jack Jansen3050a2d1995-08-14 12:19:20 +0000116 if n[-len(ext):] == ext:
117 name = os.path.join(top, n)
Jack Jansen8094f0d1995-08-31 13:47:14 +0000118 handler(name, n)
Jack Jansen3050a2d1995-08-14 12:19:20 +0000119
120def dodir(name):
Jack Jansen8094f0d1995-08-31 13:47:14 +0000121 global TOP, project_files
122 TOP = name
Jack Jansen3050a2d1995-08-14 12:19:20 +0000123 os.path.walk(name, walker, None)
Jack Jansen8094f0d1995-08-31 13:47:14 +0000124
125 for creator in project_files.keys():
126 hexbincwprojects(creator)
127 project_files = {}
Jack Jansen3050a2d1995-08-14 12:19:20 +0000128
129def main():
130 if len(sys.argv) > 1:
131 for dir in sys.argv[1:]:
132 dodir(dir)
133 elif os.name == 'mac':
134 import macfs
135 dir, ok = macfs.GetDirectory('Folder to search:')
136 if not ok:
137 sys.exit(0)
138 dodir(dir.as_pathname())
139 else:
140 print 'Usage: hexbintree dir ...'
141 sys.exit(1)
142 if os.name == 'mac':
143 sys.exit(1) # Keep window
144 else:
145 sys.exit(0)
146
147if __name__ == '__main__':
148 main()
149