diff options
author | Yann Leboulanger <asterix@lagaule.org> | 2004-01-17 18:38:29 +0300 |
---|---|---|
committer | Yann Leboulanger <asterix@lagaule.org> | 2004-01-17 18:38:29 +0300 |
commit | 6b754525576bf4d42aa75fb31b31edef3b27a561 (patch) | |
tree | 2c79dda98eedf7a0b01c6c5851c60923880b8e12 /core | |
parent | e8b6c78f5e7575fc8eabad05b9c6279a9bdf38c1 (diff) |
keyboard interrupt
comments
Diffstat (limited to 'core')
-rw-r--r-- | core/core.py | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/core/core.py b/core/core.py index 2cbcc5a83..5d4e0a3e9 100644 --- a/core/core.py +++ b/core/core.py @@ -35,6 +35,7 @@ log.setLevel(logging.DEBUG) CONFPATH = "~/.gajimrc" class GajimCore: + """Core""" def __init__(self): self.connected = 0 self.cfgParser = common.optparser.OptionsParser(CONFPATH) @@ -43,11 +44,13 @@ class GajimCore: # END __init__ def messageCB(self, con, msg): + """Called when we recieve a message""" self.hub.sendPlugin('MSG', (msg.getFrom().getBasic(), \ msg.getBody())) # END messageCB def presenceCB(self, con, prs): + """Called when we recieve a presence""" who = str(prs.getFrom()) type = prs.getType() if type == None: type = 'available' @@ -98,6 +101,7 @@ class GajimCore: # END presenceCB def disconnectedCB(self, con): + """Called when we are disconnected""" log.debug("disconnectedCB") if self.connected == 1: self.connected = 0 @@ -106,13 +110,14 @@ class GajimCore: # END disconenctedCB def connect(self, account): + """Connect and authentificate to the Jabber server""" self.cfgParser.parseCfgFile() hostname = self.cfgParser.__getattr__("%s" % account+"_hostname") name = self.cfgParser.__getattr__("%s" % account+"_name") password = self.cfgParser.__getattr__("%s" % account+"_password") ressource = self.cfgParser.__getattr__("%s" % account+"_ressource") self.con = common.jabber.Client(host = \ - hostname, debug = [common.jabber.DBG_ALWAYS], log = sys.stderr, connection=common.xmlstream.TCP, port=5222) + hostname, debug = [common.jabber.DBG_INIT], log = sys.stderr, connection=common.xmlstream.TCP, port=5222) # hostname, debug = [common.jabber.DBG_ALWAYS], log = sys.stderr, connection=common.xmlstream.TCP_SSL, port=5223) try: self.con.connect() @@ -121,15 +126,17 @@ class GajimCore: self.hub.sendPlugin('STATUS', 'offline') self.hub.sendPlugin('WARNING', "Couldn't connect to %s" % hostname) return 0 + except self.con.socket.gaierror, e: + log.debug("Couldn't connect to %s %s" % (hostname, e)) + self.hub.sendPlugin('STATUS', 'offline') + self.hub.sendPlugin('WARNING', "Couldn't connect to %s" % hostname) + return 0 else: log.debug("Connected to server") self.con.registerHandler('message', self.messageCB) self.con.registerHandler('presence', self.presenceCB) self.con.setDisconnectHandler(self.disconnectedCB) -# self.con.setMessageHandler(self.messageCB) -# self.con.setPresenceHandler(self.presenceCB) -# self.con.setDisconnectHandler(self.disconnectedCB) #BUG in jabberpy library : if hostname is wrong : "boucle" if self.con.auth(name, password, ressource): self.con.requestRoster() @@ -148,6 +155,7 @@ class GajimCore: # END connect def mainLoop(self): + """Main Loop : Read the incomming queue to execute commands comming from plugins and process Jabber""" while 1: if not self.hub.queueIn.empty(): ev = self.hub.queueIn.get() @@ -238,8 +246,9 @@ class GajimCore: # END GajimCore def loadPlugins(gc): + """Load defaults plugins : 'modules' option in section Core in ConfFile and register then to the hub""" modStr = gc.cfgParser.Core_modules - if modStr : + if modStr: mods = string.split (modStr, ' ') for mod in mods: @@ -260,7 +269,15 @@ def loadPlugins(gc): # END loadPLugins def start(): + """Start the Core""" gc = GajimCore() loadPlugins(gc) - gc.mainLoop() + try: + gc.mainLoop() + except KeyboardInterrupt: + print "Keyboard Interrupt : Bye!" + if self.r.connected: + self.r.con.disconnect() + gc.hub.sendPlugin('QUIT', ()) + return 0 # END start |