-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplugin_manager.py
More file actions
109 lines (80 loc) · 2.85 KB
/
plugin_manager.py
File metadata and controls
109 lines (80 loc) · 2.85 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 20 18:39:46 2012
@author: rafik
"""
import os
import inspect
import plugins.helper as h
plugin_dir = 'plugins'
plugin_dir_base = '.'
def get_plugin_tree():
module_list = []
for file in os.listdir(plugin_dir_base+'/'+plugin_dir):
mod_name, mod_ext = os.path.splitext(file)
if (mod_ext in ['.py', '.pyc', '.pyo']
and not mod_name in ['Abstract', 'helper', '__init__']
and not mod_name in module_list):
module_list.append(mod_name)
module_list = set(module_list) #remove dublicates
#print module_list
tree = []
flatlist = []
for mod_name in module_list:
module = __import__(plugin_dir+'.'+mod_name, fromlist=plugin_dir)
classes_of_module = []
for name, obj in inspect.getmembers(module):
if (inspect.isclass(obj)
and issubclass(obj, h.AbstractPlugin)
and hasattr(obj, '__type__')):
# print name
# print ' ',obj
# print ' ',issubclass(obj, h.AbstractPlugin), inspect.isclass(obj)
# print ' ',getattr(obj, '__doc__')
#for i in inspect.getmembers(obj): print i
classes_of_module.append(( name,
obj,
getattr(obj, '__type__'),
getattr(obj, '__doc__')))
flatlist.append((mod_name,
module.__doc__,
name,
obj,
getattr(obj, '__type__'),
getattr(obj, '__doc__')))
if len(classes_of_module)>0:
tree.append([mod_name, module.__doc__, classes_of_module])
return tree
#return flatlist
'''
datastructre of tree:
list with [module_name, module_docsting, list_of_classes]
with list_of_classes as a list of available plugins (surprise..):
[plugin_name, pointer_to_plugin, plugin_type, plugin_docstring]
datastructre of flatlist:
[module_name, module_docstring, plugin_name, pointer_to_plugin, plugin_type, plugin_docstring]
contains an entry for each plugin in a module
'''
def main():
"""this will only be used for debugging..."""
tree = get_plugin_tree()
for i,k, j in tree:
print '\n*',i, k
for jj in j:
print ' -', jj
return
def init_class():
pass
if __name__ == '__main__':
def cmdmain(*args):
try:
main()
except:
# handle general exceptions
raise
else:
return 0 #exit with errorcode 0 = everything ok
#sys.exit(cmdmain(*sys.argv))
cmdmain()
else:
init_class()