def run(self): logger.info("Starting up XMPP clients...") for each in self.clients: each[0].start() logger.info("All XMPP Clients fired.") logger.info("Feed watchdog.") self.feedDog() # begin looping while not self.sig_terminate.isSet(): logger.debug("Enter a daemon running loop.") # Job now. now = time.time() # Job #1: Check if clients got messages for us. newmessages = [] for each in self.clients: if each[0].isAlive(): newmessages += each[0].getMessage() if newmessages: logger.info("New message(s) retrived from clients. Will parse them.") for msg in newmessages: # print msg processor.handle(msg["message"], utils.stripJID(str(msg["jid"]))) newmessages = [] # Job #2: Check if there is anything to send. missions = utils.stack_get("outgoing") if missions: logger.info("New mission(s) accepted. Distributing them to clients.") for mission in missions: for each in self.clients: if not each[0].isAlive(): continue each[1].append(mission) logger.info("Will try sending messages(if any).") for each in self.clients: if not each[1]: continue if not each[0].isAlive(): logger.debug("[%s] is not alive. Will omit its job." % each[0].jid) continue if not each[0].connect_status == 2: logger.debug( "[%s] is not connected(Status: %s). Will omit its job." % (each[0].jid, each[0].connect_status) ) continue if each[0].xmpp.client_roster or True: # XXX This hack enables forcing each account to send. mission = each[1].pop(0) possible_jids = entity.getJIDsByNickname(mission["receiver"]) if possible_jids == False: continue for jid in possible_jids: if utils.stripJID(jid) == utils.stripJID(each[0].jid): continue if jid in each[0].xmpp.client_roster.keys() or True: # The same with XXX logger.debug("Set [%s] a new mission." % each[0].jid) each[0].setMessage(jid, mission["message"]) # Do WatchDog self.watchDog() # Now All Job Done time.sleep(0.1) logger.info("Exit the program.") for each in self.clients: each[0].terminate() each[0].join(10) if each[0].isAlive(): try: each[0].abort() except: pass
op = OptionParser() op.add_option("-i","--input",action="store",dest="input",default=False,help="Set the input file to be handled.") op.add_option("-r","--receiver",action="store",dest="receiver",default=False,help="Specify the receiver(NICKNAME, defined in configs/alias.cfg).") op.add_option("-t","--tag",action="store",dest="tag",default="im",help="Change message tag(default: im).") op.add_option("-x","--xi",action="store_true", dest="usexi", default=False,help="Use xi system to encrypt. OVERRIDES user's decision in inputbox if any!") op.add_option("-f","--flush",action="store_true",dest="omit",default=False,help="CAUTION: Omit any input, only push Xi generated messages(if any).") (options,args) = op.parse_args() myname = utils.myname recname = options.receiver if not str(recname).strip(): print "Please specify your intended audience by: -r/--receiver NICKNAME" exit() if not (options.omit or entity.getJIDsByNickname(recname)): print "Unrecognized receiver nickname." exit() if not options.omit: # Read file to get message if options.input == False: print "You must specify where to read input." exit() else: try: fp = open(options.input,'r') message = fp.read() fp.close() except Exception,e: print "File reading error: %s" % e