cambiati i nomi dei package
parent
687623a6d0
commit
81185b11c6
72
comm/main.py
72
comm/main.py
|
|
@ -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/<mac>/<command>', 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)
|
|
||||||
|
|
@ -2,7 +2,71 @@
|
||||||
Created on 19 mar 2020
|
Created on 19 mar 2020
|
||||||
|
|
||||||
@author: Emanuele Trabattoni
|
@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/<mac>/<command>', 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__':
|
if __name__ == '__main__':
|
||||||
pass
|
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)
|
||||||
|
|
@ -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
|
||||||
|
|
||||||
Loading…
Reference in New Issue