Exemplo n.º 1
0
 def queueHandle(self):
     if self.dmb.queue_to_send:
         for rec in self.dmb.queue_to_send:
             sended = 0
             log.info(rec['jid'])
             for j in rec['jid']:
                 if rec.get('send') or self.ui.getStatus(j):
                     queue_output.put(
                         (j, rec.get('message'), rec.get('extra')))
                     sended = 1
                     break
             if not sended:
                 post = rec.get('post')
                 message = rec.get('message')
                 comment = rec.get('comment')
                 id_recommend = rec.get('id_recommend')
                 try:
                     self.dmb.addToSendQueue(login=rec['login'],
                                             post=post,
                                             comment=comment,
                                             id_recommend=id_recommend,
                                             message=message)
                 except dmbError:
                     log.debug('%d %s %s' % (sys.exc_traceback.tb_lineno,
                                             sys.exc_type, sys.exc_value))
                 except:
                     log.error('%d %s %s' % (sys.exc_traceback.tb_lineno,
                                             sys.exc_type, sys.exc_value))
         tick = time.time()
         self.dmb.queue_to_send = []
         tick = time.time() - tick
         log.debug('%s %s' % ('queueHandle', tick))
Exemplo n.º 2
0
	def queueHandle(self):
		if self.dmb.queue_to_send:
			for rec in self.dmb.queue_to_send:
				sended = 0
				log.info(rec['jid'])
				for j in rec['jid']:
					if rec.get('send') or self.ui.getStatus(j):
						queue_output.put((j, rec.get('message'), rec.get('extra')))
						sended = 1
						break
				if not sended:
					post = rec.get('post')
					message = rec.get('message')
					comment = rec.get('comment')
					id_recommend = rec.get('id_recommend')
					try:
						self.dmb.addToSendQueue(login = rec['login'], post = post, comment = comment, id_recommend = id_recommend, message = message)
					except dmbError:
						log.debug('%d %s %s' % (sys.exc_traceback.tb_lineno, sys.exc_type, sys.exc_value))
					except:
						log.error('%d %s %s' % (sys.exc_traceback.tb_lineno, sys.exc_type, sys.exc_value))
			tick = time.time()
			self.dmb.queue_to_send = []
			tick = time.time() - tick
			log.debug('%s %s' % ('queueHandle', tick))
Exemplo n.º 3
0
 def getStatus(self, jid):
     try:
         if self.client.getRoster().getItem(jid):
             for res in self.client.getRoster().getItem(jid)["resources"].values():
                 if res["show"]:
                     return res["show"]
                 else:
                     return "online"
         return None
     except:
         log.error("%d %s %s" % (sys.exc_traceback.tb_lineno, sys.exc_type, sys.exc_value))
Exemplo n.º 4
0
 def getStatus(self, jid):
     try:
         if self.client.getRoster().getItem(jid):
             for res in self.client.getRoster().getItem(
                     jid)['resources'].values():
                 if res['show']:
                     return res['show']
                 else:
                     return 'online'
         return None
     except:
         log.error(
             '%d %s %s' %
             (sys.exc_traceback.tb_lineno, sys.exc_type, sys.exc_value))
Exemplo n.º 5
0
 def send(self, jid, message, extra):
     try:
         if message:
             message = message.rstrip()
             if message.count("\n"):
                 message = "\n" + message
             msg = xmpp.protocol.Message(jid, message, "chat")
             if extra:
                 for k, v in extra.iteritems():
                     msg.setAttr(k, v)
             log.info("%s(%s) -> %s" % (jid, msg.getBody(), msg.getAttrs()))
             self.client.send(msg)
     except:
         log.error("%d %s %s" % (sys.exc_traceback.tb_lineno, sys.exc_type, sys.exc_value))
Exemplo n.º 6
0
 def messageHandler(self, conn, msg):
     try:
         log.info("%s(%s) -> %s" % (msg.getFrom(), msg.getBody(), msg.getAttrs()))
         if msg.getAttrs().get("dmb") == "server":
             if self.s2sFunc:
                 login = msg.getAttrs().get("dmb_login")
                 self.s2sFunc(str(msg.getFrom()).split("/")[0], msg.getBody(), login)
         elif msg.getBody() and self.messageFunc:
             self.messageFunc(str(msg.getFrom()).split("/")[0], msg.getBody())
     except SystemExit:
         log.info("%s" % "system exit")
         sys.exit()
     except:
         log.error("%d %s %s" % (sys.exc_traceback.tb_lineno, sys.exc_type, sys.exc_value))
Exemplo n.º 7
0
 def presenceHandler(self, conn, event):
     try:
         if event:
             log.info("%s %s" % (event.getFrom(), event.getAttrs()))
             if event.getAttrs().get("type") == "subscribe":
                 self.client.getRoster().Authorize(event.getFrom())
             jid = str(event.getFrom()).split("/")[0]
             status = self.getStatus(jid)
             if status and self.presenceFunc:
                 self.presenceFunc(jid, status)
     except SystemExit:
         log.info("%s" % "system exit")
         sys.exit()
     except:
         log.error("%d %s %s" % (sys.exc_traceback.tb_lineno, sys.exc_type, sys.exc_value))
