2004-12-05 21:02:25 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import os
|
|
|
|
import sys
|
2005-01-03 22:57:20 +01:00
|
|
|
import time
|
2004-12-05 21:02:25 +01:00
|
|
|
import sqlite
|
|
|
|
|
|
|
|
import supybot.dbi as dbi
|
2005-01-03 22:04:51 +01:00
|
|
|
import supybot.conf as conf
|
2005-01-03 22:57:20 +01:00
|
|
|
import supybot.plugins as plugins
|
2005-01-03 22:04:51 +01:00
|
|
|
import supybot.ircutils as ircutils
|
2004-12-05 21:02:25 +01:00
|
|
|
import supybot.plugins.Lart as Lart
|
|
|
|
import supybot.plugins.Praise as Praise
|
|
|
|
|
2005-01-03 22:04:51 +01:00
|
|
|
conf.supybot.log.stdout.setValue(False)
|
|
|
|
|
2004-12-05 21:02:25 +01:00
|
|
|
def usage():
|
|
|
|
print 'usage: %s <sqlitedb> <channel> [<botname>]' % sys.argv[0]
|
|
|
|
print '<botname> is an optional parameter used if any db entries are '\
|
|
|
|
'missing a "created by" user.'
|
|
|
|
|
|
|
|
def main():
|
|
|
|
if '-h' in sys.argv or '--help' in sys.argv or len(sys.argv) not in (3, 4):
|
|
|
|
usage()
|
|
|
|
sys.exit(1)
|
|
|
|
sqldb = sys.argv[1]
|
|
|
|
channel = sys.argv[2]
|
2005-01-03 22:57:20 +01:00
|
|
|
botname = 'an unkown user'
|
|
|
|
if len(sys.argv) == 4:
|
|
|
|
botname = sys.argv[3]
|
2005-01-03 22:04:51 +01:00
|
|
|
if not ircutils.isChannel(channel):
|
2005-01-03 22:57:20 +01:00
|
|
|
print '%s is an invalid channel name.' % channel
|
2005-01-03 22:04:51 +01:00
|
|
|
sys.exit(1)
|
2004-12-05 21:02:25 +01:00
|
|
|
if not os.path.exists(sqldb):
|
|
|
|
print 'Unable to open %s' % sqldb
|
|
|
|
sys.exit(1)
|
|
|
|
praises = Praise.Praise().db
|
|
|
|
larts = Lart.Lart().db
|
|
|
|
db = sqlite.connect(sqldb)
|
|
|
|
cursor = db.cursor()
|
|
|
|
total = 0
|
|
|
|
failed = 0
|
|
|
|
success = 0
|
2004-12-10 03:44:01 +01:00
|
|
|
for (table, plugin) in (('larts', larts), ('praises', praises)):
|
2004-12-05 21:02:25 +01:00
|
|
|
cursor.execute("""SELECT * FROM %s ORDER BY id ASC""" % table)
|
|
|
|
table = table[:-1]
|
|
|
|
if cursor.rowcount != 0:
|
|
|
|
entries = cursor.fetchall()
|
|
|
|
for entry in entries:
|
|
|
|
try:
|
|
|
|
total += 1
|
|
|
|
text = entry[1]
|
|
|
|
by = entry[2]
|
|
|
|
if by is None:
|
|
|
|
by = botname
|
2005-01-03 22:57:20 +01:00
|
|
|
plugin.add(channel, time.time(), by, text)
|
2004-12-05 21:02:25 +01:00
|
|
|
success += 1
|
|
|
|
except dbi.Error:
|
|
|
|
failed += 1
|
|
|
|
print '%s/%s entries successfully added. %s failed.' % (success, total,
|
|
|
|
failed)
|
2005-01-03 22:57:20 +01:00
|
|
|
pfile = plugins.makeChannelFilename(praises.filename, channel)
|
|
|
|
lfile = plugins.makeChannelFilename(larts.filename, channel)
|
|
|
|
print 'Dbs are at: %s' % ', '.join((pfile, lfile))
|
2004-12-05 21:02:25 +01:00
|
|
|
db.close()
|
|
|
|
praises.close()
|
|
|
|
larts.close()
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|