def run(self): self._setup_sse() edr_log = EDRLog() try: for msg in self.sse: if msg.event is "keep-alive": edr_log.log(u"SSE keep-alive received", "DEBUG") continue if msg.event is "auth_revoked": edr_log.log(u"SSE auth_revoked received", "DEBUG") self.message_queue.put(msg) self.close() break if msg.event is "cancel": edr_log.log(u"SSE cancel received", "DEBUG") self.message_queue.put(msg) self.close() break edr_log.log( u"SSE msg received: {} {}".format(msg.event, msg.data), "DEBUG") self.message_queue.put(msg) except socket.error: pass # this can happen when we close the stream except requests.HTTPError: pass # this can happen when the auth is no longer valid
def __init__(self, config_file='config/igm_config.v7.ini', user_config_file=[ 'config/user_igm_config.v7.ini', 'config/user_igm_config.v6.ini' ]): self.config = cp.ConfigParser() self.fallback_config = cp.ConfigParser() self.fallback_config.read(utils2to3.abspathmaker( __file__, config_file)) user_cfg_path = utils2to3.abspathmaker(__file__, user_config_file[0]) if os.path.exists(user_cfg_path): EDRLog().log( u"Using user defined layout at {}.".format( user_config_file[0]), "INFO") self.config.read(user_cfg_path) else: EDRLog().log( u"No user defined layout at {}, using {} instead.".format( user_config_file[0], user_config_file[1]), "INFO") user_cfg_path = utils2to3.abspathmaker(__file__, user_config_file[1]) if os.path.exists(user_cfg_path): EDRLog().log( u"Using user defined layout at {}.".format( user_config_file[1]), "INFO") self.config.read(user_cfg_path) else: EDRLog().log( u"No user defined layout at {} or {}, using {} instead.". format(user_config_file[0], user_config_file[1], config_file), "INFO") self.config = self.fallback_config
def run(self): edr_log = EDRLog() while True: msg = self.inbound_queue.get() if not msg: edr_log.log(u"SSE stop signal received.", "DEBUG") break edr_log.log( u"handling msg: {} {} {}".format(msg.event, msg.data, self.kind), "DEBUG") if msg.event in ["put", "patch"] and msg.data: data = json.loads(msg.data) if data is None or data["data"] is None: continue if data["path"] == '/': # initial update keys = sorted(data["data"]) for k in keys: self.callback(self.kind, data["data"][k]) else: self.callback(self.kind, data["data"]) elif msg.event in ["cancel", "auth_revoked"]: self.callback(self.kind, msg.event)
from __future__ import absolute_import import edtime from edrlog import EDRLog EDRLOG = EDRLog() class EDRFleetCarrier(object): def __init__(self): self.id = None self.callsign = None self.name = None self.access = "none" self.allow_notorious = False self._position = {"system": None, "body": None} self.departure = {"time": None, "destination": None} self.decommission_time = None def __reset(self): self.id = None self.callsign = None self.name = None self.access = "none" self.allow_notorious = False self._position = {"system": None, "body": None} self.departure = {"time": None, "destination": None} self.decommission_time = None def bought(self, buy_event): self.__reset() self.id = buy_event.get("CarrierID", None) self.callsign = buy_event.get("Callsign", None) self._position["system"] = buy_event.get("Location", None)