Exemplo n.º 8
0
 def send(self, jid, message, extra):
     try:
         if message:
             message = message.rstrip()
             if message.count('\n'):
                 message = '\n' + message
             msg = xmpp.protocol.Message(jid, message, 'chat')
             if extra:
                 for k, v in extra.iteritems():
                     msg.setAttr(k, v)
             log.info('%s(%s) -> %s' % (jid, msg.getBody(), msg.getAttrs()))
             self.client.send(msg)
     except:
         log.error(
             '%d %s %s' %
             (sys.exc_traceback.tb_lineno, sys.exc_type, sys.exc_value))
Exemplo n.º 9
0
 def presenceHandler(self, conn, event):
     try:
         if event:
             log.info('%s %s' % (event.getFrom(), event.getAttrs()))
             if event.getAttrs().get('type') == 'subscribe':
                 self.client.getRoster().Authorize(event.getFrom())
             jid = str(event.getFrom()).split('/')[0]
             status = self.getStatus(jid)
             if status and self.presenceFunc:
                 self.presenceFunc(jid, status)
     except SystemExit:
         log.info('%s' % 'system exit')
         sys.exit()
     except:
         log.error(
             '%d %s %s' %
             (sys.exc_traceback.tb_lineno, sys.exc_type, sys.exc_value))
Exemplo n.º 10
0
 def messageHandler(self, conn, msg):
     try:
         log.info('%s(%s) -> %s' %
                  (msg.getFrom(), msg.getBody(), msg.getAttrs()))
         if msg.getAttrs().get('dmb') == 'server':
             if self.s2sFunc:
                 login = msg.getAttrs().get('dmb_login')
                 self.s2sFunc(
                     str(msg.getFrom()).split('/')[0], msg.getBody(), login)
         elif msg.getBody() and self.messageFunc:
             self.messageFunc(
                 str(msg.getFrom()).split('/')[0], msg.getBody())
     except SystemExit:
         log.info('%s' % 'system exit')
         sys.exit()
     except:
         log.error(
             '%d %s %s' %
             (sys.exc_traceback.tb_lineno, sys.exc_type, sys.exc_value))
Exemplo n.º 11
0
 def run(self):
     global is_run
     while is_run:
         try:
             jid, message, login = queue_input.get(timeout=10)
             log.info('%s %s' % (jid, message))
             if not login:
                 try:
                     login = self.dmb.getLogin(jid=jid)
                 except dmbErrorAuth:
                     login = '******'
             try:
                 self.dmb.def_locale = self.dmb.getUserParams(
                     login)['locale']
             except:
                 log.error('%d %s %s' % (sys.exc_traceback.tb_lineno,
                                         sys.exc_type, sys.exc_value))
             try:
                 tick = time.time()
                 if jid == config.admin:
                     mesg = adminParsing(self.dmb,
                                         login=unicode(login),
                                         text=unicode(message),
                                         jid=jid)
                 else:
                     mesg = parsing(self.dmb,
                                    login=unicode(login),
                                    text=unicode(message),
                                    jid=jid)
                 tick = time.time() - tick
                 log.debug('%s %s' % (message.split(' ')[0], tick))
             except SystemExit:
                 log.info('exit')
                 is_run = None
                 self.ui.is_run = None
                 sys.exit()
             except dmbError as exc:
                 log.error('%d %s %s' % (sys.exc_traceback.tb_lineno,
                                         sys.exc_type, sys.exc_value))
                 mesg = '%s %s' % (exc.getText(),
                                   self.dmb.getText(exc.getCode()))
             except:
                 log.error('%d %s %s' % (sys.exc_traceback.tb_lineno,
                                         sys.exc_type, sys.exc_value))
                 mesg = self.dmb.getText('ERR7')
             queue_output.put((jid, mesg, {}))
             self.queueHandle()
         except Queue.Empty:
             pass
Exemplo n.º 12
0
	def run(self):
		global is_run
		while is_run:
			try:
				jid, message, login = queue_input.get(timeout = 10)
				log.info('%s %s' % (jid, message))
				if not login:
					try:
						login = self.dmb.getLogin(jid = jid)
					except dmbErrorAuth:
						login = '******'
				try:
					self.dmb.def_locale = self.dmb.getUserParams(login)['locale']
				except:
					log.error('%d %s %s' % (sys.exc_traceback.tb_lineno, sys.exc_type, sys.exc_value))			
				try:
					tick = time.time()
					if jid == config.admin:
						mesg = adminParsing(self.dmb, login = unicode(login), text = unicode(message), jid = jid)
					else:
						mesg = parsing(self.dmb, login = unicode(login), text = unicode(message), jid = jid)
					tick = time.time() - tick
					log.debug('%s %s' % (message.split(' ')[0], tick))
				except SystemExit:
					log.info('exit')
					is_run = None
					self.ui.is_run = None
					sys.exit()
				except dmbError as exc:
					log.error('%d %s %s' % (sys.exc_traceback.tb_lineno, sys.exc_type, sys.exc_value))			
					mesg = '%s %s' % (exc.getText(), self.dmb.getText(exc.getCode()))
				except:
					log.error('%d %s %s' % (sys.exc_traceback.tb_lineno, sys.exc_type, sys.exc_value))
					mesg = self.dmb.getText('ERR7')
				queue_output.put((jid, mesg, {}))
				self.queueHandle()
			except Queue.Empty:
				pass