Bump version to 0.9.1.
[python/dscho.git] / Mac / scripts / fixfiletypes.py
blob284b5e1234129b6af010fdfdcfc4fc54bef82256
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 sys
13 import macostools
15 list = [
16 ('.py', 'Pyth', 'TEXT'),
17 ('.pyc', 'Pyth', 'PYC '),
18 ('.c', 'CWIE', 'TEXT'),
19 ('.h', 'CWIE', 'TEXT'),
20 ('.as', 'ToyS', 'TEXT'),
21 ('.hqx', 'BnHq', 'TEXT'),
22 ('.cmif', 'CMIF', 'TEXT'),
23 ('.cmc', 'CMIF', 'CMC '),
24 ('.aiff', 'SCPL', 'AIFF'),
25 ('.mpg', 'mMPG', 'MPEG'),
28 def walktree(name, change):
29 if os.path.isfile(name):
30 for ext, cr, tp in list:
31 if name[-len(ext):] == ext:
32 fs = macfs.FSSpec(name)
33 curcrtp = fs.GetCreatorType()
34 if curcrtp <> (cr, tp):
35 if change:
36 fs.SetCreatorType(cr, tp)
37 macostools.touched(fs)
38 print 'Fixed ', name
39 else:
40 print 'Wrong', curcrtp, name
41 elif os.path.isdir(name):
42 print '->', name
43 files = os.listdir(name)
44 for f in files:
45 walktree(os.path.join(name, f), change)
47 def run(change):
48 fss, ok = macfs.GetDirectory('Folder to search:')
49 if not ok:
50 sys.exit(0)
51 walktree(fss.as_pathname(), change)
53 if __name__ == '__main__':
54 run(1)