• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Scan the tree passed as argv[0] for .rsrc files, skipping .rsrc.df.rsrc
2# files, and open these. The effect of this is to create the .rsrc.df.rsrc
3# cache files if needed.
4# These are needed on OSX: the .rsrc files are in reality AppleSingle-encoded
5# files. We decode the resources into a datafork-based resource file.
6
7import macresource
8import os
9import sys
10import getopt
11
12class NoArgsError(Exception):
13    pass
14
15def handler((verbose, force), dirname, fnames):
16    for fn in fnames:
17        if fn[-5:] == '.rsrc' and fn[-13:] != '.rsrc.df.rsrc':
18            if force:
19                try:
20                    os.unlink(os.path.join(dirname, fn + '.df.rsrc'))
21                except IOError:
22                    pass
23            macresource.open_pathname(os.path.join(dirname, fn), verbose=verbose)
24
25def main():
26    try:
27        opts, args = getopt.getopt(sys.argv[1:], 'vf')
28        if not args:
29            raise NoArgsError
30    except (getopt.GetoptError, NoArgsError):
31        sys.stderr.write('Usage: cachersrc.py dirname ...\n')
32        sys.exit(1)
33    verbose = 0
34    force = 0
35    for o, v in opts:
36        if o == '-v':
37            verbose = 1
38        if o == '-f':
39            force = 1
40    for dir in sys.argv[1:]:
41        os.path.walk(dir, handler, (verbose, force))
42
43if __name__ == '__main__':
44    main()
45