Plugins management seems ok

This commit is contained in:
Gregory Soutade 2014-11-22 19:23:56 +01:00
parent db84036d8a
commit 38c041126d
3 changed files with 21 additions and 8 deletions

View File

@ -2,11 +2,11 @@
DB_ROOT = './output/' DB_ROOT = './output/'
DISPLAY_ROOT = './output/' DISPLAY_ROOT = './output/'
HOOKS_ROOT = './plugins/' HOOKS_ROOT = 'plugins'
PRE_HOOK_DIRECTORY = HOOKS_ROOT + 'pre_analysis/' PRE_HOOK_DIRECTORY = HOOKS_ROOT + '.pre_analysis'
POST_HOOK_DIRECTORY = HOOKS_ROOT + 'post_analysis/' POST_HOOK_DIRECTORY = HOOKS_ROOT + '.post_analysis'
DISPLAY_HOOK_DIRECTORY = HOOKS_ROOT + 'display/' DISPLAY_HOOK_DIRECTORY = HOOKS_ROOT + '.display'
META_PATH = DB_ROOT + 'meta.db' META_PATH = DB_ROOT + 'meta.db'
DB_FILENAME = 'iwla.db' DB_FILENAME = 'iwla.db'

16
iwla.py
View File

@ -1,5 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys
import os import os
import re import re
import time import time
@ -7,6 +8,7 @@ import glob
import imp import imp
import pickle import pickle
import gzip import gzip
import importlib
from display import * from display import *
@ -41,10 +43,16 @@ class IWLA(object):
ret = True ret = True
for root in self.plugins.keys(): for root in self.plugins.keys():
for plugin_name in self.plugins[root]: for plugin_name in self.plugins[root]:
p = root + '/' + plugin_name #p = root + '/' + plugin_name
p = root + '.' + plugin_name
try: try:
fp, pathname, description = imp.find_module(plugin_name, [root]) # fp, pathname, description = imp.find_module(plugin_name, [root])
self.cache_plugins[p] = imp.load_module(p, fp, pathname, description) # 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] mod = self.cache_plugins[p]
infos = mod.get_plugins_infos() infos = mod.get_plugins_infos()
if infos['class'] != IWLA.ANALYSIS_CLASS or \ if infos['class'] != IWLA.ANALYSIS_CLASS or \
@ -122,7 +130,7 @@ class IWLA(object):
print '==> Call plugins (%s)' % root print '==> Call plugins (%s)' % root
for p in self.plugins[root]: for p in self.plugins[root]:
print '\t%s' % (p) print '\t%s' % (p)
mod = self.cache_plugins[root + '/' + p] mod = self.cache_plugins[root + '.' + p]
mod.hook(*args) mod.hook(*args)
def isPage(self, request): def isPage(self, request):

View File

@ -17,6 +17,11 @@ def load():
def hook(iwla): def hook(iwla):
stats = iwla.getMonthStats() stats = iwla.getMonthStats()
if not 'top_visitors' in stats.keys():
print 'Top visitors post analysis plugin not installed'
return
index = iwla.getDisplayIndex() index = iwla.getDisplayIndex()
table = DisplayHTMLBlockTable('Top visitors', ['Host', 'Pages', 'Hits', 'Bandwidth', 'Last seen']) table = DisplayHTMLBlockTable('Top visitors', ['Host', 'Pages', 'Hits', 'Bandwidth', 'Last seen'])
for super_hit in stats['top_visitors']: for super_hit in stats['top_visitors']: