refactoring: moved sat to sat.tac, now a twisted application so we can use twistd.

This commit is contained in:
Goffi 2009-10-19 22:45:52 +02:00
commit 4b7804c669

27
sat → sat.tac Executable file → Normal file
View file

@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from twisted.application import internet, service
from twisted.internet import glib2reactor, protocol
glib2reactor.install()
@ -51,7 +52,7 @@ logging.basicConfig(level=logging.DEBUG,
class SAT:
def __init__(self):
self.reactor=reactor
#self.reactor=reactor
self.memory=Memory()
self.server_features=[] #XXX: temp dic, need to be transfered into self.memory in the future
self.connected=False #FIXME: use twisted var instead
@ -97,18 +98,21 @@ class SAT:
self.plugins[plug_info['import_name']] = getattr(mod, plug_info['main'])(self)
def connect(self):
print "Connect !"
if (self.connected):
print "connecting..."
def getService(self):
print "GetService !"
"""if (self.connected):
info("already connected !")
return
info("Connecting...")
return"""
info("Getting client...")
self.me = jid.JID(self.memory.getParamV("JabberID", "Connection"))
self.factory = client.XMPPClientFactory(self.me, self.memory.getParamV("Password", "Connection"))
self.factory.addBootstrap(xmlstream.STREAM_AUTHD_EVENT,self.authd)
self.factory.addBootstrap(xmlstream.INIT_FAILED_EVENT,self.failed)
reactor.connectTCP(self.memory.getParamV("Server", "Connection"), 5222, self.factory)
self.connectionStatus="online" #TODO: check if connection is OK
self.connected=True #TODO: use startedConnecting and clientConnectionLost of XMPPClientFactory
return internet.TCPClient(self.memory.getParamV("Server", "Connection"), 5222, self.factory)
def disconnect(self):
if (not self.connected):
@ -367,8 +371,11 @@ class SAT:
return data
app=SAT() #TODO: tmp, use twisted way instead
app.run()
application = service.Application('SàT')
sat = SAT()
service = sat.getService()
service.setServiceParent(application)
app.memory.save() #FIXME: not the best place
debug("Good Bye")
#app.memory.save() #FIXME: not the best place
#debug("Good Bye")