Mercurial > cpython-lru_cache-weakref
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 |
| 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 | 15 'target', or if 'source' exists and 'target' doesn't. Return false if |
| 16 both exist and 'target' is the same age or younger than 'source'. | |
| 17 Raise DistutilsFileError if 'source' does not exist. | |
| 18 """ | |
| 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 | 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 | 36 than its corresponding target. Return a pair of lists (sources, |
| 37 targets) where source is newer than target, according to the semantics | |
| 38 of 'newer()'. | |
| 39 """ | |
| 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 | 46 for i in range(len(sources)): |
| 47 if newer(sources[i], targets[i]): | |
| 48 n_sources.append(sources[i]) | |
| 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 | 57 """Return true if 'target' is out-of-date with respect to any file |
| 58 listed in 'sources'. In other words, if 'target' exists and is newer | |
| 59 than every file in 'sources', return false; otherwise return true. | |
| 60 'missing' controls what we do when a source file is missing; the | |
| 61 default ("error") is to blow up with an OSError from inside 'stat()'; | |
| 62 if it is "ignore", we silently drop any missing source files; if it is | |
| 63 "newer", any missing source files make us assume that 'target' is | |
| 64 out-of-date (this is handy in "dry-run" mode: it'll make you pretend to | |
| 65 carry out commands that wouldn't work because inputs are missing, but | |
| 66 that doesn't matter because you're not actually going to run the | |
| 67 commands). | |
| 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 | 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 | 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 | 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 | 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 | 82 pass |
| 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 | 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 () |
