Update for release.
[python/dscho.git] / Mac / scripts / fixfiletypes.py
blob872c891e99fae52e441a4382f7c0550964a740b8
2 # Fixfiletypes - Set mac filetypes to something sensible,
3 # recursively down a directory tree.
5 # It will only touch extensions it feels pretty sure about.
6 # This script is useful after copying files from unix.
8 # Jack Jansen, CWI, 1995.
10 import os
11 import macfs
12 import EasyDialogs
13 import sys
14 import macostools
16 list = [
17 ('.py', 'Pyth', 'TEXT'),
18 ('.pyc', 'Pyth', 'PYC '),
19 ('.c', 'CWIE', 'TEXT'),
20 ('.h', 'CWIE', 'TEXT'),
21 ('.as', 'ToyS', 'TEXT'),
22 ('.hqx', 'BnHq', 'TEXT'),
23 ('.cmif', 'CMIF', 'TEXT'),
24 ('.cmc', 'CMIF', 'CMC '),
25 ('.aiff', 'SCPL', 'AIFF'),
26 ('.mpg', 'mMPG', 'MPEG'),
29 def walktree(name, change):
30 if os.path.isfile(name):
31 for ext, cr, tp in list:
32 if name[-len(ext):] == ext:
33 fs = macfs.FSSpec(name)
34 curcrtp = fs.GetCreatorType()
35 if curcrtp <> (cr, tp):
36 if change:
37 fs.SetCreatorType(cr, tp)
38 macostools.touched(fs)
39 print 'Fixed ', name
40 else:
41 print 'Wrong', curcrtp, name
42 elif os.path.isdir(name):
43 print '->', name
44 files = os.listdir(name)
45 for f in files:
46 walktree(os.path.join(name, f), change)
48 def run(change):
49 pathname = EasyDialogs.AskFolder(message='Folder to search:')
50 if not pathname:
51 sys.exit(0)
52 walktree(pathname, change)
54 if __name__ == '__main__':
55 run(1)