Permalink
Browse files

Add some database stuff to the core.

  • Loading branch information...
1 parent 4603358 commit 0e3a249e843f291fc8fc84d43bd38c9849b77485 @mythmon mythmon committed Jul 18, 2011
Showing with 19 additions and 10 deletions.
  1. +17 −8 hamper/commander.py
  2. +1 −1 hamper/main.py
  3. +1 −1 hamper/plugins/plugin_utils.py
View
25 hamper/commander.py
@@ -5,9 +5,10 @@
from twisted.words.protocols import irc
from twisted.internet import protocol, reactor
+import sqlalchemy
+from sqlalchemy import orm
from bravo.plugin import retrieve_plugins
-
from hamper.IHamper import IPlugin
@@ -99,22 +100,30 @@ class CommanderFactory(protocol.ClientFactory):
protocol = CommanderProtocol
- def __init__(self, channel, nickname):
- self.channel = channel
- self.nickname = nickname
+ def __init__(self, config):
+ self.channel = config['channel']
+ self.nickname = config['nickname']
self.history = {}
-
self.plugins = set()
- # These are so plugins can be added/removed at run time. The
- # addition/removal will happen at a time when the set isn't being
- # iterated, so nothing breaks.
+
self.pluginsToAdd = set()
self.pluginsToRemove = set()
+ if 'db' in config:
+ engine = sqlalchemy.create_engine(config['db'])
+ else:
+ engine = sqlalchemy.create_engine('sqlite:///:memory:')
+ self.DBSession = orm.sessionmaker(engine)
+
for _, plugin in retrieve_plugins(IPlugin, 'hamper.plugins').items():
self.registerPlugin(plugin)
+ def buildProtocol(self, addr):
+ p = protocol.ClientFactory.buildProtocol(self, addr)
+ p.db = self.DBSession()
+ return p
+
def clientConnectionLost(self, connector, reason):
print "Lost connection (%s)." % (reason)
View
2 hamper/main.py
@@ -17,5 +17,5 @@
sys.exit();
reactor.connectTCP(config['server'], config['port'],
- CommanderFactory(config['channel'], config['nickname']))
+ CommanderFactory(config))
reactor.run()
View
2 hamper/plugins/plugin_utils.py
@@ -1,4 +1,4 @@
-from zope.interface import implements, Interface, Attribute
+from zope.interface import implements
from bravo import plugin

0 comments on commit 0e3a249

Please sign in to comment.