X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;f=gps303%2Ftermconfig.py;h=723e8f62766ef542dbdb337ae015c66203ff1b9c;hb=18eda7307e92eeee6a9e2fdd2e810f98d25df654;hp=b9517f0af80284be60df5a4c4a6ef87bbaa9f9e9;hpb=d6c20543cf997f20cb72bf7380674bf012a5af88;p=loctrkd.git diff --git a/gps303/termconfig.py b/gps303/termconfig.py index b9517f0..723e8f6 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,10 +13,10 @@ 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 proto in ( STATUS.PROTO, @@ -23,7 +24,7 @@ def runserver(conf): POSITION_UPLOAD_INTERVAL.PROTO, ): zsub.setsockopt(zmq.SUBSCRIBE, topic(proto)) - zpush = zctx.socket(zmq.PUSH) + zpush = zctx.socket(zmq.PUSH) # type: ignore zpush.connect(conf.get("collector", "listenurl")) try: @@ -41,6 +42,12 @@ 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]) + elif conf.has_section("termconfig"): + termconfig = common.normconf(conf["termconfig"]) + else: + termconfig = {} kwargs = {} if isinstance(msg, STATUS): kwargs = { @@ -69,7 +76,9 @@ def runserver(conf): zpush.send(resp.packed) except KeyboardInterrupt: - pass + zsub.close() + zpush.close() + zctx.destroy() # type: ignore if __name__.endswith("__main__"):