Jack Jansen | 3050a2d | 1995-08-14 12:19:20 +0000 | [diff] [blame] | 1 | # |
| 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 | |
| 13 | import os |
| 14 | import binhex |
| 15 | import sys |
| 16 | |
| 17 | extensions = ['.rsrc'] |
| 18 | |
| 19 | def walker(arg, top, names): |
| 20 | for n in names: |
| 21 | for ext in extensions: |
| 22 | if n[-len(ext):] == ext: |
| 23 | name = os.path.join(top, n) |
| 24 | print 'Binhexing', name |
| 25 | binhex.binhex(name, name + '.hqx') |
| 26 | |
| 27 | def dodir(name): |
| 28 | os.path.walk(name, walker, None) |
| 29 | |
| 30 | def main(): |
| 31 | if len(sys.argv) > 1: |
| 32 | for dir in sys.argv[1:]: |
| 33 | dodir(dir) |
| 34 | elif os.name == 'mac': |
| 35 | import macfs |
| 36 | dir, ok = macfs.GetDirectory('Folder to search:') |
| 37 | if not ok: |
| 38 | sys.exit(0) |
| 39 | dodir(dir.as_pathname()) |
| 40 | else: |
| 41 | print 'Usage: hexbintree dir ...' |
| 42 | sys.exit(1) |
| 43 | if os.name == 'mac': |
| 44 | sys.exit(1) # Keep window |
| 45 | else: |
| 46 | sys.exit(0) |
| 47 | |
| 48 | if __name__ == '__main__': |
| 49 | main() |
| 50 | |