add vacuum method to clean up db. require admin capability by default to do this.

This commit is contained in:
Daniel Folkinshteyn 2010-03-19 18:51:49 -04:00
parent 1a3d6c3821
commit 3eb6787f6d
2 changed files with 23 additions and 0 deletions

View File

@ -54,5 +54,8 @@ conf.registerChannelValue(MessageParser, 'keepRankInfo',
conf.registerChannelValue(MessageParser, 'rankListLength', conf.registerChannelValue(MessageParser, 'rankListLength',
registry.Integer(20, """Determines the number of regexps returned registry.Integer(20, """Determines the number of regexps returned
by the triggerrank command.""")) 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: # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:

View File

@ -362,6 +362,26 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
irc.reply(", ".join(s)) irc.reply(", ".join(s))
rank = wrap(rank, ['channel']) rank = wrap(rank, ['channel'])
def vacuum(self, irc, msg, args, channel):
"""[<channel>]
Vacuums the database for <channel>.
See SQLite vacuum doc here: http://www.sqlite.org/lang_vacuum.html
<channel> 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 Class = MessageParser