From ee184f86b5afda1a0258c7311108c8d9eaa01f51 Mon Sep 17 00:00:00 2001 From: Gregory Soutade Date: Mon, 6 Apr 2015 17:54:44 +0200 Subject: [PATCH] Add has_subclasses checks for iplugins (prevent for loading parent class) --- iplugin.py | 8 +++++++- plugins/display/feeds.py | 5 +++-- plugins/display/istats_diff.py | 2 +- plugins/display/referers_diff.py | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/iplugin.py b/iplugin.py index 7f57135..a745a53 100644 --- a/iplugin.py +++ b/iplugin.py @@ -79,13 +79,19 @@ def preloadPlugins(plugins, iwla): classes = [c for _,c in inspect.getmembers(mod)\ if inspect.isclass(c) and \ issubclass(c, IPlugin) and \ - c.__name__ != 'IPlugin' + c.__name__ != 'IPlugin' and \ + not c.__subclasses__() ] if not classes: logger.warning('No plugin defined in %s' % (plugin_path)) continue + if len(classes) > 1: + logger.warning('More than one class found in %s, loading may fail. Selecting %s' % (plugin_path, classes[0])) + print classes + continue + plugin = classes[0](iwla) plugin_name = plugin.__class__.__name__ diff --git a/plugins/display/feeds.py b/plugins/display/feeds.py index f8b6e1f..bcd7194 100644 --- a/plugins/display/feeds.py +++ b/plugins/display/feeds.py @@ -21,7 +21,6 @@ from iwla import IWLA from iplugin import IPlugin from display import * -from plugins.post_analysis.feeds import IWLAPostAnalysisFeeds """ Display hook @@ -60,6 +59,8 @@ class IWLADisplayFeeds(IPlugin): return True def hook(self): + from plugins.post_analysis.feeds import IWLAPostAnalysisFeeds + display = self.iwla.getDisplay() hits = self.iwla.getCurrentVisists() nb_feeds_parsers = 0 @@ -88,7 +89,7 @@ class IWLADisplayFeeds(IPlugin): else: table.appendRow([address, super_hit['viewed_pages'], super_hit['viewed_hits']]) page.appendBlock(table) - note = DisplayHTMLRaw(self.iwla, ('*%s' % (self.iwla._('Merged feeds parsers')))) + note = DisplayHTMLRaw(self.iwla, ('*%s' % (self.iwla._(u'Merged feeds parsers')))) page.appendBlock(note) display.addPage(page) diff --git a/plugins/display/istats_diff.py b/plugins/display/istats_diff.py index 897d2c4..333de6d 100644 --- a/plugins/display/istats_diff.py +++ b/plugins/display/istats_diff.py @@ -24,7 +24,7 @@ from display import * import logging """ -Display hook itnerface +Display hook interface Enlight new and updated statistics diff --git a/plugins/display/referers_diff.py b/plugins/display/referers_diff.py index 8e63ecb..2ff505a 100644 --- a/plugins/display/referers_diff.py +++ b/plugins/display/referers_diff.py @@ -53,7 +53,7 @@ class IWLADisplayReferersDiff(IWLADisplayStatsDiff): self.requires = ['IWLADisplayReferers'] self.month_stats_key = 'key_phrases' self.filename = 'key_phrases.html' - self.block_name = u'Key phrases' + self.block_name = self.iwla._(u'Key phrases') def load(self): if not self.iwla.getConfValue('create_all_key_phrases_page', True):