2010-05-02 06:20:00 +02:00
|
|
|
from connection.xmpp import XMPPConnection
|
|
|
|
|
|
|
|
import signal, sys
|
2010-05-02 15:03:32 +02:00
|
|
|
from config import config
|
2010-05-02 06:20:00 +02:00
|
|
|
|
2010-05-02 20:28:17 +02:00
|
|
|
class ModuleManager:
|
|
|
|
def __init__(self, config):
|
|
|
|
self.config = config
|
2010-05-02 21:18:09 +02:00
|
|
|
self.modules = {}
|
2010-05-02 20:28:17 +02:00
|
|
|
|
|
|
|
for mod in config['modules']:
|
2010-05-02 21:18:09 +02:00
|
|
|
self.get(mod)
|
2010-05-02 20:28:17 +02:00
|
|
|
|
2010-05-02 21:18:09 +02:00
|
|
|
def get(self, name):
|
|
|
|
if not name in self.modules:
|
|
|
|
mod = __import__('modules.' + name, globals(), locals(), ['Module'])
|
|
|
|
self.modules[name] = mod.Module(self)
|
|
|
|
|
|
|
|
return self.modules[name]
|
|
|
|
|
2010-05-02 20:28:17 +02:00
|
|
|
|
2010-05-02 06:20:00 +02:00
|
|
|
run = True
|
|
|
|
|
|
|
|
def exithandler(signum, frame):
|
|
|
|
global run
|
|
|
|
run = False
|
|
|
|
|
2010-05-03 03:37:21 +02:00
|
|
|
print 'Starting Curunir 0.1'
|
|
|
|
|
2010-05-02 06:20:00 +02:00
|
|
|
signal.signal(signal.SIGINT, exithandler)
|
|
|
|
signal.signal(signal.SIGTERM, exithandler)
|
|
|
|
signal.signal(signal.SIGQUIT, exithandler)
|
|
|
|
|
2010-05-03 03:37:21 +02:00
|
|
|
print 'Loading modules...'
|
|
|
|
|
2010-05-02 20:28:17 +02:00
|
|
|
modman = ModuleManager(config)
|
|
|
|
|
|
|
|
connection = XMPPConnection(config, modman)
|
2010-05-03 03:37:21 +02:00
|
|
|
print 'Connecting...'
|
2010-05-02 06:20:00 +02:00
|
|
|
connection.connect()
|
|
|
|
|
|
|
|
while run:
|
2010-05-02 20:28:17 +02:00
|
|
|
act = connection.stream.loop_iter(1)
|
|
|
|
if not act:
|
|
|
|
connection.idle()
|
2010-05-02 06:20:00 +02:00
|
|
|
|
|
|
|
connection.disconnect()
|