euscan: add an optional persistent cache

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

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'])

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)

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