1995-08-14 09:19:20 -03:00
|
|
|
|
#
|
1996-02-14 11:58:30 -04:00
|
|
|
|
# binhextree - Recursively descend a directory and
|
1995-08-14 09:19:20 -03:00
|
|
|
|
# pack all resource files.
|
|
|
|
|
#
|
|
|
|
|
# Jack Jansen, CWI, August 1995.
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
import binhex
|
|
|
|
|
import sys
|
1995-08-31 10:47:14 -03:00
|
|
|
|
import macostools
|
|
|
|
|
import macfs
|
1995-08-14 09:19:20 -03:00
|
|
|
|
|
1995-08-31 10:47:14 -03:00
|
|
|
|
import aetools
|
|
|
|
|
from Metrowerks_Shell_Suite import Metrowerks_Shell_Suite
|
|
|
|
|
from Required_Suite import Required_Suite
|
|
|
|
|
|
|
|
|
|
class MwShell(aetools.TalkTo, Metrowerks_Shell_Suite, Required_Suite):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
# Top-level directory
|
|
|
|
|
TOP=''
|
|
|
|
|
|
|
|
|
|
# Where to put CW projects, relative to TOP
|
|
|
|
|
CWDIR=':Mac:mwerks:projects'
|
1996-10-23 12:52:16 -03:00
|
|
|
|
# From which folders to put projects there
|
1998-06-26 12:05:29 -03:00
|
|
|
|
CWDIRDIRS=['build.mac', 'build.macstand', 'build.macfreeze', 'PlugIns']
|
1995-08-31 10:47:14 -03:00
|
|
|
|
|
|
|
|
|
# Helper routines
|
|
|
|
|
def binhexit(path, name):
|
|
|
|
|
dstfile = path + '.hqx'
|
1996-03-25 11:38:36 -04:00
|
|
|
|
if os.path.exists(dstfile):
|
|
|
|
|
print 'Compare', path,'...',
|
|
|
|
|
if binhexcompare(path, dstfile):
|
|
|
|
|
print 'Identical, skipped.'
|
|
|
|
|
return
|
|
|
|
|
else:
|
|
|
|
|
print 'Not up-to-date.'
|
1995-08-31 10:47:14 -03:00
|
|
|
|
print 'Binhexing', path
|
|
|
|
|
binhex.binhex(path, dstfile)
|
|
|
|
|
|
1996-03-25 11:38:36 -04:00
|
|
|
|
def binhexcompare(source, hqxfile):
|
|
|
|
|
"""(source, hqxfile) - Check whether the two files match (forks only)"""
|
|
|
|
|
ifp = binhex.HexBin(hqxfile)
|
|
|
|
|
|
|
|
|
|
sfp = open(source, 'rb')
|
|
|
|
|
while 1:
|
|
|
|
|
d = ifp.read(128000)
|
|
|
|
|
d2 = sfp.read(128000)
|
|
|
|
|
if d <> d2:
|
|
|
|
|
return 0
|
|
|
|
|
if not d: break
|
|
|
|
|
sfp.close()
|
|
|
|
|
ifp.close_data()
|
|
|
|
|
|
|
|
|
|
d = ifp.read_rsrc(128000)
|
|
|
|
|
if d:
|
|
|
|
|
sfp = binhex.openrsrc(source, 'rb')
|
|
|
|
|
d2 = sfp.read(128000)
|
|
|
|
|
if d <> d2:
|
|
|
|
|
return 0
|
|
|
|
|
while 1:
|
|
|
|
|
d = ifp.read_rsrc(128000)
|
|
|
|
|
d2 = sfp.read(128000)
|
|
|
|
|
if d <> d2:
|
|
|
|
|
return 0
|
|
|
|
|
if not d: break
|
|
|
|
|
return 1
|
|
|
|
|
|
1995-08-31 10:47:14 -03:00
|
|
|
|
# Project files to handle
|
|
|
|
|
project_files = {}
|
|
|
|
|
|
|
|
|
|
def hexbincwprojects(creator):
|
|
|
|
|
"""Compact and hexbin all files remembered with a given creator"""
|
1997-08-08 11:51:54 -03:00
|
|
|
|
cw_running = 0
|
1995-08-31 10:47:14 -03:00
|
|
|
|
for fss in project_files[creator]:
|
|
|
|
|
srcfile = fss.as_pathname()
|
1995-10-23 10:55:11 -03:00
|
|
|
|
|
1997-08-08 11:51:54 -03:00
|
|
|
|
old_style = 0
|
1995-10-23 10:55:11 -03:00
|
|
|
|
if srcfile[-1] == '<EFBFBD>':
|
|
|
|
|
dstfile = srcfile[:-1]+'mu.hqx'
|
1997-08-08 11:51:54 -03:00
|
|
|
|
old_style = 1
|
1996-10-23 12:52:16 -03:00
|
|
|
|
elif srcfile[-3] == '.mu':
|
|
|
|
|
dstfile = srcfile + '.hqx'
|
1995-10-23 10:55:11 -03:00
|
|
|
|
elif ord(srcfile[-1]) >= 128:
|
|
|
|
|
dstfile = srcfile[:-1]+`ord(srcfile[-1])`+'.hqx'
|
|
|
|
|
else:
|
|
|
|
|
dstfile = srcfile + '.hqx'
|
|
|
|
|
|
1995-08-31 10:47:14 -03:00
|
|
|
|
if os.path.exists(dstfile) and \
|
1996-10-23 12:52:16 -03:00
|
|
|
|
os.stat(dstfile)[8] >= os.stat(srcfile)[8]:
|
1995-09-01 08:53:17 -03:00
|
|
|
|
print 'Skip', dstfile,'- Up-to-date'
|
1995-08-31 10:47:14 -03:00
|
|
|
|
continue
|
|
|
|
|
print 'Compacting', dstfile
|
1997-08-08 11:51:54 -03:00
|
|
|
|
if old_style:
|
|
|
|
|
if not cw_running:
|
|
|
|
|
try:
|
|
|
|
|
mgr = MwShell(creator, start=1)
|
|
|
|
|
except 'foo':
|
|
|
|
|
print 'Not handled:', creator
|
|
|
|
|
return
|
|
|
|
|
cw_running = 1
|
|
|
|
|
mgr.open(fss)
|
|
|
|
|
mgr.Reset_File_Paths()
|
|
|
|
|
mgr.Remove_Binaries()
|
|
|
|
|
mgr.Close_Project()
|
1995-08-31 10:47:14 -03:00
|
|
|
|
|
|
|
|
|
print 'Binhexing', dstfile
|
|
|
|
|
binhex.binhex(srcfile, dstfile)
|
1997-08-08 11:51:54 -03:00
|
|
|
|
if cw_running:
|
|
|
|
|
mgr.quit()
|
1995-08-31 10:47:14 -03:00
|
|
|
|
|
|
|
|
|
def copycwproject(path, name):
|
|
|
|
|
"""Copy CW project (if needed) and remember for hexbinning"""
|
|
|
|
|
global project_files
|
|
|
|
|
|
|
|
|
|
dstdir = os.path.join(TOP, CWDIR)
|
1996-10-23 12:52:16 -03:00
|
|
|
|
if path[:len(dstdir)] == dstdir:
|
1995-08-31 10:47:14 -03:00
|
|
|
|
return
|
1996-10-23 12:52:16 -03:00
|
|
|
|
srcdir = os.path.split(path)[0]
|
|
|
|
|
srcdir = os.path.split(srcdir)[1]
|
|
|
|
|
if srcdir in CWDIRDIRS:
|
|
|
|
|
if not os.path.exists(dstdir):
|
|
|
|
|
print dstdir
|
|
|
|
|
print 'No CW-project dir, skip', name
|
|
|
|
|
return
|
1996-11-09 14:36:00 -04:00
|
|
|
|
dstfile = os.path.join(dstdir, os.path.join(srcdir, name))
|
1996-10-23 12:52:16 -03:00
|
|
|
|
else:
|
1997-08-08 11:51:54 -03:00
|
|
|
|
if path[-2:] == '.<2E>':
|
|
|
|
|
dstfile = path[:-2]+ '.mu'
|
|
|
|
|
elif path[-4:] == '.prj':
|
|
|
|
|
dstfile = None
|
|
|
|
|
else:
|
1996-10-23 12:52:16 -03:00
|
|
|
|
return
|
1995-08-31 10:47:14 -03:00
|
|
|
|
|
1997-08-08 11:51:54 -03:00
|
|
|
|
if dstfile:
|
|
|
|
|
# If the destination doesn't exists or is older that the source
|
|
|
|
|
# we copy and remember it
|
|
|
|
|
|
|
|
|
|
if os.path.exists(dstfile) and \
|
|
|
|
|
os.stat(dstfile)[8] >= os.stat(path)[8]:
|
|
|
|
|
print 'Not copying', path,'- Up-to-date'
|
|
|
|
|
else:
|
|
|
|
|
print 'Copy', path
|
|
|
|
|
macostools.copy(path, dstfile)
|
1995-08-31 10:47:14 -03:00
|
|
|
|
else:
|
1997-08-08 11:51:54 -03:00
|
|
|
|
dstfile = path
|
1995-08-31 10:47:14 -03:00
|
|
|
|
|
|
|
|
|
fss = macfs.FSSpec(dstfile)
|
|
|
|
|
creator = fss.GetCreatorType()[0]
|
|
|
|
|
|
|
|
|
|
if project_files.has_key(creator):
|
|
|
|
|
project_files[creator].append(fss)
|
|
|
|
|
else:
|
|
|
|
|
project_files[creator] = [fss]
|
|
|
|
|
|
1996-04-19 13:02:20 -03:00
|
|
|
|
def copycwexpfile(path, name):
|
|
|
|
|
"""Copy CW export file"""
|
|
|
|
|
global project_files
|
|
|
|
|
|
|
|
|
|
dstdir = os.path.join(TOP, CWDIR)
|
1996-10-23 12:52:16 -03:00
|
|
|
|
if path[:len(dstdir)] == dstdir:
|
1996-04-19 13:02:20 -03:00
|
|
|
|
return
|
1996-10-23 12:52:16 -03:00
|
|
|
|
srcdir = os.path.split(path)[0]
|
|
|
|
|
srcdir = os.path.split(srcdir)[1]
|
|
|
|
|
if srcdir in CWDIRDIRS:
|
|
|
|
|
if not os.path.exists(dstdir):
|
|
|
|
|
print dstdir
|
|
|
|
|
print 'No CW-project dir, skip', name
|
|
|
|
|
return
|
1996-11-09 14:36:00 -04:00
|
|
|
|
dstfile = os.path.join(dstdir, os.path.join(srcdir, name))
|
1996-10-23 12:52:16 -03:00
|
|
|
|
else:
|
|
|
|
|
if path[-6:] != '.<2E>.exp':
|
|
|
|
|
return
|
|
|
|
|
dstfile = path[:-6] + '.mu.exp'
|
1996-04-19 13:02:20 -03:00
|
|
|
|
if dstfile[-6:] == '.<2E>.exp':
|
|
|
|
|
dstfile = dstfile[:-6]+'.mu.exp'
|
|
|
|
|
|
|
|
|
|
# If the destination doesn't exists or is older that the source
|
|
|
|
|
# we copy and remember it
|
|
|
|
|
|
|
|
|
|
if os.path.exists(dstfile) and \
|
1996-10-23 12:52:16 -03:00
|
|
|
|
os.stat(dstfile)[8] >= os.stat(path)[8]:
|
1996-04-19 13:02:20 -03:00
|
|
|
|
print 'Not copying', path,'- Up-to-date'
|
|
|
|
|
else:
|
|
|
|
|
print 'Copy', path
|
|
|
|
|
macostools.copy(path, dstfile)
|
1995-08-31 10:47:14 -03:00
|
|
|
|
|
|
|
|
|
extensions = [
|
|
|
|
|
('.rsrc', binhexit),
|
1996-04-10 11:51:38 -03:00
|
|
|
|
('.gif', binhexit),
|
1996-04-19 13:02:20 -03:00
|
|
|
|
('.<2E>', copycwproject),
|
1997-08-08 11:51:54 -03:00
|
|
|
|
('.prj', copycwproject),
|
|
|
|
|
('.prj.exp', copycwexpfile),
|
1996-04-19 13:02:20 -03:00
|
|
|
|
('.<2E>.exp', copycwexpfile)
|
1995-08-31 10:47:14 -03:00
|
|
|
|
]
|
1995-08-14 09:19:20 -03:00
|
|
|
|
|
|
|
|
|
def walker(arg, top, names):
|
1996-03-07 11:16:27 -04:00
|
|
|
|
lnames = names[:]
|
|
|
|
|
for n in lnames:
|
|
|
|
|
if n[0] == '(' and n[-1] == ')':
|
|
|
|
|
names.remove(n)
|
|
|
|
|
continue
|
1995-08-31 10:47:14 -03:00
|
|
|
|
for ext, handler in extensions:
|
1995-08-14 09:19:20 -03:00
|
|
|
|
if n[-len(ext):] == ext:
|
|
|
|
|
name = os.path.join(top, n)
|
1995-08-31 10:47:14 -03:00
|
|
|
|
handler(name, n)
|
1995-08-14 09:19:20 -03:00
|
|
|
|
|
|
|
|
|
def dodir(name):
|
1995-08-31 10:47:14 -03:00
|
|
|
|
global TOP, project_files
|
|
|
|
|
TOP = name
|
1995-08-14 09:19:20 -03:00
|
|
|
|
os.path.walk(name, walker, None)
|
1995-08-31 10:47:14 -03:00
|
|
|
|
|
|
|
|
|
for creator in project_files.keys():
|
|
|
|
|
hexbincwprojects(creator)
|
|
|
|
|
project_files = {}
|
1995-08-14 09:19:20 -03:00
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
|
for dir in sys.argv[1:]:
|
|
|
|
|
dodir(dir)
|
|
|
|
|
elif os.name == 'mac':
|
|
|
|
|
import macfs
|
|
|
|
|
dir, ok = macfs.GetDirectory('Folder to search:')
|
|
|
|
|
if not ok:
|
|
|
|
|
sys.exit(0)
|
|
|
|
|
dodir(dir.as_pathname())
|
|
|
|
|
else:
|
|
|
|
|
print 'Usage: hexbintree dir ...'
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
if os.name == 'mac':
|
|
|
|
|
sys.exit(1) # Keep window
|
|
|
|
|
else:
|
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
main()
|
|
|
|
|
|