Browse Source

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.
pull/1/head
Hidden Z 14 years ago
parent
commit
4bd9b7883f
  1. 5
      py-i2phosts-fetcher

5
py-i2phosts-fetcher

@ -2,6 +2,7 @@
import re import re
import os import os
import os.path
import sys import sys
import errno import errno
import time import time
@ -29,7 +30,7 @@ for source in sources:
filename = 'hosts.txt.' + source_hostname filename = 'hosts.txt.' + source_hostname
# build last-modified info from file mtime # build last-modified info from file mtime
try: try:
statinfo = os.stat(filename) mtime = os.path.getmtime(filename)
except OSError, e: except OSError, e:
if e.errno == errno.ENOENT: if e.errno == errno.ENOENT:
pass pass
@ -37,7 +38,7 @@ for source in sources:
sys.stderr.write('fatal error: %s', e) sys.stderr.write('fatal error: %s', e)
os.exit(1) os.exit(1)
else: 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 # prevent redownloading of hosts-file by passing If-Modified-Since http header
opener.addheaders = [('If-Modified-Since', last_modified)] opener.addheaders = [('If-Modified-Since', last_modified)]
try: try:

Loading…
Cancel
Save