Introduce logging
This commit is contained in:
parent
51ce2e6ff0
commit
a8f007d421
@ -1,11 +1,14 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import logging
|
||||||
import selectors
|
import selectors
|
||||||
import socket
|
import socket
|
||||||
import socketserver
|
import socketserver
|
||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
logger = logging.getLogger("fieldpoc.controller")
|
||||||
|
|
||||||
class Controller:
|
class Controller:
|
||||||
def __init__(self, fp):
|
def __init__(self, fp):
|
||||||
self.fp = fp
|
self.fp = fp
|
||||||
@ -63,6 +66,7 @@ exit Disconnect
|
|||||||
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
logger.info("starting server")
|
||||||
class Server(socketserver.ThreadingTCPServer):
|
class Server(socketserver.ThreadingTCPServer):
|
||||||
allow_reuse_address = True
|
allow_reuse_address = True
|
||||||
|
|
||||||
@ -75,6 +79,7 @@ exit Disconnect
|
|||||||
self.fp.queues["controller"].task_done()
|
self.fp.queues["controller"].task_done()
|
||||||
|
|
||||||
if msg.get("type") == "stop":
|
if msg.get("type") == "stop":
|
||||||
|
logger.info("stopping server")
|
||||||
server.shutdown()
|
server.shutdown()
|
||||||
for h in self.handlers:
|
for h in self.handlers:
|
||||||
h.send(b'\0')
|
h.send(b'\0')
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import logging
|
||||||
import mitel_ommclient2
|
import mitel_ommclient2
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
logger = logging.getLogger("fieldpoc.dect")
|
||||||
|
|
||||||
class Dect:
|
class Dect:
|
||||||
def __init__(self, fp):
|
def __init__(self, fp):
|
||||||
self.fp = fp
|
self.fp = fp
|
||||||
@ -30,6 +33,7 @@ class Dect:
|
|||||||
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
logger.info("initialising connection to OMM")
|
||||||
self._init_client()
|
self._init_client()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
import pathlib
|
import pathlib
|
||||||
import queue
|
import queue
|
||||||
import threading
|
import threading
|
||||||
@ -9,21 +10,26 @@ from . import config
|
|||||||
from . import controller
|
from . import controller
|
||||||
from . import dect
|
from . import dect
|
||||||
|
|
||||||
|
logger = logging.getLogger("fieldpoc.fieldpoc")
|
||||||
|
|
||||||
class FieldPOC:
|
class FieldPOC:
|
||||||
config = None
|
config = None
|
||||||
extensions = None
|
extensions = None
|
||||||
|
|
||||||
def __init__(self, config_file_path, extensions_file_path):
|
def __init__(self, config_file_path, extensions_file_path):
|
||||||
|
logger.info("loading configuration")
|
||||||
self.config_file_path = pathlib.Path(config_file_path)
|
self.config_file_path = pathlib.Path(config_file_path)
|
||||||
self._load_config()
|
self._load_config()
|
||||||
self.extensions_file_path = pathlib.Path(extensions_file_path)
|
self.extensions_file_path = pathlib.Path(extensions_file_path)
|
||||||
self._load_extensions()
|
self._load_extensions()
|
||||||
|
|
||||||
|
logger.info("initialising queues")
|
||||||
self.queues = {
|
self.queues = {
|
||||||
"controller": queue.Queue(),
|
"controller": queue.Queue(),
|
||||||
"dect": queue.Queue(),
|
"dect": queue.Queue(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info("initialising components")
|
||||||
self._controller = controller.Controller(self)
|
self._controller = controller.Controller(self)
|
||||||
self._dect = dect.Dect(self)
|
self._dect = dect.Dect(self)
|
||||||
|
|
||||||
@ -36,12 +42,16 @@ class FieldPOC:
|
|||||||
queue.put(msg)
|
queue.put(msg)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
logger.info("stating components")
|
||||||
|
|
||||||
self._controller_thread = threading.Thread(target=self._controller.run)
|
self._controller_thread = threading.Thread(target=self._controller.run)
|
||||||
self._controller_thread.start()
|
self._controller_thread.start()
|
||||||
|
|
||||||
self._dect_thread = threading.Thread(target=self._dect.run)
|
self._dect_thread = threading.Thread(target=self._dect.run)
|
||||||
self._dect_thread.start()
|
self._dect_thread.start()
|
||||||
|
|
||||||
|
logger.info("started components")
|
||||||
|
|
||||||
def _load_config(self):
|
def _load_config(self):
|
||||||
self.config = config.Config(json.loads(self.config_file_path.read_text()))
|
self.config = config.Config(json.loads(self.config_file_path.read_text()))
|
||||||
|
|
||||||
|
@ -1,17 +1,25 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import logging
|
||||||
import selectors
|
import selectors
|
||||||
import signal
|
import signal
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
from . import fieldpoc
|
from . import fieldpoc
|
||||||
|
|
||||||
|
logger = logging.getLogger("fieldpoc.run")
|
||||||
|
|
||||||
ap = argparse.ArgumentParser(prog="fieldpoc")
|
ap = argparse.ArgumentParser(prog="fieldpoc")
|
||||||
ap.add_argument("-c", "--config", dest="config_file_path", default="fieldpoc_config.json", help="Path to the fieldpoc config file")
|
ap.add_argument("-c", "--config", dest="config_file_path", default="fieldpoc_config.json", help="Path to the fieldpoc config file")
|
||||||
ap.add_argument("-e", "--extensions", dest="extensions_file_path", default="fieldpoc_extensions.json", help="Path to the fieldpoc extensions file")
|
ap.add_argument("-e", "--extensions", dest="extensions_file_path", default="fieldpoc_extensions.json", help="Path to the fieldpoc extensions file")
|
||||||
|
ap.add_argument('--debug', dest="debug", action='store_true')
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
|
args = ap.parse_args()
|
||||||
|
if args.debug:
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
||||||
sel = selectors.DefaultSelector()
|
sel = selectors.DefaultSelector()
|
||||||
|
|
||||||
interrupt_stop_read, interrupt_stop_write = socket.socketpair()
|
interrupt_stop_read, interrupt_stop_write = socket.socketpair()
|
||||||
@ -22,17 +30,23 @@ def run():
|
|||||||
signal.signal(signal.SIGHUP, lambda signum, frame: interrupt_reload_write.send(b'\0'))
|
signal.signal(signal.SIGHUP, lambda signum, frame: interrupt_reload_write.send(b'\0'))
|
||||||
sel.register(interrupt_reload_read, selectors.EVENT_READ)
|
sel.register(interrupt_reload_read, selectors.EVENT_READ)
|
||||||
|
|
||||||
args = ap.parse_args()
|
logger.info("prepared signal handling")
|
||||||
fp = fieldpoc.FieldPOC(**args.__dict__)
|
|
||||||
|
fp = fieldpoc.FieldPOC(config_file_path=args.config_file_path, extensions_file_path=args.extensions_file_path)
|
||||||
fp.run()
|
fp.run()
|
||||||
|
|
||||||
|
logger.info("handle signals")
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
for key, mask in sel.select():
|
for key, mask in sel.select():
|
||||||
|
logger.info("incoming signal")
|
||||||
key.fileobj.recv(1)
|
key.fileobj.recv(1)
|
||||||
if key.fileobj == interrupt_stop_read:
|
if key.fileobj == interrupt_stop_read:
|
||||||
|
logger.info("signal requested service stop")
|
||||||
fp.queue_all({"type": "stop"})
|
fp.queue_all({"type": "stop"})
|
||||||
exit()
|
exit()
|
||||||
elif key.fileobj == interrupt_reload_read:
|
elif key.fileobj == interrupt_reload_read:
|
||||||
|
logger.info("signal requested reload")
|
||||||
fp.queue_all({"type": "reload"})
|
fp.queue_all({"type": "reload"})
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user