Add docstring & comments, remove dead code

This commit is contained in:
n07070
2026-05-22 10:43:38 +02:00
parent 20f1145b60
commit 1ba3d1bee3

View File

@@ -101,9 +101,6 @@ app.config["TEMPLATES_AUTO_RELOAD"] = True
# Printer connection # Printer connection
# Uses the class defined in the printer.py file # Uses the class defined in the printer.py file
printer = Printer(app, 0x04B8, 0x0E28) printer = Printer(app, 0x04B8, 0x0E28)
# printers = Printer(app)
# printers.discover_printers()
# printers.init()
printer.init_printer() printer.init_printer()
# Find out if we are running on a Raspberry Pi # Find out if we are running on a Raspberry Pi
@@ -122,20 +119,19 @@ RASPBERRY_PI_CONNECTED = rpi.is_raspberry_pi()
# Queue creation # Queue creation
print_queue = PrintQueue(app) print_queue = PrintQueue(app)
# Web & API routes # Web & API management
web = Web(app, print_queue) web = Web(app, print_queue)
# Start worker thread # Start worker thread
worker = PrintWorker(app, print_queue, printer, socketio) worker = PrintWorker(app, print_queue, printer, socketio)
worker.start() worker.start()
# The rate limit
limiter = Limiter( limiter = Limiter(
get_remote_address, app=app, default_limits=["1500 per day", "500 per hour"] get_remote_address, app=app, default_limits=["1500 per day", "500 per hour"]
) )
# General routes # General routes
@app.route("/") @app.route("/")
@limiter.limit("1/second", override_defaults=False) @limiter.limit("1/second", override_defaults=False)
def index(): def index():
@@ -153,8 +149,6 @@ def webcam():
# Form treatement # Form treatement
@app.route("/web/print/sms", methods=["POST"]) @app.route("/web/print/sms", methods=["POST"])
@limiter.limit("6/minute", override_defaults=False) @limiter.limit("6/minute", override_defaults=False)
def web_print_sms(): def web_print_sms():
@@ -185,7 +179,7 @@ def web_print_sms():
return redirect(url_for("index")) return redirect(url_for("index"))
# end try # end try
flash("The SMS has been printed !", "info") flash("The SMS has been added to the print queue !", "info")
return redirect(url_for("index")) return redirect(url_for("index"))
@@ -227,7 +221,7 @@ def web_print_img():
flash("The image could not be printed because : " + str(e), "error") flash("The image could not be printed because : " + str(e), "error")
return redirect(url_for("index")) return redirect(url_for("index"))
flash("Picture printed !", "info") flash("Picture added to the print queue !", "info")
return redirect(url_for("index")) return redirect(url_for("index"))
@@ -296,8 +290,7 @@ def api_print_image():
return "No image submitted", 400 return "No image submitted", 400
file = request.files["img"] file = request.files["img"]
# If the user does not select a file, the browser submits an # If the user submits an empty file without a filename.
# empty file without a filename.
if file.filename == "": if file.filename == "":
app.logger.error("Submitted file has no filename !") app.logger.error("Submitted file has no filename !")
return "Submitted file has no filename !", 400 return "Submitted file has no filename !", 400
@@ -337,12 +330,18 @@ def api_worker_state():
@app.route("/api/worker/start") @app.route("/api/worker/start")
def api_worker_start(): def api_worker_start():
"""
Enable to worker. This starts to process the print queue.
"""
worker.start_worker() worker.start_worker()
return jsonify(worker.current_state()) return jsonify(worker.current_state())
@app.route("/api/worker/stop") @app.route("/api/worker/stop")
def api_worker_stop(): def api_worker_stop():
"""
Stops the print queue. This stops the processing of the print queue.
"""
worker.stop_worker() worker.stop_worker()
return jsonify(worker.current_state()) return jsonify(worker.current_state())