Remove printer import, remove vendor&device configuration, update

print_queue
This commit is contained in:
n07070
2026-06-03 23:53:02 +02:00
parent 1218d3fbee
commit db7e030a1f

View File

@@ -36,7 +36,6 @@ import werkzeug.exceptions
from flask_socketio import SocketIO
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address
from printer import Printer # The wrapper for the printer class
from raspberry import Raspberry # The Raspberry pi control Class
from web import Web # Wrapper for the web routes and API
from print_queue import PrintQueue
@@ -73,11 +72,7 @@ except OSError as e:
app.logger.debug("Config file loaded !")
# Define the USB connections here.
vendor_id = configuration_file["printer"]["vendor_id"]
device_id = configuration_file["printer"]["device_id"]
UPLOAD_FOLDER = str(configuration_file["printer"]["upload_folder"])
try:
os.mkdir(UPLOAD_FOLDER)
app.logger.debug("Directory %s created successfully.", UPLOAD_FOLDER)
@@ -98,13 +93,12 @@ app.config["ALLOWED_EXTENSIONS"] = ALLOWED_EXTENSIONS
app.config["MAX_CONTENT_LENGTH"] = 10 * 1000 * 1000 # Maximum 3Mb for a file upload
app.config["TEMPLATES_AUTO_RELOAD"] = True
# Printer connection
# Uses the class defined in the printer.py file
printer = Printer(app, 0x04B8, 0x0E28)
# Queue creation
print_queue = PrintQueue(app)
# Find out if we are running on a Raspberry Pi
rpi = Raspberry(
printer,
print_queue,
app,
socketio,
configuration_file["rpi"]["button_gpio_port_number"],
@@ -112,18 +106,20 @@ rpi = Raspberry(
configuration_file["rpi"]["flash_gpio_port_number"],
configuration_file["rpi"]["flash"],
)
RASPBERRY_PI_CONNECTED = rpi.is_raspberry_pi()
# Queue creation
print_queue = PrintQueue(app)
# Web & API management
web = Web(app, print_queue)
# Start worker thread
worker = PrintWorker(app, print_queue, printer, socketio)
# When created, the worker will try to find printers connected to the system
try:
worker = PrintWorker(app, print_queue, socketio)
worker.start()
except Exception as e:
app.logger.error("Could not start the worker because %s ", str(e))
sys.exit(-1)
# The rate limit
limiter = Limiter(
@@ -303,6 +299,7 @@ def api_print_image():
return "OK", 200
# TODO: This might not depend on the Raspberry Pi
@app.route("/api/camera/picture", methods=["GET"])
def camera_picture():
"""Returns a picture taken by the camera on a raspberry pi"""
@@ -320,6 +317,10 @@ def api_queue_status():
"""API endpoint for entire queue"""
return jsonify(web.get_queue_state())
@app.route("/api/queue/completed", methods=["GET"])
def api_queue_completed():
"""API endpoint that returns the finished tasks"""
return jsonify(web.get_queue_completed())
@app.route("/api/worker", methods=["GET"])
def api_worker_state():