From 37b09d7e1511dce9b8145f5ef34ec00b520263d4 Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Fri, 11 Feb 2011 10:28:48 +0100 Subject: [PATCH] Disable view of parent source if it is a parent directory. --- doc/changelog.txt | 1 + linkcheck/gui/contextmenu.py | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/doc/changelog.txt b/doc/changelog.txt index 8215d25a..14745d8e 100644 --- a/doc/changelog.txt +++ b/doc/changelog.txt @@ -3,6 +3,7 @@ Fixes: - checking: Do not remove CGI parameters when joining URLs. - gui: Remove old context menu action to view URL properties. +- gui: Disable viewing of parent URL source if its a local directory. Changes: - gui: Use Alt-key shortcuts for menu entries. diff --git a/linkcheck/gui/contextmenu.py b/linkcheck/gui/contextmenu.py index fef3fa5d..80397913 100644 --- a/linkcheck/gui/contextmenu.py +++ b/linkcheck/gui/contextmenu.py @@ -15,6 +15,9 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. from PyQt4 import QtGui +import os +import urlparse +from linkcheck.checker.fileurl import get_os_filename class ContextMenu (QtGui.QMenu): """Show context menu.""" @@ -29,22 +32,26 @@ class ContextMenu (QtGui.QMenu): def enableFromItem (self, item): """Enable context menu actions depending on the item content.""" parent = self.parentWidget() + # data is an instance of CompactUrlData data = item.url_data # enable view online actions parent.actionViewOnline.setEnabled(bool(data.url)) parent.actionViewParentOnline.setEnabled(bool(data.parent_url)) # enable view source actions - enable_parent_url_source = self.can_view_source(data.parent_url) + enable_parent_url_source = self.can_view_parent_source(data) parent.actionViewParentSource.setEnabled(enable_parent_url_source) - def can_view_source (self, url, result=None): - """Determine if URL source could be retrieved.""" - if not url: + def can_view_parent_source (self, url_data): + """Determine if parent URL source can be retrieved.""" + if not url_data.valid: return False - if result and result.startswith(u"Error"): + parent = url_data.parent_url + if not parent: return False - return (url.startswith(u"http:") or - url.startswith(u"https:") or - url.startswith(u"ftp:") or - url.startswith(u"ftps:") or - url.startswith(u"file:")) + if parent.startswith(u"file:"): + urlparts = urlparse.urlsplit(parent) + return not os.path.isdir(get_os_filename(urlparts[2])) + return (parent.startswith(u"http:") or + parent.startswith(u"https:") or + parent.startswith(u"ftp:") or + parent.startswith(u"ftps:"))