X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;f=loctrkd%2Fwatch.py;h=8e962bc2278dcef0b8eda170116dae0be702df2a;hb=9bf81b19b7b790bc2115ac08dc1f3c112aede976;hp=ab041edc832c7ae78198ea5deb3375d9e32dff29;hpb=63a086cf3956b93f760b1a0344afd757e0d0392f;p=loctrkd.git diff --git a/loctrkd/watch.py b/loctrkd/watch.py index ab041ed..8e962bc 100644 --- a/loctrkd/watch.py +++ b/loctrkd/watch.py @@ -8,19 +8,12 @@ from typing import Any, cast, List import zmq from . import common +from .protomodule import ProtoModule from .zmsg import Bcast log = getLogger("loctrkd/watch") -class ProtoModule: - PROTO_PREFIX: str - - @staticmethod - def parse_message(packet: bytes, is_incoming: bool = True) -> Any: - ... - - pmods: List[ProtoModule] = [] @@ -28,7 +21,7 @@ def runserver(conf: ConfigParser) -> None: global pmods pmods = [ cast(ProtoModule, import_module("." + modnm, __package__)) - for modnm in conf.get("collector", "protocols").split(",") + for modnm in conf.get("common", "protocols").split(",") ] # Is this https://github.com/zeromq/pyzmq/issues/1627 still not fixed?! zctx = zmq.Context() # type: ignore @@ -39,11 +32,11 @@ def runserver(conf: ConfigParser) -> None: try: while True: zmsg = Bcast(zsub.recv()) - print("Bcast:", zmsg) + print("I" if zmsg.is_incoming else "O", zmsg.proto, zmsg.imei) for pmod in pmods: - if zmsg.proto.startswith(pmod.PROTO_PREFIX): + if pmod.proto_handled(zmsg.proto): msg = pmod.parse_message(zmsg.packet, zmsg.is_incoming) - print("I" if zmsg.is_incoming else "O", zmsg.imei, msg) + print(msg) except KeyboardInterrupt: pass