add unload method to IrcAdmin, which unloads a module

hopefully this all works right. i remove two known references
to the object, and then call a del for good measure, which i
think covers it?
This commit is contained in:
Brian S. Stephan 2010-12-15 21:28:57 -06:00
parent 2295f524d4
commit ea0f795194
1 changed files with 23 additions and 0 deletions

View File

@ -81,6 +81,8 @@ class IrcAdmin(Module):
return self.sub_load_module(connection, event, nick, userhost, replypath, what, admin_unlocked)
elif whats[0] == 'reload' and admin_unlocked and len(whats) >= 2:
return self.sub_reload_module(connection, event, nick, userhost, replypath, what, admin_unlocked)
elif whats[0] == 'unload' and admin_unlocked and len(whats) >= 2:
return self.sub_unload_module(connection, event, nick, userhost, replypath, what, admin_unlocked)
def sub_join_channel(self, connection, event, nick, userhost, replypath, what, admin_unlocked):
whats = what.split(' ')
@ -192,6 +194,27 @@ class IrcAdmin(Module):
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]
for module in self.modlist:
if modname == module.__class__.__name__:
# remove module references
self.modlist.remove(module)
module.unregister_handlers()
# del it
del module
return self.reply(connection, replypath, modname + ' unloaded.')
# guess it was never loaded
return self.reply(connection, replypath, modname + ' is not loaded.')
# Save the config file.
def save_config(self):
with open('dr.botzo.cfg', 'w') as cfg: