blob: 8f9c79da7ffd65850c7971d83c82e2eb4a2601a1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from utils import *
class ModuleManager:
def import_module(self,name):
parts = name.split(".")
try:
obj= sys.modules[name]
except KeyError:
obj = __import__(".".join(parts[:-1]))
if(len(parts)>1):
for part in parts[1:]:
try:
obj = getattr(obj,part)
except:
obj = None
return obj
def getModuleInstance(self,action):
module_name = self.find_module(action)
if(module_name):
try:
return self.import_module(module_name).getInstance()
except:
print dir(self.import_module(module_name))
else:
return None
def find_module(self,action):
try:
return getModulesList()[action]
except:
return None
def getModulesInfoAsHTML(self):
module_dict=getModulesList ()
response = "<h2>Available Modules</h2></hr>"
response = response+"<table class=\"table1\"><tr><th>Module</th><th>Description</th><th>Status</th></tr>"
for action in module_dict:
module_instance=self.getModuleInstance(action)
response = response+"<tr><td><a href='?action="+ action +"'>"+module_instance.get_module_name()+"</a></td>"
response = response+"<td>"+module_instance.get_info()+"</td><td>OK</td></tr>"
return response+"</table>"
if __name__ == '__main__':
mm=ModuleManager()
print mm.getModuleInstance("lemmatize")
print mm.import_module("modules.lemmatizer").getInstance()
|