~m4v/+junk/Factos

« back to all changes in this revision

Viewing changes to plugin.py

  • Committer: Elián Hanisch
  • Date: 2010-05-16 06:10:54 UTC
  • Revision ID: lambdae2@gmail.com-20100516061054-y63xd9ln3i8fykiz
reactoring, drop setting table name with config options, is useless.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
from network import freenode, freenodeSubstitution
40
40
 
41
41
factosConf = conf.supybot.plugins.Factos
42
 
tableConf = factosConf.sqlite.table
43
 
# tables setup
44
 
# base fact table
45
 
tableFact = objects.Table(objects.tblFactStruct, tableConf.fact())
46
 
# base table for record edits
47
 
tableHist = objects.Table(objects.tblHistStruct, tableConf.history())
48
 
tableHistRedo = objects.Table(objects.tblHistStruct, tableConf.redo())
49
 
# table for user hostmasks
50
 
tableUser = objects.databases.Table(objects.tblUserStruct, tableConf.users())
51
 
 
52
 
class FactosDB(objects.SqliteDB):
53
 
    def __init__(self, filename, **kwargs):
54
 
        self.__parent = super(FactosDB, self)
55
 
        self.__parent.__init__(filename, tableFact, tableHist, tableHistRedo, tableUser,
56
 
                **kwargs)
57
 
 
 
42
 
 
43
FactosDB = objects.SqliteDB
58
44
class MultiFactosDB(MultiDB):
59
45
    database = FactosDB
60
46
 
61
47
 
 
48
User = objects.User
62
49
class Fact(objects.Fact):
63
50
    """Class for handling facts."""
64
 
    dbTable = tableFact
65
 
    dbTableHist = tableHist
66
51
    prefix = conf.supybot.reply.whenAddressedBy.chars()[0]
67
52
    regexp = u'[\w\-\.\#]+' # regexp for a valid fact name
68
53
    formatChannel = staticmethod(formatChannel) # better use formatChannel from supyutils
122
107
        return s
123
108
 
124
109
 
125
 
class User(objects.User):
126
 
    """Class for handling users."""
127
 
    dbTable = tableUser
128
 
 
129
 
 
130
110
def logInfo(irc, msg, s, fact=None):
131
111
    """Information logging."""
132
112
    vars = {'msg': msg.args[1]}
811
791
            if id > 0:
812
792
                # redo history
813
793
                redo = True
814
 
                hist = db.getHist(fact.name, channel=fact.channel, table=tableHistRedo)
 
794
                hist = db.getHist(fact.name, channel=fact.channel, table=db.tableHistRedo)
815
795
                id -= 1
816
796
            else:
817
797
                hist = db.getHist(fact.name, channel=fact.channel)
1271
1251
        db = fact.db
1272
1252
 
1273
1253
        fact.pull(channel)
1274
 
        hist = db.getHistOne(fact.name, channel=fact.channel, table=tableHistRedo)
 
1254
        hist = db.getHistOne(fact.name, channel=fact.channel, table=db.tableHistRedo)
1275
1255
        if hist:
1276
1256
            db.updateHist(fact.getHist(), hist['history_id'], undo=False,
1277
1257
                    channel=fact.channel)
1294
1274
        db = self.db.getDB(name=self.registryValue('sqlite.default', channel))
1295
1275
 
1296
1276
        if 'all-channels' in self.options:
1297
 
            tableList = db.getTables(all=self.registryValue('sqlite.table.fact'))
 
1277
            tableList = db.getTables(all=db.tableFact.name) # FIXME
1298
1278
        elif channel:
1299
1279
            tableList = db.getTables(inChannel=channel)
1300
1280
        else:
1301
 
            tableList = db.getTables(all=self.registryValue('sqlite.table.fact'))
 
1281
            tableList = db.getTables(all=db.tableFact.name) # FIXME
1302
1282
 
1303
1283
        #log.debug('Factos.search() tables=%s' % (tableList, ))
1304
1284
        matchall = True