diff --git a/Module.py b/Module.py index 3270eb7..19757d0 100644 --- a/Module.py +++ b/Module.py @@ -205,23 +205,6 @@ class Module(object): except Exception as e: print('EXCEPTION: ' + str(e)) - def reload(self): - """Reload this module's code and then create a new object of it, removing the old.""" - - # re-read and re-compile module from source on disk - reload(sys.modules[self.__module__]) - - # find the class declaration for the current module - for name, obj in inspect.getmembers(sys.modules[self.__module__]): - if inspect.isclass(obj) and str(obj).find(self.__module__) > 0: - # remove existing object from in-memory stuff - self.modlist.remove(self) - self.unregister_handlers() - - # create new object, like how we did initially - obj(self.config, self.server, self.modlist) - self.register_handlers(self.server) - def reply(self, connection, replypath, replystr): """ Reply over IRC to replypath or return a string with the reply. diff --git a/modules/IrcAdmin.py b/modules/IrcAdmin.py index e205c21..5c0b09d 100644 --- a/modules/IrcAdmin.py +++ b/modules/IrcAdmin.py @@ -188,39 +188,47 @@ class IrcAdmin(Module): except ImportError: return self.reply(connection, replypath, 'Module ' + modname + ' not found.') - def sub_reload_module(self, connection, event, nick, userhost, replypath, what, admin_unlocked): - """ - Attempt to reload a module, by seeing if it's loaded and, if so, calling its reload() - """ - - whats = what.split(' ') - - modname = whats[1] - for module in self.modlist: - if modname == module.__class__.__name__: - module.reload() - return self.reply(connection, replypath, modname + ' reloaded.') - def sub_unload_module(self, connection, event, nick, userhost, replypath, what, admin_unlocked): """ Attempt to unload and del a module if it's loaded. """ whats = what.split(' ') - modname = whats[1] + modstr = 'modules.'+modname + for module in self.modlist: if modname == module.__class__.__name__: + # do anything the module needs to do to clean up + module.shutdown() + # remove module references self.modlist.remove(module) module.unregister_handlers() # del it - del module - return self.reply(connection, replypath, modname + ' unloaded.') + del(sys.modules[modstr]) + del(module) + + return self.reply(connection, replypath, 'Module ' + modname + ' unloaded.') # guess it was never loaded - return self.reply(connection, replypath, modname + ' is not loaded.') + return self.reply(connection, replypath, 'Module ' + modname + ' is not loaded.') + + def sub_reload_module(self, connection, event, nick, userhost, replypath, what, admin_unlocked): + """ + Attempt to reload a module, by removing it from memory and then re-initializing it. + """ + + whats = what.split(' ') + modname = whats[1] + ret = self.sub_unload_module(connection, event, nick, userhost, None, what, admin_unlocked) + if ret == 'Module ' + modname + ' unloaded.': + ret = self.sub_load_module(connection, event, nick, userhost, None, what, admin_unlocked) + if ret == 'Module ' + modname + ' loaded.': + return self.reply(connection, replypath, 'Module ' + modname + ' reloaded.') + + return self.reply(connection, replypath, 'Module ' + modname + ' reload failed. Check the console.') # Save the config file. def save_config(self):