From 3eb6787f6d6d066467e491399fb5d578e6dbbf22 Mon Sep 17 00:00:00 2001 From: Daniel Folkinshteyn Date: Fri, 19 Mar 2010 18:51:49 -0400 Subject: [PATCH] add vacuum method to clean up db. require admin capability by default to do this. --- plugins/MessageParser/config.py | 3 +++ plugins/MessageParser/plugin.py | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/plugins/MessageParser/config.py b/plugins/MessageParser/config.py index f0ee0c4ba..8a89d8f5f 100644 --- a/plugins/MessageParser/config.py +++ b/plugins/MessageParser/config.py @@ -54,5 +54,8 @@ conf.registerChannelValue(MessageParser, 'keepRankInfo', conf.registerChannelValue(MessageParser, 'rankListLength', registry.Integer(20, """Determines the number of regexps returned by the triggerrank command.""")) +conf.registerChannelValue(MessageParser, 'requireVacuumCapability', + registry.String('admin', """Determines the capability required (if any) to + vacuum the database.""")) # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: diff --git a/plugins/MessageParser/plugin.py b/plugins/MessageParser/plugin.py index 4c8b6d02d..adbd82339 100644 --- a/plugins/MessageParser/plugin.py +++ b/plugins/MessageParser/plugin.py @@ -362,6 +362,26 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler): irc.reply(", ".join(s)) rank = wrap(rank, ['channel']) + def vacuum(self, irc, msg, args, channel): + """[] + + Vacuums the database for . + See SQLite vacuum doc here: http://www.sqlite.org/lang_vacuum.html + is only necessary if the message isn't sent in + the channel itself. + First check if user has the required capability specified in plugin + config requireVacuumCapability. + """ + capability = self.registryValue('requireVacuumCapability') + if capability: + if not ircdb.checkCapability(msg.prefix, capability): + irc.errorNoCapability(capability, Raise=True) + db = self.getDb(channel) + cursor = db.cursor() + cursor.execute("""VACUUM""") + db.commit() + irc.replySuccess() + vacuum = wrap(vacuum, ['channel']) Class = MessageParser