X-Git-Url: http://www.average.org/gitweb/?a=blobdiff_plain;f=loctrkd%2Fqry.py;h=fc647c74c687b840d9fe9d2d63321d23f7b43c0f;hb=042f003133249fb38d87d92faa9c730833d14904;hp=e33ba16b1fcb9d5208de77ae611ea441f01e2ffb;hpb=e4f6256a6cd5a80e9afcaaa4033fa40d4d0b7ee9;p=loctrkd.git diff --git a/loctrkd/qry.py b/loctrkd/qry.py index e33ba16..fc647c7 100644 --- a/loctrkd/qry.py +++ b/loctrkd/qry.py @@ -10,20 +10,11 @@ from sys import argv from typing import Any, cast, List, Tuple from . import common +from .protomodule import ProtoModule log = getLogger("loctrkd/qry") -class ProtoModule: - @staticmethod - def proto_handled(proto: str) -> bool: - ... - - @staticmethod - def parse_message(packet: bytes, is_incoming: bool = True) -> Any: - ... - - pmods: List[ProtoModule] = [] @@ -33,7 +24,7 @@ def main( 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(",") ] db = connect(conf.get("storage", "dbfn")) c = db.cursor() @@ -43,6 +34,13 @@ def main( else: proto = "" selector = "" + dopts = dict(opts) + if len(args) > 1 and "-o" in dopts: + attr = args[1] + fn = dopts["-o"] + else: + attr = "" + fn = "" c.execute( """select tstamp, imei, peeraddr, is_incoming, proto, packet @@ -64,8 +62,11 @@ def main( peeraddr, msg, ) + if fn and hasattr(msg, attr): + with open(fn, "wb") as fl: # TODO support multiple files + fl.write(getattr(msg, attr)) if __name__.endswith("__main__"): - opts, args = getopt(argv[1:], "c:d") + opts, args = getopt(argv[1:], "o:c:d") main(common.init(log, opts=opts), opts, args)