source: vendor/python/2.5/Lib/distutils/dep_util.py@ 3225

Last change on this file since 3225 was 3225, checked in by bird, 19 years ago

Python 2.5

File size: 3.5 KB
Line 
1"""distutils.dep_util
2
3Utility functions for simple, timestamp-based dependency of files
4and groups of files; also, function based entirely on such
5timestamp dependency analysis."""
6
7# This module should be kept compatible with Python 2.1.
8
9__revision__ = "$Id: dep_util.py 37828 2004-11-10 22:23:15Z loewis $"
10
11import os
12from distutils.errors import DistutilsFileError
13
14
15def newer (source, target):
16 """Return true if 'source' exists and is more recently modified than
17 'target', or if 'source' exists and 'target' doesn't. Return false if
18 both exist and 'target' is the same age or younger than 'source'.
19 Raise DistutilsFileError if 'source' does not exist.
20 """
21 if not os.path.exists(source):
22 raise DistutilsFileError, "file '%s' does not exist" % source
23 if not os.path.exists(target):
24 return 1
25
26 from stat import ST_MTIME
27 mtime1 = os.stat(source)[ST_MTIME]
28 mtime2 = os.stat(target)[ST_MTIME]
29
30 return mtime1 > mtime2
31
32# newer ()
33
34
35def newer_pairwise (sources, targets):
36 """Walk two filename lists in parallel, testing if each source is newer
37 than its corresponding target. Return a pair of lists (sources,
38 targets) where source is newer than target, according to the semantics
39 of 'newer()'.
40 """
41 if len(sources) != len(targets):
42 raise ValueError, "'sources' and 'targets' must be same length"
43
44 # build a pair of lists (sources, targets) where source is newer
45 n_sources = []
46 n_targets = []
47 for i in range(len(sources)):
48 if newer(sources[i], targets[i]):
49 n_sources.append(sources[i])
50 n_targets.append(targets[i])
51
52 return (n_sources, n_targets)
53
54# newer_pairwise ()
55
56
57def newer_group (sources, target, missing='error'):