From 8ef297990550fff2ba1eedc4bd2f2ed197eae266 Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Mon, 11 Oct 2010 23:50:59 +0200 Subject: [PATCH] Refactor configuration.sanitize() function. --- linkcheck/configuration/__init__.py | 70 ++++++++++++++++++----------- 1 file changed, 45 insertions(+), 25 deletions(-) diff --git a/linkcheck/configuration/__init__.py b/linkcheck/configuration/__init__.py index 65b449be..9dec8250 100644 --- a/linkcheck/configuration/__init__.py +++ b/linkcheck/configuration/__init__.py @@ -249,34 +249,54 @@ class Configuration (dict): def sanitize (self): "Make sure the configuration is consistent." if self["anchors"]: - if not self["warnings"]: - self["warnings"] = True - from ..checker import Warnings - self["ignorewarnings"] = Warnings.keys() - if 'url-anchor-not-found' in self["ignorewarnings"]: - self["ignorewarnings"].remove('url-anchor-not-found') - self['logger'] = self.logger_new(self['output']) + self.sanitize_anchors() + if self['logger'] is None: + self.sanitize_logger() if self['checkhtml']: - try: - import tidy - except ImportError: - log.warn(LOG_CHECK, - _("warning: tidy module is not available; " \ - "download from http://utidylib.berlios.de/")) - self['checkhtml'] = False + self.sanitize_checkhtml() if self['checkcss']: - try: - import cssutils - except ImportError: - log.warn(LOG_CHECK, - _("warning: cssutils module is not available; " \ - "download from http://cthedot.de/cssutils/")) - self['checkcss'] = False + self.sanitize_checkcss() if self['scanvirus']: - try: - clamav.init_clamav_conf(self['clamavconf']) - except clamav.ClamavError: - self['scanvirus'] = False + self.sanitize_scanvirus() + + def sanitize_anchors (self): + if not self["warnings"]: + self["warnings"] = True + from ..checker import Warnings + self["ignorewarnings"] = Warnings.keys() + if 'url-anchor-not-found' in self["ignorewarnings"]: + self["ignorewarnings"].remove('url-anchor-not-found') + + def sanitize_logger (self): + if not self['output']: + self['output'] = 'text' + self['logger'] = self.logger_new(self['output']) + + def sanitize_checkhtml (self): + try: + import tidy + except ImportError: + log.warn(LOG_CHECK, + _("warning: tidy module is not available; " \ + "download from http://utidylib.berlios.de/")) + self['checkhtml'] = False + + def sanitize_checkcss (self): + try: + import cssutils + except ImportError: + log.warn(LOG_CHECK, + _("warning: cssutils module is not available; " \ + "download from http://cthedot.de/cssutils/")) + self['checkcss'] = False + + def sanitize_scanvirus (self): + try: + clamav.init_clamav_conf(self['clamavconf']) + except clamav.ClamavError: + log.warn(LOG_CHECK, + _("warning: Clamav could not be initialized")) + self['scanvirus'] = False def copy_sys_config (syspath, userpath):