mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +01:00
Partial conversion to registry, need to get it on my desktop box to test.
This commit is contained in:
parent
285ac5ef6d
commit
03c6efcb7f
@ -88,6 +88,9 @@ def configure(advanced):
|
||||
onStart.append('lookup add %s %s' % (command, filename))
|
||||
|
||||
|
||||
conf.registerPlugin('Lookup')
|
||||
conf.registerGroup(conf.supybot.plugins.Lookup, 'lookups')
|
||||
|
||||
class LookupDB(plugins.DBHandler):
|
||||
def makeDb(self, filename):
|
||||
return sqlite.connect(filename)
|
||||
@ -149,36 +152,39 @@ class Lookup(callbacks.Privmsg):
|
||||
self.addCommand(name)
|
||||
irc.replySuccess()
|
||||
except sqlite.DatabaseError:
|
||||
# Good, there's no such database.
|
||||
try:
|
||||
dataDir = conf.supybot.directories.data()
|
||||
filename = os.path.join(dataDir, filename)
|
||||
fd = file(filename)
|
||||
self.addDatabase(name, filename)
|
||||
except EnvironmentError, e:
|
||||
irc.error('Could not open %s: %s' % (filename, e.args[1]))
|
||||
return
|
||||
try:
|
||||
cursor.execute("""SELECT COUNT(*) FROM %s""" % name)
|
||||
except sqlite.DatabaseError:
|
||||
cursor.execute("CREATE TABLE %s (key TEXT, value TEXT)" % name)
|
||||
sql = "INSERT INTO %s VALUES (%%s, %%s)" % name
|
||||
for line in utils.nonCommentNonEmptyLines(fd):
|
||||
line = line.rstrip('\r\n')
|
||||
try:
|
||||
(key, value) = self._splitRe.split(line, 1)
|
||||
key = key.replace('\\:', ':')
|
||||
except ValueError:
|
||||
cursor.execute("""DROP TABLE %s""" % name)
|
||||
s = 'Invalid line in %s: %r' % (filename, line)
|
||||
irc.error(s)
|
||||
return
|
||||
cursor.execute(sql, key, value)
|
||||
cursor.execute("CREATE INDEX %s_keys ON %s (key)" %(name,name))
|
||||
db.commit()
|
||||
self.addCommand(name)
|
||||
irc.replySuccess('(lookup %s added)' % name)
|
||||
add = privmsgs.checkCapability(add, 'admin')
|
||||
|
||||
def addDatabase(self, name, filename):
|
||||
db = self.dbHandler.getDb()
|
||||
cursor = db.cursor()
|
||||
dataDir = conf.supybot.directories.data()
|
||||
filename = os.path.join(dataDir, filename)
|
||||
fd = file(filename)
|
||||
try:
|
||||
cursor.execute("""SELECT COUNT(*) FROM %s""" % name)
|
||||
except sqlite.DatabaseError:
|
||||
cursor.execute("CREATE TABLE %s (key TEXT, value TEXT)" % name)
|
||||
sql = "INSERT INTO %s VALUES (%%s, %%s)" % name
|
||||
for line in utils.nonCommentNonEmptyLines(fd):
|
||||
line = line.rstrip('\r\n')
|
||||
try:
|
||||
(key, value) = self._splitRe.split(line, 1)
|
||||
key = key.replace('\\:', ':')
|
||||
except ValueError:
|
||||
cursor.execute("""DROP TABLE %s""" % name)
|
||||
s = 'Invalid line in %s: %r' % (filename, line)
|
||||
raise callbacks.Error, s
|
||||
cursor.execute(sql, key, value)
|
||||
cursor.execute("CREATE INDEX %s_keys ON %s (key)" % (name, name))
|
||||
db.commit()
|
||||
|
||||
def addCommand(self, name):
|
||||
def f(self, irc, msg, args):
|
||||
args.insert(0, name)
|
||||
|
Loading…
Reference in New Issue
Block a user