X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;f=loctrkd%2F__main__.py;h=bba38ff1f1321f3ac76a62e69eefebe7db8c0bc9;hb=16bea55924c0ab9d035f3e99573fc49c370de231;hp=c3dcb4b35e379be6db682b200df163a7ee3105b3;hpb=dbdf9d63af31770ad57302e16b17a2fdc526773f;p=loctrkd.git diff --git a/loctrkd/__main__.py b/loctrkd/__main__.py index c3dcb4b..bba38ff 100644 --- a/loctrkd/__main__.py +++ b/loctrkd/__main__.py @@ -3,22 +3,31 @@ from configparser import ConfigParser from datetime import datetime, timezone from getopt import getopt +from importlib import import_module from logging import getLogger from sys import argv from time import time -from typing import List, Tuple +from typing import Any, cast, List, Tuple, Type, Union import zmq from . import common -from .zx303proto import * +from .protomodule import ProtoModule from .zmsg import Bcast, Resp log = getLogger("loctrkd") +pmods: List[ProtoModule] = [] + + def main( conf: ConfigParser, opts: List[Tuple[str, str]], args: List[str] ) -> None: + global pmods + pmods = [ + cast(ProtoModule, import_module("." + modnm, __package__)) + 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 zpush = zctx.socket(zmq.PUSH) # type: ignore @@ -31,7 +40,14 @@ def main( imei = args[0] cmd = args[1] args = args[2:] - cls = class_by_prefix(cmd) + handled = False + for pmod in pmods: + if pmod.proto_handled(cmd): + handled = True + break + if not handled: + raise NotImplementedError(f"No protocol can handle {cmd}") + cls = pmod.class_by_prefix(cmd) if isinstance(cls, list): raise ValueError("Prefix does not select a single class: " + str(cls)) kwargs = dict([arg.split("=") for arg in args])