Limnoria/plugins/baseplugin.py

49 lines
1.2 KiB
Python
Raw Normal View History

2003-03-12 07:26:59 +01:00
#!/usr/bin/env python
import sys
sys.path.insert(0, 'src')
sys.path.insert(0, 'others')
from fix import *
import os
import cdb
import conf
import world
2003-04-11 22:52:39 +02:00
import ircutils
2003-03-12 07:26:59 +01:00
import callbacks
2003-03-28 06:15:08 +01:00
class ChannelDBHandler(object):
2003-03-12 07:26:59 +01:00
"""A class to handle database stuff for individual channels transparently.
"""
suffix = '.db'
def __init__(self, suffix='.db'):
2003-04-11 22:52:39 +02:00
self.dbCache = ircutils.IrcDict()
2003-03-12 07:26:59 +01:00
suffix = self.suffix
if self.suffix and self.suffix[0] != '.':
suffix = '.' + suffix
self.suffix = suffix
def makeFilename(self, channel):
channel = ircutils.toLower(channel)
2003-03-12 07:26:59 +01:00
prefix = '%s-%s%s' % (channel, self.__class__.__name__, self.suffix)
return os.path.join(conf.dataDir, prefix)
def makeDb(self, filename):
return cdb.shelf(filename)
def getDb(self, channel):
try:
return self.dbCache[channel]
except KeyError:
db = self.makeDb(self.makeFilename(channel))
self.dbCache[channel] = db
return db
def die(self):
for db in self.dbCache.itervalues():
db.close()
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: