[Python-checkins] cpython: Issue #7582: Use ISO timestamp in diff.py

alexander.belopolsky python-checkins at python.org
Fri Jun 22 18:48:29 CEST 2012


http://hg.python.org/cpython/rev/ec95b94ea831
changeset:   77572:ec95b94ea831
parent:      77570:336c53c1f547
user:        Alexander Belopolsky <alexander.belopolsky at gmail.com>
date:        Fri Jun 22 12:46:19 2012 -0400
summary:
  Issue #7582: Use ISO timestamp in diff.py

files:
  Tools/scripts/diff.py |  16 ++++++++++++----
  1 files changed, 12 insertions(+), 4 deletions(-)


diff --git a/Tools/scripts/diff.py b/Tools/scripts/diff.py
--- 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 @@
     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)

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list