diff options
author | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2012-06-22 16:46:19 (GMT) |
---|---|---|
committer | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2012-06-22 16:46:19 (GMT) |
commit | a2637729f23dc993e820fd92f0d1759ad714c9b2 (patch) | |
tree | a959f472103499f4e7a5c60def0ae960c846202a /Tools | |
parent | ff493c9c465ba9502629bf5001f690068be97f33 (diff) | |
download | cpython-a2637729f23dc993e820fd92f0d1759ad714c9b2.zip cpython-a2637729f23dc993e820fd92f0d1759ad714c9b2.tar.gz cpython-a2637729f23dc993e820fd92f0d1759ad714c9b2.tar.bz2 |
Issue #7582: Use ISO timestamp in diff.py
Diffstat (limited to 'Tools')
-rwxr-xr-x | Tools/scripts/diff.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/Tools/scripts/diff.py b/Tools/scripts/diff.py index 9efb078..f9b14bf 100755 --- a/Tools/scripts/diff.py +++ b/Tools/scripts/diff.py @@ -9,6 +9,12 @@ """ import sys, os, time, difflib, optparse +from datetime import datetime, timezone + +def file_mtime(path): + t = datetime.fromtimestamp(os.stat(path).st_mtime, + timezone.utc) + return t.astimezone().isoformat() def main(): @@ -30,10 +36,12 @@ def main(): n = options.lines fromfile, tofile = args - fromdate = time.ctime(os.stat(fromfile).st_mtime) - todate = time.ctime(os.stat(tofile).st_mtime) - fromlines = open(fromfile, 'U').readlines() - tolines = open(tofile, 'U').readlines() + fromdate = file_mtime(fromfile) + todate = file_mtime(tofile) + with open(fromfile, 'U') as ff: + fromlines = ff.readlines() + with open(tofile, 'U') as tf: + tolines = tf.readlines() if options.u: diff = difflib.unified_diff(fromlines, tolines, fromfile, tofile, fromdate, todate, n=n) |