diff options
author | Tarek Ziadé <ziade.tarek@gmail.com> | 2010-07-22 12:50:05 (GMT) |
---|---|---|
committer | Tarek Ziadé <ziade.tarek@gmail.com> | 2010-07-22 12:50:05 (GMT) |
commit | 3679727939a9d25ccfe057e71e8a4b8be73d47ce (patch) | |
tree | 88326b8ec80cf57f51d2e093143e233ec4ce1be5 /Lib/distutils/dep_util.py | |
parent | 5db0c94072abad10c9d2df99eefd1f51eb84f2bc (diff) | |
download | cpython-3679727939a9d25ccfe057e71e8a4b8be73d47ce.zip cpython-3679727939a9d25ccfe057e71e8a4b8be73d47ce.tar.gz cpython-3679727939a9d25ccfe057e71e8a4b8be73d47ce.tar.bz2 |
reverted distutils its 3.1 state. All new work is now happening in disutils2, and distutils is now feature-frozen.
Diffstat (limited to 'Lib/distutils/dep_util.py')
-rw-r--r-- | Lib/distutils/dep_util.py | 64 |
1 files changed, 35 insertions, 29 deletions
diff --git a/Lib/distutils/dep_util.py b/Lib/distutils/dep_util.py index b91a62e..07b3549 100644 --- a/Lib/distutils/dep_util.py +++ b/Lib/distutils/dep_util.py @@ -9,27 +9,29 @@ __revision__ = "$Id$" import os from distutils.errors import DistutilsFileError -def newer(source, target): - """Tells if the target is newer than the source. - Return true if 'source' exists and is more recently modified than - 'target', or if 'source' exists and 'target' doesn't. - - Return false if both exist and 'target' is the same age or younger - than 'source'. Raise DistutilsFileError if 'source' does not exist. - - Note that this test is not very accurate: files created in the same second - will have the same "age". +def newer (source, target): + """Return true if 'source' exists and is more recently modified than + 'target', or if 'source' exists and 'target' doesn't. Return false if + both exist and 'target' is the same age or younger than 'source'. + Raise DistutilsFileError if 'source' does not exist. """ if not os.path.exists(source): raise DistutilsFileError("file '%s' does not exist" % os.path.abspath(source)) if not os.path.exists(target): - return True + return 1 + + from stat import ST_MTIME + mtime1 = os.stat(source)[ST_MTIME] + mtime2 = os.stat(target)[ST_MTIME] + + return mtime1 > mtime2 + +# newer () - return os.stat(source).st_mtime > os.stat(target).st_mtime -def newer_pairwise(sources, targets): +def newer_pairwise (sources, targets): """Walk two filename lists in parallel, testing if each source is newer than its corresponding target. Return a pair of lists (sources, targets) where source is newer than target, according to the semantics @@ -41,18 +43,19 @@ def newer_pairwise(sources, targets): # build a pair of lists (sources, targets) where source is newer n_sources = [] n_targets = [] - for source, target in zip(sources, targets): - if newer(source, target): - n_sources.append(source) - n_targets.append(target) + for i in range(len(sources)): + if newer(sources[i], targets[i]): + n_sources.append(sources[i]) + n_targets.append(targets[i]) - return n_sources, n_targets + return (n_sources, n_targets) + +# newer_pairwise () -def newer_group(sources, target, missing='error'): - """Return true if 'target' is out-of-date with respect to any file - listed in 'sources'. - In other words, if 'target' exists and is newer +def newer_group (sources, target, missing='error'): + """Return true if 'target' is out-of-date with respect to any file + listed in 'sources'. In other words, if 'target' exists and is newer than every file in 'sources', return false; otherwise return true. 'missing' controls what we do when a source file is missing; the default ("error") is to blow up with an OSError from inside 'stat()'; @@ -65,14 +68,14 @@ def newer_group(sources, target, missing='error'): """ # If the target doesn't even exist, then it's definitely out-of-date. if not os.path.exists(target): - return True + return 1 # Otherwise we have to find out the hard way: if *any* source file # is more recent than 'target', then 'target' is out-of-date and # we can immediately return true. If we fall through to the end # of the loop, then 'target' is up-to-date and we return false. - target_mtime = os.stat(target).st_mtime - + from stat import ST_MTIME + target_mtime = os.stat(target)[ST_MTIME] for source in sources: if not os.path.exists(source): if missing == 'error': # blow up when we stat() the file @@ -80,9 +83,12 @@ def newer_group(sources, target, missing='error'): elif missing == 'ignore': # missing source dropped from continue # target's dependency list elif missing == 'newer': # missing source means target is - return True # out-of-date + return 1 # out-of-date - if os.stat(source).st_mtime > target_mtime: - return True + source_mtime = os.stat(source)[ST_MTIME] + if source_mtime > target_mtime: + return 1 + else: + return 0 - return False +# newer_group () |