X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;f=gps303%2Ftermconfig.py;h=953e6aec75f67ae380732d7f80dcfcc4cfa845ed;hb=428cb6396a46338d3681fca111f983cd5f8876d5;hp=9f9168409d6ddd21b0abf746d2d21ce5eae251c8;hpb=2cc29ee67b6432e1cd74a21b3c9181b8b5b557f9;p=loctrkd.git diff --git a/gps303/termconfig.py b/gps303/termconfig.py index 9f91684..953e6ae 100644 --- a/gps303/termconfig.py +++ b/gps303/termconfig.py @@ -1,5 +1,6 @@ """ For when responding to the terminal is not trivial """ +from configparser import ConfigParser from datetime import datetime, timezone from logging import getLogger from struct import pack @@ -12,19 +13,18 @@ from .zmsg import Bcast, Resp, topic log = getLogger("gps303/termconfig") -def runserver(conf): - termconfig = common.normconf(conf["termconfig"]) - zctx = zmq.Context() - zsub = zctx.socket(zmq.SUB) +def runserver(conf: ConfigParser) -> None: + # Is this https://github.com/zeromq/pyzmq/issues/1627 still not fixed?! + zctx = zmq.Context() # type: ignore + zsub = zctx.socket(zmq.SUB) # type: ignore zsub.connect(conf.get("collector", "publishurl")) - for protoname in ( - "STATUS", - "SETUP", - "POSITION_UPLOAD_INTERVAL", + for proto in ( + STATUS.PROTO, + SETUP.PROTO, + POSITION_UPLOAD_INTERVAL.PROTO, ): - tosub = topic(proto_by_name(protoname)) - zsub.setsockopt(zmq.SUBSCRIBE, tosub) - zpush = zctx.socket(zmq.PUSH) + zsub.setsockopt(zmq.SUBSCRIBE, topic(proto)) + zpush = zctx.socket(zmq.PUSH) # type: ignore zpush.connect(conf.get("collector", "listenurl")) try: @@ -42,6 +42,10 @@ def runserver(conf): log.error( "%s does not expect externally provided response", msg ) + if zmsg.imei is not None and conf.has_section(zmsg.imei): + termconfig = common.normconf(conf[zmsg.imei]) + else: + termconfig = common.normconf(conf["termconfig"]) kwargs = {} if isinstance(msg, STATUS): kwargs = {