def processMessage(self, xmsg, addr, eventTime, newPeer, fromQueue): """ process any message event, including lunch calls @type xmsg: extMessageIncoming @type addr: unicode @type eventTime: float @type newPeer: bool @type fromQueue: bool """ mtime = localtime(eventTime) t = strftime("%a, %d %b %Y %H:%M:%S", mtime).decode("utf-8") msg = xmsg.getPlainMessage() if not newPeer: with get_peers(): m = get_peers().getPeerInfo(pIP=addr, lock=False) peerName = get_peers().getDisplayedPeerName(pIP=addr, lock=False) if m is None: getCoreLogger().error("Error processing message: info dict is None") else: if peerName is None: peerName = m.get(LunchPeers.PEER_NAME_KEY, "<unknown>") getCoreLogger().info("%s: [%s (%s)] %s", t, peerName, m[LunchPeers.PEER_ID_KEY], msg) self._insertMessage(mtime, m[LunchPeers.PEER_ID_KEY], msg) get_notification_center().emitMessagePrepended(mtime, m[LunchPeers.PEER_ID_KEY], msg) else: m = {u"ID": addr} processLunchCall = False #deprecated: self.processPluginCall(addr, lambda p, ip, member_info: p.process_message(msg, ip, member_info), newPeer, fromQueue) #the next block could be one huge statement, but for readability I leave it as is if get_settings().get_lunch_trigger() in msg.lower(): # the message contains the lunch keyword if eventTime - self.last_lunch_call > get_settings().get_mute_timeout() or \ fromQueue and self.last_lunch_call == eventTime: # it has not been reported before # the call has not been during the mute_timeout or # this is a queued lunch call that previously wasn't muted diff = getTimeDifference(get_settings().get_alarm_begin_time(), get_settings().get_alarm_end_time(), getCoreLogger()) if diff == None or 0 < diff: # either the time format is invalid or we are within the alarm time processLunchCall = True else: diff = getTimeDifference(get_settings().get_next_lunch_begin(), get_settings().get_next_lunch_end(), getCoreLogger()) if diff == None or 0 < diff: # either the time format is invalid or we are within the free for lunch time processLunchCall = True if processLunchCall: self.last_lunch_call = eventTime #deprecated: self.processPluginCall(addr, lambda p, ip, member_info: p.process_lunch_call(msg, ip, member_info), newPeer, fromQueue) else: getCoreLogger().debug("messages will not trigger alarm: %s: [%s] %s until %s (unless you change the setting, that is)", t, m, msg, strftime("%H:%M:%S", localtime(eventTime + get_settings().get_mute_timeout()))) self.processPluginCall(addr, lambda p, ip, member_info: p.process_group_message(xmsg, ip, member_info, processLunchCall), newPeer, fromQueue)
def _checkOK(self): if self.getEndTime() < self.getBeginTime(): self._error(u"End time is before begin time.") elif self._checkBeforeNow and \ getTimeDifference(self.getBeginTimeString(), self.getEndTimeString(), getCoreLogger()) == 0: self._error(u"The time span is already over.") else: self.accept()
def _checkInfoForReady(self, p_info): if p_info and p_info.has_key(self.NEXT_LUNCH_BEGIN_KEY) and p_info.has_key(self.NEXT_LUNCH_END_KEY): diff = getTimeDifference(p_info[self.NEXT_LUNCH_BEGIN_KEY], p_info[self.NEXT_LUNCH_END_KEY], self.logger) if diff == None: # illegal format, just assume ready return True return diff > 0 else: # no lunch time information (only happening with very old lunchinators), assume ready return True
def isPeerReadinessKnown(self, ip): """returns True if there is a valid lunch time interval for the peer""" if ip in self._peer_info: p_info = self._peer_info[ip] if p_info and p_info.has_key(self.NEXT_LUNCH_BEGIN_KEY) and p_info.has_key(self.NEXT_LUNCH_END_KEY): diff = getTimeDifference( p_info[self.NEXT_LUNCH_BEGIN_KEY], p_info[self.NEXT_LUNCH_END_KEY], self.logger ) if diff != None: # valid format return True return False
def _updateLunchTimeItem(self, peerID, infoDict, item): if infoDict is None: # peer is not there any more and should be removed soon anyways return isMember = self.dataSource.isMember(pID=peerID) if self._LUNCH_BEGIN_KEY in infoDict and self._LUNCH_END_KEY in infoDict: item.setText(infoDict[self._LUNCH_BEGIN_KEY]+"-"+infoDict[self._LUNCH_END_KEY]) try: beginTime = datetime.strptime(infoDict[self._LUNCH_BEGIN_KEY], lunch_settings.LUNCH_TIME_FORMAT) beginTime = beginTime.replace(year=2000) item.setData(QVariant(time.mktime(beginTime.timetuple())), self.SORT_ROLE) timeDifference = getTimeDifference(infoDict[self._LUNCH_BEGIN_KEY],infoDict[self._LUNCH_END_KEY], self.logger) if timeDifference != None: if timeDifference > 0: item.setData(self._green if isMember else self._grayGreen, Qt.DecorationRole) else: item.setData(self._red if isMember else self._grayRed, Qt.DecorationRole) except ValueError: self.logger.debug("Ignoring illegal lunch time: %s", infoDict[self._LUNCH_BEGIN_KEY]) else: item.setData(QVariant(-1), self.SORT_ROLE) self._grayOutIfNoMember(item, peerID)