Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/distutils/dep_util.py

    r2 r391  
    55timestamp dependency analysis."""
    66
    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$"
    108
    119import os
     10from stat import ST_MTIME
    1211from distutils.errors import DistutilsFileError
    1312
     13def newer(source, target):
     14    """Tells if the target is newer than the source.
    1415
    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".
    2024    """
    2125    if not os.path.exists(source):
    22         raise DistutilsFileError, ("file '%s' does not exist" %
    23                                    os.path.abspath(source))
     26        raise DistutilsFileError("file '%s' does not exist" %
     27                                 os.path.abspath(source))
    2428    if not os.path.exists(target):
    25         return 1
     29        return True
    2630
    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]
    3032
    31     return mtime1 > mtime2
    32 
    33 # newer ()
    34 
    35 
    36 def newer_pairwise (sources, targets):
     33def newer_pairwise(sources, targets):
    3734    """Walk two filename lists in parallel, testing if each source is newer
    3835    than its corresponding target.  Return a pair of lists (sources,
     
    4643    n_sources = []
    4744    n_targets = []
    48     for i in range(len(sources)):
    49         if newer(sources[i], targets[i]):
    50             n_sources.append(sources[i])
    51             n_targets.append(targets[i])
     45    for source, target in zip(sources, targets):
     46        if newer(source, target):
     47            n_sources.append(source)
     48            n_targets.append(target)
    5249
    53     return (n_sources, n_targets)
     50    return n_sources, n_targets
    5451
    55 # newer_pairwise ()
     52def newer_group(sources, target, missing='error'):
     53    """Return true if 'target' is out-of-date with respect to any file
     54    listed in 'sources'.
    5655
    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
    6157    than every file in 'sources', return false; otherwise return true.
    6258    'missing' controls what we do when a source file is missing; the
     
    7167    # If the target doesn't even exist, then it's definitely out-of-date.
    7268    if not os.path.exists(target):
    73         return 1
     69        return True
    7470
    7571    # Otherwise we have to find out the hard way: if *any* source file
     
    7773    # we can immediately return true.  If we fall through to the end
    7874    # of the loop, then 'target' is up-to-date and we return false.
    79     from stat import ST_MTIME
    8075    target_mtime = os.stat(target)[ST_MTIME]
     76
    8177    for source in sources:
    8278        if not os.path.exists(source):
     
    8682                continue                #  target's dependency list
    8783            elif missing == 'newer':    # missing source means target is
    88                 return 1                #  out-of-date
     84                return True             #  out-of-date
    8985
    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
    9588
    96 # newer_group ()
     89    return False
Note: See TracChangeset for help on using the changeset viewer.