diff --git a/comm/__init__.py b/comm/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/comm/main.py b/comm/main.py deleted file mode 100644 index d240481..0000000 --- a/comm/main.py +++ /dev/null @@ -1,72 +0,0 @@ -''' -Created on 19 mar 2020 - -@author: Emanuele Trabattoni -@copyright: Briq srl -@contact: Scritto per Briq srl come collaboratore esterno, contiene dei frammenti di codice di proprieta' di Briq srl -''' - -from flask import Flask, escape, request -import threading -import multiprocessing -import sys -import logging -from waitress import serve -import os - -app = Flask(__name__) - -#questo manda le rest di risposta a django -@app.route('/markoprinter//', methods=['POST']) -def hello(mac, command): - parameters = request.get_json() - print(mac, command, parameters) - queue_id = printer_manager.get_queue_id(mac) - print(mac) - print(printer_manager.mappa_mac) - if queue_id is not None and queue_id in queues_in: - print("trovata") - queues_in[queue_id].put({'name': command, 'parameters': parameters}) - return "Inviato", 200 - else: - print("non trovata") - return "Stampante non trovata", 404 - - -def build_logger(): - logger = logging.getLogger(__name__) - logger.setLevel(logging.INFO) - logger.propagate = False - formatter = logging.Formatter(("%(asctime)s|%(levelname)-7s|%(funcName)-10s|%(lineno)-3d: %(message)-50s"), - ("%m-%d %H:%M:%S")) - # File Logging - fh = logging.FileHandler(("./log/dimelog.log")) - fh.setLevel(logging.DEBUG) - fh.setFormatter(formatter) - logger.addHandler(fh) - # Console Logging - cl = logging.StreamHandler(sys.stdout) - cl.setLevel(logging.DEBUG) - cl.setFormatter(formatter) - logger.addHandler(cl) - return logger - - -if __name__ == '__main__': - logger = build_logger() - queues_in = {} - queue_out = multiprocessing.Queue() - django_addr = ("http://{}:{}/" - .format(os.getenv('DJANGO_HOST', '127.0.0.1'), - os.getenv('DJANGO_PORT'))) - t_notify_django = threading.Thread(target=notify_django.notifier, - args=[django_addr, queue_out, logger], - daemon=True) - t_notify_django.start() - t_print = threading.Thread(target=printer_manager.main, - args=[queues_in, queue_out, logger], - daemon=True) - t_print.start() - listen = "{}:{}".format(os.getenv("MARKOPRINTER_DRIVER_HOST"), - os.getenv("MARKOPRINTER_DRIVER_PORT")) - serve(app, listen=listen) \ No newline at end of file diff --git a/driver/main.py b/driver/main.py index 9ce4415..ee919b0 100644 --- a/driver/main.py +++ b/driver/main.py @@ -2,7 +2,71 @@ Created on 19 mar 2020 @author: Emanuele Trabattoni +@copyright: Briq srl +@contact: Scritto per Briq srl come collaboratore esterno, contiene dei frammenti di codice di proprieta' di Briq srl ''' +from flask import Flask, escape, request +import threading +import multiprocessing +import sys +import logging +from waitress import serve +import os + +app = Flask(__name__) + +#questo manda le rest di risposta a django +@app.route('/markoprinter//', methods=['POST']) +def hello(mac, command): + parameters = request.get_json() + print(mac, command, parameters) + queue_id = printer_manager.get_queue_id(mac) + print(mac) + print(printer_manager.mappa_mac) + if queue_id is not None and queue_id in queues_in: + print("trovata") + queues_in[queue_id].put({'name': command, 'parameters': parameters}) + return "Inviato", 200 + else: + print("non trovata") + return "Stampante non trovata", 404 + + +def build_logger(): + logger = logging.getLogger(__name__) + logger.setLevel(logging.INFO) + logger.propagate = False + formatter = logging.Formatter(("%(asctime)s|%(levelname)-7s|%(funcName)-10s|%(lineno)-3d: %(message)-50s"), + ("%m-%d %H:%M:%S")) + # File Logging + fh = logging.FileHandler(("./log/dimelog.log")) + fh.setLevel(logging.DEBUG) + fh.setFormatter(formatter) + logger.addHandler(fh) + # Console Logging + cl = logging.StreamHandler(sys.stdout) + cl.setLevel(logging.DEBUG) + cl.setFormatter(formatter) + logger.addHandler(cl) + return logger + + if __name__ == '__main__': - pass \ No newline at end of file + logger = build_logger() + queues_in = {} + queue_out = multiprocessing.Queue() + django_addr = ("http://{}:{}/" + .format(os.getenv('DJANGO_HOST', '127.0.0.1'), + os.getenv('DJANGO_PORT'))) + #t_notify_django = threading.Thread(target=notify_django.notifier, + # args=[django_addr, queue_out, logger], + # daemon=True) + #t_notify_django.start() + t_print = threading.Thread(target=printer_manager.main, + args=[queues_in, queue_out, logger], + daemon=True) + t_print.start() + listen = "{}:{}".format(os.getenv("MARKOPRINTER_DRIVER_HOST"), + os.getenv("MARKOPRINTER_DRIVER_PORT")) + serve(app, listen=listen) \ No newline at end of file diff --git a/driver/tsc_manager.py b/driver/tsc_manager.py new file mode 100644 index 0000000..30479bc --- /dev/null +++ b/driver/tsc_manager.py @@ -0,0 +1,25 @@ +''' +Created on 19 mar 2020 + +@author: Emanuele Trabattoni +@copyright: Briq srl +@contact: Scritto per Briq srl come collaboratore esterno, contiene dei frammenti di codice di proprieta' di Briq srl +''' + +import threading, socket, sys, queue + +Q_TIMEOUT = 2 + +def stampante(q_in, q_out, ip, ): + + +#lancia i thread, uno per stampante +def main(q_in :queue.Queue, q_out :queue.Queue, q_comm: queue.Queue, logger): + while True: + try: + q_comm.get(block=True, timeout=Q_TIMEOUT) + except Empty: + + + pass +