euscan: add an optional persistent cache

Signed-off-by: Corentin Chary <corentincj@iksaif.net>
This commit is contained in:
Corentin Chary committed 2011-10-02 10:04:44 +02:00
1 parent 7f56dd4ac4
commit d7f655cdde
3 files changed
+10 -4

No files matched your search

+2 -1
View File
@@ -20,7 +20,8 @@ CONFIG = {
'scan-dir': True, 'scan-dir': True,
'oneshot': False, 'oneshot': False,
'user-agent' : 'escan (http://euscan.iksaif.net)', 'user-agent' : 'escan (http://euscan.iksaif.net)',
'skip-robots-txt' : False 'skip-robots-txt' : False,
'cache' : False
} }
output = EOutput(CONFIG['quiet']) output = EOutput(CONFIG['quiet'])
+7 -3
View File
@@ -267,11 +267,15 @@ def urlopen(url, timeout=None, verb="GET"):
request.add_header('User-Agent', CONFIG['user-agent']) request.add_header('User-Agent', CONFIG['user-agent'])
handlers = []
if CONFIG['cache']:
from cache import CacheHandler
handlers.append(CacheHandler(CONFIG['cache']))
if CONFIG['verbose']: if CONFIG['verbose']:
debuglevel = CONFIG['verbose'] - 1 debuglevel = CONFIG['verbose'] - 1
handlers = [urllib2.HTTPHandler(debuglevel=debuglevel)] handlers.append(urllib2.HTTPHandler(debuglevel=debuglevel))
else:
handlers = []
opener = urllib2.build_opener(*handlers) opener = urllib2.build_opener(*handlers)
+1
View File
@@ -20,6 +20,7 @@ def filter_versions(cp, versions):
for url, version in versions: for url, version in versions:
''' Try to keep the most specific urls (determinted by the length) ''' ''' Try to keep the most specific urls (determinted by the length) '''
if version in filtered and len(url) < len(filtered[version]): if version in filtered and len(url) < len(filtered[version]):
continue continue