Changeset 391 for python/trunk/Lib/distutils/dep_util.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/distutils/dep_util.py
r2 r391 5 5 timestamp dependency analysis.""" 6 6 7 # This module should be kept compatible with Python 2.1. 8 9 __revision__ = "$Id: dep_util.py 58049 2007-09-08 00:34:17Z skip.montanaro $" 7 __revision__ = "$Id$" 10 8 11 9 import os 10 from stat import ST_MTIME 12 11 from distutils.errors import DistutilsFileError 13 12 13 def newer(source, target): 14 """Tells if the target is newer than the source. 14 15 15 def 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. 16 Return true if 'source' exists and is more recently modified than 17 'target', or if 'source' exists and 'target' doesn't. 18 19 Return false if both exist and 'target' is the same age or younger 20 than 'source'. Raise DistutilsFileError if 'source' does not exist. 21 22 Note that this test is not very accurate: files created in the same second 23 will have the same "age". 20 24 """ 21 25 if not os.path.exists(source): 22 raise DistutilsFileError ,("file '%s' does not exist" %23 26 raise DistutilsFileError("file '%s' does not exist" % 27 os.path.abspath(source)) 24 28 if not os.path.exists(target): 25 return 129 return True 26 30 27 from stat import ST_MTIME 28 mtime1 = os.stat(source)[ST_MTIME] 29 mtime2 = os.stat(target)[ST_MTIME] 31 return os.stat(source)[ST_MTIME] > os.stat(target)[ST_MTIME] 30 32 31 return mtime1 > mtime2 32 33 # newer () 34 35 36 def newer_pairwise (sources, targets): 33 def newer_pairwise(sources, targets): 37 34 """Walk two filename lists in parallel, testing if each source is newer 38 35 than its corresponding target. Return a pair of lists (sources, … … 46 43 n_sources = [] 47 44 n_targets = [] 48 for i in range(len(sources)):49 if newer(source s[i], targets[i]):50 n_sources.append(source s[i])51 n_targets.append(target s[i])45 for source, target in zip(sources, targets): 46 if newer(source, target): 47 n_sources.append(source) 48 n_targets.append(target) 52 49 53 return (n_sources, n_targets)50 return n_sources, n_targets 54 51 55 # newer_pairwise () 52 def newer_group(sources, target, missing='error'): 53 """Return true if 'target' is out-of-date with respect to any file 54 listed in 'sources'. 56 55 57 58 def newer_group (sources, target, missing='error'): 59 """Return true if 'target' is out-of-date with respect to any file 60 listed in 'sources'. In other words, if 'target' exists and is newer 56 In other words, if 'target' exists and is newer 61 57 than every file in 'sources', return false; otherwise return true. 62 58 'missing' controls what we do when a source file is missing; the … … 71 67 # If the target doesn't even exist, then it's definitely out-of-date. 72 68 if not os.path.exists(target): 73 return 169 return True 74 70 75 71 # Otherwise we have to find out the hard way: if *any* source file … … 77 73 # we can immediately return true. If we fall through to the end 78 74 # of the loop, then 'target' is up-to-date and we return false. 79 from stat import ST_MTIME80 75 target_mtime = os.stat(target)[ST_MTIME] 76 81 77 for source in sources: 82 78 if not os.path.exists(source): … … 86 82 continue # target's dependency list 87 83 elif missing == 'newer': # missing source means target is 88 return 1# out-of-date84 return True # out-of-date 89 85 90 source_mtime = os.stat(source)[ST_MTIME] 91 if source_mtime > target_mtime: 92 return 1 93 else: 94 return 0 86 if os.stat(source)[ST_MTIME] > target_mtime: 87 return True 95 88 96 # newer_group () 89 return False
Note:
See TracChangeset
for help on using the changeset viewer.