annotate Lib/distutils/dep_util.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents a5229237eb50
children 9211a5d7d0b4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12226
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
1 """distutils.dep_util
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
2
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
3 Utility functions for simple, timestamp-based dependency of files
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
4 and groups of files; also, function based entirely on such
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
5 timestamp dependency analysis."""
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
6
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
7 __revision__ = "$Id$"
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
8
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
9 import os
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
10 from distutils.errors import DistutilsFileError
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
11
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
12
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
13 def newer (source, target):
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
14 """Return true if 'source' exists and is more recently modified than
14864
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
15 'target', or if 'source' exists and 'target' doesn't. Return false if
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
16 both exist and 'target' is the same age or younger than 'source'.
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
17 Raise DistutilsFileError if 'source' does not exist.
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
18 """
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
19 if not os.path.exists(source):
43290
ffa0747a7cb7 be explicit about the actual location of the missing file
Skip Montanaro <skip@pobox.com>
parents: 33965
diff changeset
20 raise DistutilsFileError, ("file '%s' does not exist" %
ffa0747a7cb7 be explicit about the actual location of the missing file
Skip Montanaro <skip@pobox.com>
parents: 33965
diff changeset
21 os.path.abspath(source))
14864
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
22 if not os.path.exists(target):
12226
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
23 return 1
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
24
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
25 from stat import ST_MTIME
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
26 mtime1 = os.stat(source)[ST_MTIME]
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
27 mtime2 = os.stat(target)[ST_MTIME]
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
28
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
29 return mtime1 > mtime2
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
30
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
31 # newer ()
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
32
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
33
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
34 def newer_pairwise (sources, targets):
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
35 """Walk two filename lists in parallel, testing if each source is newer
14864
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
36 than its corresponding target. Return a pair of lists (sources,
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
37 targets) where source is newer than target, according to the semantics
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
38 of 'newer()'.
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
39 """
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
40 if len(sources) != len(targets):
12226
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
41 raise ValueError, "'sources' and 'targets' must be same length"
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
42
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
43 # build a pair of lists (sources, targets) where source is newer
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
44 n_sources = []
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
45 n_targets = []
14864
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
46 for i in range(len(sources)):
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
47 if newer(sources[i], targets[i]):
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
48 n_sources.append(sources[i])
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
49 n_targets.append(targets[i])
12226
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
50
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
51 return (n_sources, n_targets)
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
52
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
53 # newer_pairwise ()
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
54
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
55
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
56 def newer_group (sources, target, missing='error'):
14864
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
57 """Return true if 'target' is out-of-date with respect to any file
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
58 listed in 'sources'. In other words, if 'target' exists and is newer
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
59 than every file in 'sources', return false; otherwise return true.
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
60 'missing' controls what we do when a source file is missing; the
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
61 default ("error") is to blow up with an OSError from inside 'stat()';
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
62 if it is "ignore", we silently drop any missing source files; if it is
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
63 "newer", any missing source files make us assume that 'target' is
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
64 out-of-date (this is handy in "dry-run" mode: it'll make you pretend to
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
65 carry out commands that wouldn't work because inputs are missing, but
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
66 that doesn't matter because you're not actually going to run the
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
67 commands).
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
68 """
12226
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
69 # If the target doesn't even exist, then it's definitely out-of-date.
14864
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
70 if not os.path.exists(target):
12226
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
71 return 1
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 14864
diff changeset
72
12226
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
73 # Otherwise we have to find out the hard way: if *any* source file
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
74 # is more recent than 'target', then 'target' is out-of-date and
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
75 # we can immediately return true. If we fall through to the end
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
76 # of the loop, then 'target' is up-to-date and we return false.
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
77 from stat import ST_MTIME
14864
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
78 target_mtime = os.stat(target)[ST_MTIME]
12226
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
79 for source in sources:
14864
56fda4e9ece9 Reformat docstrings.
Greg Ward <gward@python.net>
parents: 12226
diff changeset
80 if not os.path.exists(source):
12226
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
81 if missing == 'error': # blow up when we stat() the file
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 14864
diff changeset
82 pass
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 14864
diff changeset
83 elif missing == 'ignore': # missing source dropped from
12226
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
84 continue # target's dependency list
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
85 elif missing == 'newer': # missing source means target is
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
86 return 1 # out-of-date
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 14864
diff changeset
87
12226
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
88 source_mtime = os.stat(source)[ST_MTIME]
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
89 if source_mtime > target_mtime:
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
90 return 1
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
91 else:
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
92 return 0
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
93
ffd242fed0e2 Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
diff changeset
94 # newer_group ()