From 38c041126d1b1604ec47b64c5591b92a69e121b6 Mon Sep 17 00:00:00 2001 From: Gregory Soutade Date: Sat, 22 Nov 2014 19:23:56 +0100 Subject: [PATCH] Plugins management seems ok --- default_conf.py | 8 ++++---- iwla.py | 16 ++++++++++++---- plugins/display/top_visitors.py | 5 +++++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/default_conf.py b/default_conf.py index 9faf4e9..074a9e6 100644 --- a/default_conf.py +++ b/default_conf.py @@ -2,11 +2,11 @@ DB_ROOT = './output/' DISPLAY_ROOT = './output/' -HOOKS_ROOT = './plugins/' +HOOKS_ROOT = 'plugins' -PRE_HOOK_DIRECTORY = HOOKS_ROOT + 'pre_analysis/' -POST_HOOK_DIRECTORY = HOOKS_ROOT + 'post_analysis/' -DISPLAY_HOOK_DIRECTORY = HOOKS_ROOT + 'display/' +PRE_HOOK_DIRECTORY = HOOKS_ROOT + '.pre_analysis' +POST_HOOK_DIRECTORY = HOOKS_ROOT + '.post_analysis' +DISPLAY_HOOK_DIRECTORY = HOOKS_ROOT + '.display' META_PATH = DB_ROOT + 'meta.db' DB_FILENAME = 'iwla.db' diff --git a/iwla.py b/iwla.py index e8a93d7..af8d705 100755 --- a/iwla.py +++ b/iwla.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +import sys import os import re import time @@ -7,6 +8,7 @@ import glob import imp import pickle import gzip +import importlib from display import * @@ -41,10 +43,16 @@ class IWLA(object): ret = True for root in self.plugins.keys(): for plugin_name in self.plugins[root]: - p = root + '/' + plugin_name + #p = root + '/' + plugin_name + p = root + '.' + plugin_name try: - fp, pathname, description = imp.find_module(plugin_name, [root]) - self.cache_plugins[p] = imp.load_module(p, fp, pathname, description) + # fp, pathname, description = imp.find_module(plugin_name, [root]) + # self.cache_plugins[p] = imp.load_module(p, fp, pathname, description) + #p = 'plugins.display.top_visitors' + #sys.path.append(root) + #self.cache_plugins[p] = importlib.import_module(plugin_name, root) + #sys.path.remove(root) + self.cache_plugins[p] = importlib.import_module(p) mod = self.cache_plugins[p] infos = mod.get_plugins_infos() if infos['class'] != IWLA.ANALYSIS_CLASS or \ @@ -122,7 +130,7 @@ class IWLA(object): print '==> Call plugins (%s)' % root for p in self.plugins[root]: print '\t%s' % (p) - mod = self.cache_plugins[root + '/' + p] + mod = self.cache_plugins[root + '.' + p] mod.hook(*args) def isPage(self, request): diff --git a/plugins/display/top_visitors.py b/plugins/display/top_visitors.py index f058a79..c4db4f8 100644 --- a/plugins/display/top_visitors.py +++ b/plugins/display/top_visitors.py @@ -17,6 +17,11 @@ def load(): def hook(iwla): stats = iwla.getMonthStats() + + if not 'top_visitors' in stats.keys(): + print 'Top visitors post analysis plugin not installed' + return + index = iwla.getDisplayIndex() table = DisplayHTMLBlockTable('Top visitors', ['Host', 'Pages', 'Hits', 'Bandwidth', 'Last seen']) for super_hit in stats['top_visitors']: