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.
(source, target)
| 9 | |
| 10 | |
| 11 | def newer (source, target): |
| 12 | """Return true if 'source' exists and is more recently modified than |
| 13 | 'target', or if 'source' exists and 'target' doesn't. Return false if |
| 14 | both exist and 'target' is the same age or younger than 'source'. |
| 15 | Raise DistutilsFileError if 'source' does not exist. |
| 16 | """ |
| 17 | if not os.path.exists(source): |
| 18 | raise DistutilsFileError("file '%s' does not exist" % |
| 19 | os.path.abspath(source)) |
| 20 | if not os.path.exists(target): |
| 21 | return 1 |
| 22 | |
| 23 | from stat import ST_MTIME |
| 24 | mtime1 = os.stat(source)[ST_MTIME] |
| 25 | mtime2 = os.stat(target)[ST_MTIME] |
| 26 | |
| 27 | return mtime1 > mtime2 |
| 28 | |
| 29 | # newer () |
| 30 |