annotate Mac/scripts/cachersrc.py @ 27998:e27f58a50737 legacy-trunk

SF bug #690377: Dud footnote reference in distutils docs
author Raymond Hettinger <python@rcn.com>
date Fri, 21 Feb 2003 02:47:09 +0000
parents eef73e8823d5
children c3a096bfbd6b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24697
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1 # Scan the tree passed as argv[0] for .rsrc files, skipping .rsrc.df.rsrc
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
2 # files, and open these. The effect of this is to create the .rsrc.df.rsrc
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
3 # cache files if needed.
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
4 # These are needed on OSX: the .rsrc files are in reality AppleSingle-encoded
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
5 # files. We decode the resources into a datafork-based resource file.
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
6
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
7 import macresource
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
8 import os
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
9 import sys
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
10 import getopt
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
11
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
12 class NoArgsError(Exception):
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
13 pass
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
14
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
15 def handler((verbose, force), dirname, fnames):
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
16 for fn in fnames:
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
17 if fn[-5:] == '.rsrc' and fn[-13:] != '.rsrc.df.rsrc':
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
18 if force:
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
19 try:
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
20 os.unlink(os.path.join(dirname, fn + '.df.rsrc'))
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
21 except IOError:
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
22 pass
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
23 macresource.open_pathname(os.path.join(dirname, fn), verbose=verbose)
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
24
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
25 def main():
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
26 try:
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
27 opts, args = getopt.getopt(sys.argv[1:], 'vf')
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
28 if not args:
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
29 raise NoArgsError
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
30 except (getopt.GetoptError, NoArgsError):
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
31 sys.stderr.write('Usage: cachersrc.py dirname ...\n')
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
32 sys.exit(1)
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
33 verbose = 0
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
34 force = 0
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
35 for o, v in opts:
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
36 if o == '-v':
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
37 verbose = 1
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
38 if o == '-f':
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
39 force = 1
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
40 for dir in sys.argv[1:]:
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
41 os.path.walk(dir, handler, (verbose, force))
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
42
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
43 if __name__ == '__main__':
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
44 main()
eef73e8823d5 Tool to pre-created cached .rsrc.df.rsrc files in the Lib directories,
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
45