new consumer interface

git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@1434 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
calvin 2004-08-19 21:36:17 +00:00
parent a66a8359d1
commit c3100ef518
5 changed files with 36 additions and 26 deletions

View file

@ -22,8 +22,6 @@ import time
from linkcheck.i18n import _
import httplib2, ftests
# logger areas
LOG = "linkcheck"
LOG_CMDLINE = "linkcheck.cmdline"
@ -84,3 +82,4 @@ Loggers = {
}
# for easy printing: a comma separated logger list
LoggerKeys = ", ".join(["%r"%name for name in Loggers.keys()])

View file

@ -20,7 +20,10 @@ import os
import unittest
import difflib
import linkcheck
import linkcheck.checker
import linkcheck.checker.cache
import linkcheck.checker.consumer
import linkcheck.configuration
import linkcheck.logger
@ -68,7 +71,7 @@ class TestLogger (linkcheck.logger.Logger):
self.diff.append(line)
def get_test_config (confargs, logargs):
def get_test_consumer (confargs, logargs):
"""initialize a test configuration object"""
config = linkcheck.configuration.Configuration()
config.logger_add('test', TestLogger)
@ -76,10 +79,11 @@ def get_test_config (confargs, logargs):
config['logger'] = config.logger_new('test', **logargs)
config["anchors"] = True
config["verbose"] = True
config.set_threads(0)
config['threads'] = 0
for key, value in confargs.items():
config[key] = value
return config
cache = linkcheck.checker.cache.Cache()
return linkcheck.checker.consumer.Consumer(config, cache)
class StandardTest (unittest.TestCase, object):
@ -107,11 +111,12 @@ class StandardTest (unittest.TestCase, object):
url = self.get_file(filename)
confargs = {}
logargs = {'expected': self.get_resultlines(filename)}
config = get_test_config(confargs, logargs)
config.append_url(linkcheck.checker.get_url_from(url, 0, config))
linkcheck.checker.check_urls(config)
if config['logger'].diff:
self.fail(os.linesep.join([url] + config['logger'].diff))
consumer = get_test_consumer(confargs, logargs)
url_data = linkcheck.checker.get_url_from(url, 0, consumer)
consumer.append_url(url_data)
linkcheck.checker.check_urls(consumer)
if consumer.config['logger'].diff:
self.fail(os.linesep.join([url] + consumer.config['logger'].diff))
def direct (self, url, resultlines, fields=None, recursionlevel=0):
"""check url with expected result"""
@ -119,8 +124,10 @@ class StandardTest (unittest.TestCase, object):
logargs = {'expected': resultlines}
if fields is not None:
logargs['fields'] = fields
config = get_test_config(confargs, logargs)
config.append_url(linkcheck.checker.get_url_from(url, 0, config))
linkcheck.checker.check_urls(config)
if config['logger'].diff:
self.fail(os.linesep.join([url]+config['logger'].diff))
consumer = get_test_consumer(confargs, logargs)
url_data = linkcheck.checker.get_url_from(url, 0, consumer)
consumer.append_url(url_data)
linkcheck.checker.check_urls(consumer)
if consumer.config['logger'].diff:
self.fail(os.linesep.join([url] + consumer.config['logger'].diff))

View file

@ -64,8 +64,7 @@ class ColoredLogger (linkcheck.logger.standard.StandardLogger):
self.fd.write("o"+os.linesep)
self.fd.write(os.linesep+self.field("parenturl")+
self.spaces("parenturl")+
self.colorparent+
(url_data.parent_url or "")+
self.colorparent+url_data.parent_url+
self.colorreset+os.linesep)
self.currentPage = url_data.parent_url
self.prefix = 1
@ -80,7 +79,7 @@ class ColoredLogger (linkcheck.logger.standard.StandardLogger):
else:
self.fd.write(os.linesep)
self.fd.write(self.field("url")+self.spaces("url")+self.colorurl+
url_data.base_url+self.colorreset)
repr(url_data.base_url)+self.colorreset)
if url_data.line:
self.fd.write(_(", line %d")%url_data.line)
if url_data.column:
@ -94,7 +93,7 @@ class ColoredLogger (linkcheck.logger.standard.StandardLogger):
if self.prefix:
self.fd.write("| ")
self.fd.write(self.field("name")+self.spaces("name")+
self.colorname+url_data.name+self.colorreset+
self.colorname+repr(url_data.name)+self.colorreset+
os.linesep)
if url_data.base_ref and self.has_field("base"):
if self.prefix:

View file

@ -102,22 +102,22 @@ class StandardLogger (linkcheck.logger.Logger):
return
if self.has_field('url'):
self.fd.write(os.linesep+self.field('url')+self.spaces('url')+
url_data.base_url)
repr(url_data.base_url))
if url_data.cached:
self.fd.write(_(" (cached)")+os.linesep)
else:
self.fd.write(os.linesep)
if url_data.name and self.has_field('name'):
self.fd.write(self.field("name")+self.spaces("name")+
url_data.name+os.linesep)
repr(url_data.name)+os.linesep)
if url_data.parent_url and self.has_field('parenturl'):
self.fd.write(self.field('parenturl')+self.spaces("parenturl")+
(url_data.parent_url or "")+
url_data.parent_url+
(_(", line %d")%url_data.line)+
(_(", col %d")%url_data.column)+os.linesep)
if url_data.base_ref and self.has_field('base'):
self.fd.write(self.field("base")+self.spaces("base")+
url_data.base_ref+os.linesep)
repr(url_data.base_ref)+os.linesep)
if url_data.url and self.has_field('realurl'):
self.fd.write(self.field("realurl")+self.spaces("realurl")+
url_data.url+os.linesep)

View file

@ -38,6 +38,8 @@ import linkcheck
import linkcheck.log
import linkcheck.optcomplete
import linkcheck.checker
import linkcheck.checker.cache
import linkcheck.checker.consumer
import linkcheck.configuration
from linkcheck.i18n import _
@ -473,18 +475,21 @@ if len(args)==0:
else:
linkcheck.log.warn(linkcheck.LOG_CMDLINE, _("no files or urls given"))
cache = linkcheck.checker.cache.Cache()
consumer = linkcheck.checker.consumer.Consumer(config, cache)
# syntactic sugar
for url in args:
if url.startswith("www."):
url = "http://%s"%url
elif url.startswith("ftp."):
url = "ftp://%s"%url
config.append_url(linkcheck.checker.get_url_from(url, 0, config, cmdline=True))
url_data = linkcheck.checker.get_url_from(url, 0, consumer, cmdline=True)
consumer.append_url(url_data)
############################# check the urls ################################
if do_profile:
import profile
profile.run("linkcheck.checker.check_urls(config)", _profile)
profile.run("linkcheck.checker.check_urls(consumer)", _profile)
else:
# do not use psyco, at the moment (Oct 2003) it has bugs causing
# infinite loops when threads are enabled, and psyco disables
@ -494,7 +499,7 @@ else:
# psyco.full()
#except ImportError:
# pass
linkcheck.checker.check_urls(config)
linkcheck.checker.check_urls(consumer)
#############################################################################
# interactive input end