summaryrefslogtreecommitdiffstats
path: root/wmd/irc.py
diff options
context:
space:
mode:
Diffstat (limited to 'wmd/irc.py')
-rw-r--r--wmd/irc.py59
1 files changed, 39 insertions, 20 deletions
diff --git a/wmd/irc.py b/wmd/irc.py
index b06cfec..68a5384 100644
--- a/wmd/irc.py
+++ b/wmd/irc.py
@@ -14,6 +14,11 @@ class IRC(object):
14 self.nick = nick 14 self.nick = nick
15 self.name = name 15 self.name = name
16 self.port = port 16 self.port = port
17
18 # the structure
19 # TODO: Refactor
20 # self.actions["module_name"][0]: the actual module. saved to reload if needed
21 # self.actions["module_name"][1]: dictionary. key = class name, value = class object
17 self.actions = dict() 22 self.actions = dict()
18 23
19 self.load_actions() 24 self.load_actions()
@@ -64,10 +69,22 @@ class IRC(object):
64 Loads the provided action 69 Loads the provided action
65 """ 70 """
66 module_name, class_name = path.rsplit('.', 1) 71 module_name, class_name = path.rsplit('.', 1)
67 try: 72
68 module = __import__(module_name, globals(), locals(), [class_name], -1) 73 if self.actions.has_key(module_name):
69 except ImportError: 74 module = self.actions[module_name][0]
70 self.log("Error loading module: %s" %(path,)) 75 else:
76 try:
77 module = __import__(module_name, globals(), locals(), [class_name], -1)
78 except ImportError:
79 self.log("Error loading module: %s" %(path,))
80 return
81
82 if not self.actions.has_key(module_name):
83 self.actions[module_name] = []
84 self.actions[module_name].insert(0, module) # Save the module so it can be reloaded later
85 self.actions[module_name].insert(1, dict())
86 elif class_name in self.actions[module_name][1]:
87 self.log("Class already loaded")
71 return 88 return
72 89
73 try: 90 try:
@@ -76,7 +93,7 @@ class IRC(object):
76 self.log("Class does not exist in module") 93 self.log("Class does not exist in module")
77 return 94 return
78 95
79 self.actions[class_name] = classz() 96 self.actions[module_name][1][class_name] = classz()
80 97
81 def __call__(self, *args, **kwargs): 98 def __call__(self, *args, **kwargs):
82 """ 99 """
@@ -104,18 +121,20 @@ class IRC(object):
104 121
105 modules_to_load = [] 122 modules_to_load = []
106 modules_to_unload = [] 123 modules_to_unload = []
107 for plugin_name in self.actions: 124 for module_name in self.actions:
108 retval = self.actions[plugin_name].recv_msg(self, obj_data) 125 for class_name in self.actions[module_name][1]:
109 if type(retval) == type(dict()): 126 retval = self.actions[module_name][1][class_name].recv_msg(self, obj_data)
110 if retval.has_key('load'): 127
111 modules_to_load.append(retval['load']) 128 if type(retval) == type(dict()):
112 if retval.has_key('unload'): 129 if retval.has_key('load'):
113 modules_to_unload.append(retval['unload']) 130 modules_to_load.append(retval['load'])
114 elif type(retval) == type('str is str'): 131 if retval.has_key('unload'):
115 self.rawsend(retval) 132 modules_to_unload.append(retval['unload'])
116 133 elif type(retval) == type('str is str'):
117 for module in modules_to_load: 134 self.rawsend(retval)
118 self.load_action(module) 135
119 for module in modules_to_unload: 136 for module in modules_to_load:
120 if self.actions.has_key(module): 137 self.load_action(module)
121 del(self.actions[module]) 138 #for module in modules_to_unload:
139 # if self.actions.has_key(module):
140 # del(self.actions[module])