Skip to content

Commit

Permalink
Add some database stuff to the core.
Browse files Browse the repository at this point in the history
  • Loading branch information
mythmon committed Jul 18, 2011
1 parent 4603358 commit 0e3a249
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
25 changes: 17 additions & 8 deletions hamper/commander.py
Expand Up @@ -5,9 +5,10 @@


from twisted.words.protocols import irc from twisted.words.protocols import irc
from twisted.internet import protocol, reactor from twisted.internet import protocol, reactor
import sqlalchemy
from sqlalchemy import orm


from bravo.plugin import retrieve_plugins from bravo.plugin import retrieve_plugins

from hamper.IHamper import IPlugin from hamper.IHamper import IPlugin




Expand Down Expand Up @@ -99,22 +100,30 @@ class CommanderFactory(protocol.ClientFactory):


protocol = CommanderProtocol protocol = CommanderProtocol


def __init__(self, channel, nickname): def __init__(self, config):
self.channel = channel self.channel = config['channel']
self.nickname = nickname self.nickname = config['nickname']


self.history = {} self.history = {}

self.plugins = set() 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.pluginsToAdd = set()
self.pluginsToRemove = 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(): for _, plugin in retrieve_plugins(IPlugin, 'hamper.plugins').items():
self.registerPlugin(plugin) self.registerPlugin(plugin)


def buildProtocol(self, addr):
p = protocol.ClientFactory.buildProtocol(self, addr)
p.db = self.DBSession()
return p

def clientConnectionLost(self, connector, reason): def clientConnectionLost(self, connector, reason):
print "Lost connection (%s)." % (reason) print "Lost connection (%s)." % (reason)


Expand Down
2 changes: 1 addition & 1 deletion hamper/main.py
Expand Up @@ -17,5 +17,5 @@
sys.exit(); sys.exit();


reactor.connectTCP(config['server'], config['port'], reactor.connectTCP(config['server'], config['port'],
CommanderFactory(config['channel'], config['nickname'])) CommanderFactory(config))
reactor.run() reactor.run()
2 changes: 1 addition & 1 deletion 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 from bravo import plugin


Expand Down

0 comments on commit 0e3a249

Please sign in to comment.