From 4bd9b7883fbe4b158ab5d24b751c570fd0eea642 Mon Sep 17 00:00:00 2001 From: Hidden Z Date: Wed, 20 Oct 2010 17:12:29 +0000 Subject: [PATCH] py-i2phosts-fetcher: use os.path.mtime() for getting mtime This is more efficient way than os.stat because it returns just mtime, not full stat() info. --- py-i2phosts-fetcher | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/py-i2phosts-fetcher b/py-i2phosts-fetcher index 9ebc22a..98445b9 100755 --- a/py-i2phosts-fetcher +++ b/py-i2phosts-fetcher @@ -2,6 +2,7 @@ import re import os +import os.path import sys import errno import time @@ -29,7 +30,7 @@ for source in sources: filename = 'hosts.txt.' + source_hostname # build last-modified info from file mtime try: - statinfo = os.stat(filename) + mtime = os.path.getmtime(filename) except OSError, e: if e.errno == errno.ENOENT: pass @@ -37,7 +38,7 @@ for source in sources: sys.stderr.write('fatal error: %s', e) os.exit(1) else: - last_modified = time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.localtime(statinfo.st_mtime)) + last_modified = time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.localtime(mtime)) # prevent redownloading of hosts-file by passing If-Modified-Since http header opener.addheaders = [('If-Modified-Since', last_modified)] try: