+++ /dev/null
-"""distutils.dep_util\r
-\r
-Utility functions for simple, timestamp-based dependency of files\r
-and groups of files; also, function based entirely on such\r
-timestamp dependency analysis."""\r
-\r
-__revision__ = "$Id$"\r
-\r
-import os\r
-from distutils.errors import DistutilsFileError\r
-\r
-def newer(source, target):\r
- """Tells if the target is newer than the source.\r
-\r
- Return true if 'source' exists and is more recently modified than\r
- 'target', or if 'source' exists and 'target' doesn't.\r
-\r
- Return false if both exist and 'target' is the same age or younger\r
- than 'source'. Raise DistutilsFileError if 'source' does not exist.\r
-\r
- Note that this test is not very accurate: files created in the same second\r
- will have the same "age".\r
- """\r
- if not os.path.exists(source):\r
- raise DistutilsFileError("file '%s' does not exist" %\r
- os.path.abspath(source))\r
- if not os.path.exists(target):\r
- return True\r
-\r
- return os.stat(source).st_mtime > os.stat(target).st_mtime\r
-\r
-def newer_pairwise(sources, targets):\r
- """Walk two filename lists in parallel, testing if each source is newer\r
- than its corresponding target. Return a pair of lists (sources,\r
- targets) where source is newer than target, according to the semantics\r
- of 'newer()'.\r
- """\r
- if len(sources) != len(targets):\r
- raise ValueError, "'sources' and 'targets' must be same length"\r
-\r
- # build a pair of lists (sources, targets) where source is newer\r
- n_sources = []\r
- n_targets = []\r
- for source, target in zip(sources, targets):\r
- if newer(source, target):\r
- n_sources.append(source)\r
- n_targets.append(target)\r
-\r
- return n_sources, n_targets\r
-\r
-def newer_group(sources, target, missing='error'):\r
- """Return true if 'target' is out-of-date with respect to any file\r
- listed in 'sources'.\r
-\r
- In other words, if 'target' exists and is newer\r
- than every file in 'sources', return false; otherwise return true.\r
- 'missing' controls what we do when a source file is missing; the\r
- default ("error") is to blow up with an OSError from inside 'stat()';\r
- if it is "ignore", we silently drop any missing source files; if it is\r
- "newer", any missing source files make us assume that 'target' is\r
- out-of-date (this is handy in "dry-run" mode: it'll make you pretend to\r
- carry out commands that wouldn't work because inputs are missing, but\r
- that doesn't matter because you're not actually going to run the\r
- commands).\r
- """\r
- # If the target doesn't even exist, then it's definitely out-of-date.\r
- if not os.path.exists(target):\r
- return True\r
-\r
- # Otherwise we have to find out the hard way: if *any* source file\r
- # is more recent than 'target', then 'target' is out-of-date and\r
- # we can immediately return true. If we fall through to the end\r
- # of the loop, then 'target' is up-to-date and we return false.\r
- target_mtime = os.stat(target).st_mtime\r
-\r
- for source in sources:\r
- if not os.path.exists(source):\r
- if missing == 'error': # blow up when we stat() the file\r
- pass\r
- elif missing == 'ignore': # missing source dropped from\r
- continue # target's dependency list\r
- elif missing == 'newer': # missing source means target is\r
- return True # out-of-date\r
-\r
- if os.stat(source).st_mtime > target_mtime:\r
- return True\r
-\r
- return False\r