From 719441cca5a237bde4bbfd01e70bd6ecb7021d30 Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Wed, 20 Apr 2011 09:08:11 +0200 Subject: [PATCH] Make module detection more robust and use it when possible. --- doc/changelog.txt | 4 ++++ linkcheck/checker/urlbase.py | 5 ++--- linkcheck/configuration/__init__.py | 8 ++------ linkcheck/fileutil.py | 3 ++- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/doc/changelog.txt b/doc/changelog.txt index 99d40b77..b65c8842 100644 --- a/doc/changelog.txt +++ b/doc/changelog.txt @@ -1,5 +1,9 @@ 6.8 "" (released xx.xx.2011) +Fixes: +- checking: make module detection more robust + + Changes: - gui: Print detected module information in about dialog. - gui: Close application on Ctrl-C. diff --git a/linkcheck/checker/urlbase.py b/linkcheck/checker/urlbase.py index 159675d4..bb8b24c2 100644 --- a/linkcheck/checker/urlbase.py +++ b/linkcheck/checker/urlbase.py @@ -754,12 +754,11 @@ class UrlBase (object): def check_html (self): """Check HTML syntax of this page (which is supposed to be HTML) with the local HTML tidy module.""" - try: - import tidy - except ImportError: + if not fileutil.has_module("tidy"): log.warn(LOG_CHECK, _("warning: tidy module is not available; " \ "download from http://utidylib.berlios.de/")) return + import tidy options = dict(output_html=0, show_warnings=1, quiet=True, input_encoding='utf8', output_encoding='utf8', tidy_mark=0) try: diff --git a/linkcheck/configuration/__init__.py b/linkcheck/configuration/__init__.py index f7c568b5..d49d3f19 100644 --- a/linkcheck/configuration/__init__.py +++ b/linkcheck/configuration/__init__.py @@ -339,9 +339,7 @@ class Configuration (dict): def sanitize_checkhtml (self): """Ensure HTML tidy is installed for checking HTML.""" - try: - import tidy - except ImportError: + if not fileutil.has_module("tidy"): log.warn(LOG_CHECK, _("warning: tidy module is not available; " \ "download from http://utidylib.berlios.de/")) @@ -349,9 +347,7 @@ class Configuration (dict): def sanitize_checkcss (self): """Ensure cssutils is installed for checking CSS.""" - try: - import cssutils - except ImportError: + if not fileutil.has_module("cssutils"): log.warn(LOG_CHECK, _("warning: cssutils module is not available; " \ "download from http://cthedot.de/cssutils/")) diff --git a/linkcheck/fileutil.py b/linkcheck/fileutil.py index 60cd8afa..e70321d6 100644 --- a/linkcheck/fileutil.py +++ b/linkcheck/fileutil.py @@ -65,7 +65,8 @@ def has_module (name): try: exec "import %s" % name return True - except ImportError: + except (OSError, ImportError): + # some modules (for example HTMLtidy) raise OSError return False