diff --git a/Makefile b/Makefile index 4f15e893..a5a160e1 100644 --- a/Makefile +++ b/Makefile @@ -120,7 +120,8 @@ check: doccheck: py-check-docstrings --force linkcheck/HtmlParser linkcheck/checker \ linkcheck/cache linkcheck/configuration linkcheck/director \ - linkcheck/htmlutil linkcheck/logger linkcheck/network *.py + linkcheck/htmlutil linkcheck/logger linkcheck/network \ + linkcheck/bookmarks *.py filescheck: -./linkchecker $(LCOPTS) http://$(HOST)/ diff --git a/linkcheck/bookmarks/__init__.py b/linkcheck/bookmarks/__init__.py new file mode 100644 index 00000000..067bb316 --- /dev/null +++ b/linkcheck/bookmarks/__init__.py @@ -0,0 +1,16 @@ +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2011 Bastian Kleineidam +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. diff --git a/linkcheck/firefox.py b/linkcheck/bookmarks/firefox.py similarity index 100% rename from linkcheck/firefox.py rename to linkcheck/bookmarks/firefox.py diff --git a/linkcheck/bookmarks/opera.py b/linkcheck/bookmarks/opera.py new file mode 100644 index 00000000..35c466f4 --- /dev/null +++ b/linkcheck/bookmarks/opera.py @@ -0,0 +1,35 @@ +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2011 Bastian Kleineidam +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + +def parse_bookmarks (data): + """Return iterator for bookmarks of the form (url, name, line number). + Bookmarks are not sorted. + """ + name = None + lineno = 0 + for line in data.splitlines(): + lineno += 1 + line = line.strip() + if line.startswith("NAME="): + name = line[5:] + elif line.startswith("URL="): + url = line[4:] + if url and name is not None: + yield (url, name, lineno) + else: + name = None diff --git a/linkcheck/checker/fileurl.py b/linkcheck/checker/fileurl.py index 4c9233cc..6584beab 100644 --- a/linkcheck/checker/fileurl.py +++ b/linkcheck/checker/fileurl.py @@ -25,7 +25,8 @@ import urllib import urllib2 from . import urlbase, get_index_html, get_url_from -from .. import log, LOG_CHECK, fileutil, firefox +from .. import log, LOG_CHECK, fileutil +from ..bookmarks import firefox from .const import WARN_FILE_MISSING_SLASH, WARN_FILE_SYSTEM_PATH diff --git a/linkcheck/checker/urlbase.py b/linkcheck/checker/urlbase.py index 1eb89589..9c393244 100644 --- a/linkcheck/checker/urlbase.py +++ b/linkcheck/checker/urlbase.py @@ -924,22 +924,11 @@ class UrlBase (object): def parse_opera (self): """Parse an opera bookmark file.""" log.debug(LOG_CHECK, "Parsing Opera bookmarks %s", self) - name = None - lineno = 0 - for line in self.get_content().splitlines(): - lineno += 1 - line = line.strip() - if line.startswith("NAME="): - name = line[5:] - elif line.startswith("URL="): - url = line[4:] - if url and name is not None: - url_data = get_url_from(url, self.recursion_level+1, - self.aggregate, parent_url=self.url, - line=lineno, name=name) - self.aggregate.urlqueue.put(url_data) - else: - name = None + from ..bookmarks.opera import parse_bookmarks + for url, name, lineno in parse_bookmarks(self.get_content()): + url_data = get_url_from(url, self.recursion_level+1, + self.aggregate, parent_url=self.url, line=lineno, name=name) + self.aggregate.urlqueue.put(url_data) def parse_text (self): """ diff --git a/linkcheck/gui/lineedit.py b/linkcheck/gui/lineedit.py index 886e8a87..eeada165 100644 --- a/linkcheck/gui/lineedit.py +++ b/linkcheck/gui/lineedit.py @@ -63,8 +63,7 @@ class LineEdit (QtGui.QLineEdit): def add_firefox (self): """Copy Firefox bookmark file URL.""" - from ..firefox import find_bookmark_file + from ..bookmarks.firefox import find_bookmark_file fname = find_bookmark_file() if fname: self.setText(fname) - diff --git a/setup.py b/setup.py index 8f196de8..6901f607 100755 --- a/setup.py +++ b/setup.py @@ -562,6 +562,7 @@ o a (Fast)CGI web interface (requires HTTP server) 'linkcheck.htmlutil', 'linkcheck.dns', 'linkcheck.dns.rdtypes', 'linkcheck.dns.rdtypes.ANY', 'linkcheck.dns.rdtypes.IN', 'linkcheck.HtmlParser', 'linkcheck.network', 'linkcheck.gui', + 'linkcheck.bookmarks', ], ext_modules = [ Extension('linkcheck.HtmlParser.htmlsax',