Back to index

python3.2  3.2.2
Functions
distutils.dep_util Namespace Reference

Functions

def newer
def newer_pairwise
def newer_group

Detailed Description

distutils.dep_util

Utility functions for simple, timestamp-based dependency of files
and groups of files; also, function based entirely on such
timestamp dependency analysis.

Function Documentation

def distutils.dep_util.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.

Definition at line 11 of file dep_util.py.

00011 
00012 def newer (source, target):
00013     """Return true if 'source' exists and is more recently modified than
00014     'target', or if 'source' exists and 'target' doesn't.  Return false if
00015     both exist and 'target' is the same age or younger than 'source'.
00016     Raise DistutilsFileError if 'source' does not exist.
00017     """
00018     if not os.path.exists(source):
00019         raise DistutilsFileError("file '%s' does not exist" %
00020                                  os.path.abspath(source))
00021     if not os.path.exists(target):
00022         return 1
00023 
00024     from stat import ST_MTIME
00025     mtime1 = os.stat(source)[ST_MTIME]
00026     mtime2 = os.stat(target)[ST_MTIME]
00027 
00028     return mtime1 > mtime2
00029 
00030 # newer ()
00031 

Here is the caller graph for this function:

def distutils.dep_util.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()';
if it is "ignore", we silently drop any missing source files; if it is
"newer", any missing source files make us assume that 'target' is
out-of-date (this is handy in "dry-run" mode: it'll make you pretend to
carry out commands that wouldn't work because inputs are missing, but
that doesn't matter because you're not actually going to run the
commands).

Definition at line 54 of file dep_util.py.

00054 
00055 def newer_group (sources, target, missing='error'):
00056     """Return true if 'target' is out-of-date with respect to any file
00057     listed in 'sources'.  In other words, if 'target' exists and is newer
00058     than every file in 'sources', return false; otherwise return true.
00059     'missing' controls what we do when a source file is missing; the
00060     default ("error") is to blow up with an OSError from inside 'stat()';
00061     if it is "ignore", we silently drop any missing source files; if it is
00062     "newer", any missing source files make us assume that 'target' is
00063     out-of-date (this is handy in "dry-run" mode: it'll make you pretend to
00064     carry out commands that wouldn't work because inputs are missing, but
00065     that doesn't matter because you're not actually going to run the
00066     commands).
00067     """
00068     # If the target doesn't even exist, then it's definitely out-of-date.
00069     if not os.path.exists(target):
00070         return 1
00071 
00072     # Otherwise we have to find out the hard way: if *any* source file
00073     # is more recent than 'target', then 'target' is out-of-date and
00074     # we can immediately return true.  If we fall through to the end
00075     # of the loop, then 'target' is up-to-date and we return false.
00076     from stat import ST_MTIME
00077     target_mtime = os.stat(target)[ST_MTIME]
00078     for source in sources:
00079         if not os.path.exists(source):
00080             if missing == 'error':      # blow up when we stat() the file
00081                 pass
00082             elif missing == 'ignore':   # missing source dropped from
00083                 continue                #  target's dependency list
00084             elif missing == 'newer':    # missing source means target is
00085                 return 1                #  out-of-date
00086 
00087         source_mtime = os.stat(source)[ST_MTIME]
00088         if source_mtime > target_mtime:
00089             return 1
00090     else:
00091         return 0
00092 
00093 # newer_group ()

Here is the caller graph for this function:

def distutils.dep_util.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
of 'newer()'.

Definition at line 32 of file dep_util.py.

00032 
00033 def newer_pairwise (sources, targets):
00034     """Walk two filename lists in parallel, testing if each source is newer
00035     than its corresponding target.  Return a pair of lists (sources,
00036     targets) where source is newer than target, according to the semantics
00037     of 'newer()'.
00038     """
00039     if len(sources) != len(targets):
00040         raise ValueError("'sources' and 'targets' must be same length")
00041 
00042     # build a pair of lists (sources, targets) where  source is newer
00043     n_sources = []
00044     n_targets = []
00045     for i in range(len(sources)):
00046         if newer(sources[i], targets[i]):
00047             n_sources.append(sources[i])
00048             n_targets.append(targets[i])
00049 
00050     return (n_sources, n_targets)
00051 
00052 # newer_pairwise ()
00053 

Here is the call graph for this function:

Here is the caller graph for this function: