diff --git a/linkcheck/Config.py b/linkcheck/Config.py index 3d337ce4..1fcf2fa4 100644 --- a/linkcheck/Config.py +++ b/linkcheck/Config.py @@ -90,6 +90,7 @@ class Configuration(UserDict.UserDict): def reset(self): """Reset to default values""" + self.data['linknumber'] = 0 self.data["verbose"] = 0 self.data["warnings"] = 0 self.data["anchors"] = 0 @@ -180,6 +181,7 @@ class Configuration(UserDict.UserDict): self.robotsTxtCache_get = self.robotsTxtCache_get_NoThreads self.robotsTxtCache_set = self.robotsTxtCache_set_NoThreads self.robotsTxtCacheLock = None + self.incrementLinknumber = self.incrementLinknumber_NoThreads self.log_newUrl = self.log_newUrl_NoThreads self.logLock = None self.urls = [] @@ -208,6 +210,7 @@ class Configuration(UserDict.UserDict): self.robotsTxtCache_get = self.robotsTxtCache_get_Threads self.robotsTxtCache_set = self.robotsTxtCache_set_Threads self.robotsTxtCacheLock = Lock() + self.incrementLinknumber = self.incrementLinknumber_Threads self.log_newUrl = self.log_newUrl_Threads self.logLock = Lock() self.urls = Queue.Queue(0) @@ -254,6 +257,9 @@ class Configuration(UserDict.UserDict): def newLogger(self, name, dict={}): return apply(Loggers[name], (), dictjoin(self.data[name],dict)) + def incrementLinknumber_NoThreads(self): + self.data['linknumber'] = self.data['linknumber'] + 1 + def log_newUrl_NoThreads(self, url): if not self.data["quiet"]: self.data["log"].newUrl(url) for log in self.data["fileoutput"]: @@ -265,9 +271,10 @@ class Configuration(UserDict.UserDict): log.init() def log_endOfOutput(self): - if not self.data["quiet"]: self.data["log"].endOfOutput() + if not self.data["quiet"]: + self.data["log"].endOfOutput(linknumber=self.data['linknumber']) for log in self.data["fileoutput"]: - log.endOfOutput() + log.endOfOutput(linknumber=self.linknumber) def connectNntp_NoThreads(self): if not self.data.has_key("nntp"): @@ -281,6 +288,13 @@ class Configuration(UserDict.UserDict): finally: self.dataLock.release() + def incrementLinknumber_Threads(self): + try: + self.dataLock.acquire() + self.data['linknumber'] = self.data['linknumber'] + 1 + finally: + self.dataLock.release() + def _do_connectNntp(self): """This is done only once per checking task.""" import nntplib diff --git a/linkcheck/Logging.py b/linkcheck/Logging.py index a049de7d..42fdc411 100644 --- a/linkcheck/Logging.py +++ b/linkcheck/Logging.py @@ -76,7 +76,6 @@ class StandardLogger: def __init__(self, **args): self.errors = 0 self.warnings = 0 - self.linknumber = 0 if args.has_key('fileoutput'): self.fd = open(args['filename'], "w") elif args.has_key('fd'): @@ -95,7 +94,6 @@ class StandardLogger: def newUrl(self, urldata): - self.linknumber = self.linknumber+1 self.fd.write("\n"+_("URL")+Spaces["URL"]+urldata.urlName) if urldata.cached: self.fd.write(_(" (cached)\n")) @@ -136,7 +134,7 @@ class StandardLogger: self.fd.flush() - def endOfOutput(self): + def endOfOutput(self, linknumber=-1): self.fd.write(_("\nThats it. ")) if self.warnings==1: @@ -147,10 +145,12 @@ class StandardLogger: self.fd.write(_("1 error")) else: self.fd.write(str(self.errors)+_(" errors")) - if self.linknumber == 1: - self.fd.write(_(" in 1 link found\n")) - else: - self.fd.write(_(" in %d links found\n") % self.linknumber) + if linknumber >= 0: + if linknumber == 1: + self.fd.write(_(" in 1 link")) + else: + self.fd.write(_(" in %d links") % linknumber) + self.fd.write(_(" found\n")) self.stoptime = time.time() duration = self.stoptime - self.starttime name = _("seconds") @@ -194,7 +194,6 @@ class HtmlLogger(StandardLogger): def newUrl(self, urlData): - self.linknumber = self.linknumber+1 self.fd.write("