1
0
mirror of https://github.com/r4sas/py-i2phosts synced 2025-02-02 01:44:40 +00:00

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.
This commit is contained in:
Hidden Z 2010-10-20 17:12:29 +00:00
parent fafa992507
commit 4bd9b7883f

View File

@ -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: