From 4ae2ea185853f4d15bc4720746febf568e2c2b6a Mon Sep 17 00:00:00 2001 From: Mendel Mobach Date: Fri, 22 Nov 2024 13:34:53 +0100 Subject: [PATCH 01/14] nu met betere stickers :) --- kassa.py | 25 ++++---- plugins/accounts.py | 8 ++- plugins/stickers.py | 151 +++++++++++++++++++++++++------------------- plugins/undo.py | 7 +- requirements.in | 2 + 5 files changed, 109 insertions(+), 84 deletions(-) diff --git a/kassa.py b/kassa.py index 86ff5b4..6a530db 100755 --- a/kassa.py +++ b/kassa.py @@ -101,16 +101,15 @@ def callhook(self, hook, arg): def donext(self, plug, function): self.nextcall = {"plug": plug, "function": function} - - def input(self, text): + def input(self, text): # pylint: disable=too-many-branches if not text: self.send_message(True, "message", "Enter product, command or username") self.send_message(True, "buttons", json.dumps({})) return - + self.buttons = {} done = 0 - + for plug, plugin in self.plugins.items(): try: plugin.pre_input(text) @@ -118,9 +117,9 @@ def input(self, text): pass except: print(traceback.format_exc()) - + self.prompt = "" - + if self.nextcall: try: plug = self.nextcall["plug"] @@ -133,22 +132,22 @@ def input(self, text): done = 1 except: print(traceback.format_exc()) - + if done == 0: parts = text.split() for part in parts: if part: done = self.handle_part(part) # Call handle_part for each part - + if done == 1 and not self.prompt: self.send_message(True, "message", "Enter product, command or username") elif not self.prompt: self.send_message(True, "message", "Unknown product, command or username") self.callhook("wrong", ()) - + if not self.nextcall and not self.buttons: self.send_message(True, "buttons", json.dumps({})) - + def handle_part(self, part): done = 0 if self.nextcall: @@ -160,7 +159,7 @@ def handle_part(self, part): done = 1 except: print(traceback.format_exc()) - + if done == 0: for plug, plugin in self.plugins.items(): try: @@ -171,13 +170,13 @@ def handle_part(self, part): print(traceback.format_exc()) except: print(traceback.format_exc()) - + if done == 0: if self.plugins.get("withdraw") and self.plugins["withdraw"].withdraw(part): done = 1 if self.plugins.get("accounts") and self.plugins["accounts"].newuser(part): done = 1 - + return done def send_message(self, retain, topic, message): diff --git a/plugins/accounts.py b/plugins/accounts.py index 6cb4309..b46111c 100644 --- a/plugins/accounts.py +++ b/plugins/accounts.py @@ -19,9 +19,13 @@ def help(self): def get_last_updated_accounts(self): # Sort the accounts based on last update time, in descending order - sorted_accounts = sorted(self.accounts.items(), key=lambda x: x[1]['lastupdate'], reverse=True) + sorted_accounts = sorted( + self.accounts.items(), key=lambda x: x[1]["lastupdate"], reverse=True + ) # Extract the account names from the sorted list - account_names = [account[0] for account in sorted_accounts if account[0] not in self.members][0:125] + account_names = [ + account[0] for account in sorted_accounts if account[0] not in self.members + ][0:125] self.master.send_message(True, "nonmembers", json.dumps(account_names)) # Internal functions diff --git a/plugins/stickers.py b/plugins/stickers.py index f8451b2..74880a7 100644 --- a/plugins/stickers.py +++ b/plugins/stickers.py @@ -1,25 +1,28 @@ # -*- coding: utf-8 -*- -import os import traceback import json import re -import time import io import base64 +import urllib from PIL import Image, ImageDraw, ImageFont import pyqrcode import cups +import brother_ql.conversion +import brother_ql.backends.helpers +import brother_ql.raster class stickers: - SMALL = (690, 271) + SMALL = (696, 271) LOGOSMALLSIZE = (309, 200) WHITE = (255, 255, 255) BLACK = (0, 0, 0) LOGOFILE = "images/hack42.png" FONT = "images/arialbd.ttf" printer = "QL710W" - printer = "QL710W" + PRINTER = "tcp://172.16.22.149:9100" + MODEL = "QL-810W" SPACE = ( 0 # spacing around qrcode, should be 4 but our printer prints on white labels ) @@ -134,55 +137,58 @@ def thtprint(self): options={"copies": str(self.copies), "page-ranges": "1"}, ) - def toolprint(self): - if re.compile("^[0-9A-Z]+$").match(self.name): + def toolprint(self): # pylint: disable=too-many-locals + FONTSIZE = 80 + LABELSIZE = 696 # 62 mm at 300 DPI + MARGIN = 32 + qrname = "https://hack42.nl/wiki/Tool:" + urllib.parse.quote( + self.name.replace(" ", "_") + ) + if re.compile("^[0-9A-Z]+$").match(qrname): print("Qrcode: alphanum") - qrcode_image = pyqrcode.create( - self.name, error="L", version=1, mode="alphanumeric" - ).png_as_base64_str(scale=5) + qrcode_image = pyqrcode.create(qrname, error="L", mode="alphanumeric") else: print("Qrcode: binary") - qrcode_image = pyqrcode.create( - self.name, error="L", version=2, mode="binary" - ).png_as_base64_str(scale=5) - - # Create an image object - img = Image.new("RGB", self.SMALL, self.WHITE) + qrcode_image = pyqrcode.create(qrname, error="L", mode="binary") + qrcode_image = qrcode_image.png_as_base64_str( + scale=int((LABELSIZE - MARGIN) / qrcode_image.get_png_size()) + ) + font = ImageFont.truetype(self.FONT, FONTSIZE) + txtsize = font.getbbox(self.name) + imagewidth = ( + LABELSIZE if txtsize[2] < (LABELSIZE - MARGIN) else txtsize[2] + MARGIN, + LABELSIZE, + ) + img = Image.new("RGB", imagewidth, self.WHITE) draw = ImageDraw.Draw(img) - - # Load the QR code as an image qrcode_img = Image.open(io.BytesIO(base64.b64decode(qrcode_image))) - - # Calculate size for QR code - size = self.SMALL[1] // (qrcode_img.size[0] + 4 * self.SPACE) - qrcode_img = qrcode_img.resize( - (size * qrcode_img.size[0], size * qrcode_img.size[1]), - resample=Image.LANCZOS, # pylint: disable=no-member + img.paste(qrcode_img, (int((imagewidth[0] - (LABELSIZE - MARGIN)) / 2), 10)) + txtstart = int((LABELSIZE - txtsize[2]) / 2) + draw.text( + (txtstart, int(LABELSIZE - 20 - FONTSIZE)), + self.name, + fill=self.BLACK, + font=font, ) - - # Place QR code on the image - img.paste(qrcode_img, (self.SPACE, self.SPACE)) - - # Load a font - font = ImageFont.truetype(self.FONT, 40) - - # Add text to the image - draw.text((64, self.SMALL[1]), self.name, fill=self.BLACK, font=font) - - # Save the image - img.save("data/toollabel.jpg", "JPEG", dpi=(300, 300)) - - # Print the file - options={"copies": str(self.copies), "page-ranges": "1", "media": "media=custom_61.98x100mm_61.98x100mm"} - cups.Connection().printFile( # pylint: disable=no-member - self.printer, - "data/toollabel.jpg", - title="Toollabel", - options=options, + qlr = brother_ql.raster.BrotherQLRaster(self.MODEL) + qlr.exception_on_warning = True + printoptions = { + "rotate": "90", + "label": "62", + "images": (img,), + "threshold": 70.0, + "dither": False, + "compress": False, + "red": False, + "dpi_600": False, + "lq": True, + "cut": True, + } + instructions = brother_ql.conversion.convert(qlr=qlr, **printoptions) + brother_ql.backends.helpers.send( + instructions=instructions, printer_identifier=self.PRINTER, blocking=True ) - - def eigendomprint(self): img = Image.new("RGB", self.SMALL, self.WHITE) draw = ImageDraw.Draw(img) @@ -195,34 +201,49 @@ def eigendomprint(self): first = 10 last = 190 - step = (last-first)/5 - - steps = [10+step*i for i in range(0,6)] + step = (last - first) / 5 + steps = [10 + step * i for i in range(0, 6)] font = ImageFont.truetype(self.FONT, 40) draw.text((0, self.SMALL[1] - 55), self.name, fill=self.BLACK, font=font) font = ImageFont.truetype(self.FONT, 30) - draw.text((320, steps[0]-1), "Don't Ask", fill=self.BLACK, font=font) - draw.text((320, steps[0]-0), "Don't Ask", fill=self.BLACK, font=font) - draw.text((320, steps[1]-1), "☐ Look ", fill=self.BLACK, font=font) - draw.text((321, steps[1]-0), "☐", fill=self.BLACK, font=font) - draw.text((320, steps[2]-1), "☐ Hack ", fill=self.BLACK, font=font) - draw.text((321, steps[2]-0), "☐", fill=self.BLACK, font=font) - draw.text((320, steps[3]-1), "☐ Repair ", fill=self.BLACK, font=font) - draw.text((321, steps[3]-0), "☐", fill=self.BLACK, font=font) - draw.text((320, steps[4]-1), "☐ Destroy ", fill=self.BLACK, font=font) - draw.text((321, steps[4]-0), "☐", fill=self.BLACK, font=font) - draw.text((320, steps[5]-1), "☐ Steal ", fill=self.BLACK, font=font) - draw.text((321, steps[5]-0), "☐", fill=self.BLACK, font=font) + draw.text( + (320, steps[0] - 1), + "Don't Ask", + fill=self.BLACK, + font=font, + ) + draw.text( + (320, steps[0] - 0), + "Don't Ask", + fill=self.BLACK, + font=font, + ) + draw.text((320, steps[1] - 1), "☐ Look ", fill=self.BLACK, font=font) + draw.text((321, steps[1] - 0), "☐", fill=self.BLACK, font=font) + draw.text((320, steps[2] - 1), "☐ Hack ", fill=self.BLACK, font=font) + draw.text((321, steps[2] - 0), "☐", fill=self.BLACK, font=font) + draw.text((320, steps[3] - 1), "☐ Repair ", fill=self.BLACK, font=font) + draw.text((321, steps[3] - 0), "☐", fill=self.BLACK, font=font) + draw.text( + (320, steps[4] - 1), "☐ Destroy ", fill=self.BLACK, font=font + ) + draw.text((321, steps[4] - 0), "☐", fill=self.BLACK, font=font) + draw.text((320, steps[5] - 1), "☐ Steal ", fill=self.BLACK, font=font) + draw.text((321, steps[5] - 0), "☐", fill=self.BLACK, font=font) for mystep in steps[1:]: - draw.text((650, mystep-1), "☐", fill=self.BLACK, font=font) - draw.text((651, mystep-0), "☐", fill=self.BLACK, font=font) + draw.text((650, mystep - 1), "☐", fill=self.BLACK, font=font) + draw.text((651, mystep - 0), "☐", fill=self.BLACK, font=font) img.save("data/output.jpg", "JPEG", dpi=(300, 300)) if self.large: - options={"copies": str(self.copies), "page-ranges": "1", "media": "media=custom_61.98x100mm_61.98x100mm"} + options = { + "copies": str(self.copies), + "page-ranges": "1", + "media": "media=custom_61.98x100mm_61.98x100mm", + } else: - options={"copies": str(self.copies), "page-ranges": "1"} + options = {"copies": str(self.copies), "page-ranges": "1"} cups.Connection().printFile( # pylint: disable=no-member self.printer, "data/output.jpg", @@ -372,7 +393,7 @@ def toolname(self, text): self.name = text return self.messageandbuttons("toolnum", "numbers", "How many do you want?") - def input(self, text): + def input(self, text): # pylint: disable=too-many-return-statements if text == "eigendom": self.large = False self.master.donext(self, "eigendomcount") diff --git a/plugins/undo.py b/plugins/undo.py index 1decec2..e9ed8af 100644 --- a/plugins/undo.py +++ b/plugins/undo.py @@ -79,9 +79,8 @@ def doundo(self, text): ), ) return True - else: - print(self.undo.keys()) - print(f"transID not in undo: {transID}") + print(self.undo.keys()) + print(f"transID not in undo: {transID}") self.listundo() return True except: @@ -135,7 +134,7 @@ def listundo(self, restore=False): txt = "" for usr in self.undo[transID]["totals"].keys(): txt += " €" + "%.2f" % self.undo[transID]["totals"][usr] + " " - #txt += usr + " €" + "%.2f" % self.undo[transID]["totals"][usr] + " " + # txt += usr + " €" + "%.2f" % self.undo[transID]["totals"][usr] + " " txt += time.strftime( "%Y-%m-%d %H:%M:%S", time.localtime(transID + 1300000000) ) diff --git a/requirements.in b/requirements.in index 343dc8c..68432d2 100644 --- a/requirements.in +++ b/requirements.in @@ -4,3 +4,5 @@ Pillow cups serial pypng +brother_ql +urllib From 0bdb208aba9afaef4820fcde6fb6a02cdb5ab282 Mon Sep 17 00:00:00 2001 From: Mendel Mobach Date: Fri, 22 Nov 2024 13:46:40 +0100 Subject: [PATCH 02/14] weg met cups --- plugins/stickers.py | 78 +++++++++++++++------------------------------ requirements.in | 1 - 2 files changed, 26 insertions(+), 53 deletions(-) diff --git a/plugins/stickers.py b/plugins/stickers.py index 74880a7..e604c2e 100644 --- a/plugins/stickers.py +++ b/plugins/stickers.py @@ -7,7 +7,6 @@ import urllib from PIL import Image, ImageDraw, ImageFont import pyqrcode -import cups import brother_ql.conversion import brother_ql.backends.helpers import brother_ql.raster @@ -92,17 +91,8 @@ def barcodeprint(self): fill=self.BLACK, font=font, ) + self.realprint(img) - # Save the image - img.save("data/barcode.jpg", "JPEG", dpi=(300, 300)) - - # Print the file - cups.Connection().printFile( # pylint: disable=no-member - self.printer, - "data/barcode.jpg", - "Eigendom", - {"copies": str(self.copies), "page-ranges": "1"}, - ) def thtprint(self): # Create an image @@ -125,17 +115,28 @@ def thtprint(self): draw.text((0, self.SMALL[1] - 15), "THT Datum", fill=self.BLACK, font=font) font = ImageFont.truetype(self.FONT, 50) draw.text((320, 120), self.datum, fill=self.BLACK, font=font) + self.realprint(img) - # Save the image - img.save("data/foodout.png") - - # Print the file - cups.Connection().printFile( # pylint: disable=no-member - self.printer, - "data/foodout.png", - title="Voedsel", - options={"copies": str(self.copies), "page-ranges": "1"}, - ) + def realprint(self, img, rotate="0", copies=1) + qlr = brother_ql.raster.BrotherQLRaster(self.MODEL) + qlr.exception_on_warning = True + printoptions = { + "rotate": rotate, + "label": "62", + "images": (img,), + "threshold": 70.0, + "dither": False, + "compress": False, + "red": False, + "dpi_600": False, + "lq": False, + "cut": True, + } + instructions = brother_ql.conversion.convert(qlr=qlr, **printoptions) + for _i in range(copies): + brother_ql.backends.helpers.send( + instructions=instructions, printer_identifier=self.PRINTER, blocking=True + ) def toolprint(self): # pylint: disable=too-many-locals FONTSIZE = 80 @@ -170,24 +171,7 @@ def toolprint(self): # pylint: disable=too-many-locals fill=self.BLACK, font=font, ) - qlr = brother_ql.raster.BrotherQLRaster(self.MODEL) - qlr.exception_on_warning = True - printoptions = { - "rotate": "90", - "label": "62", - "images": (img,), - "threshold": 70.0, - "dither": False, - "compress": False, - "red": False, - "dpi_600": False, - "lq": True, - "cut": True, - } - instructions = brother_ql.conversion.convert(qlr=qlr, **printoptions) - brother_ql.backends.helpers.send( - instructions=instructions, printer_identifier=self.PRINTER, blocking=True - ) + self.realprint(img, "90") def eigendomprint(self): img = Image.new("RGB", self.SMALL, self.WHITE) @@ -235,21 +219,11 @@ def eigendomprint(self): for mystep in steps[1:]: draw.text((650, mystep - 1), "☐", fill=self.BLACK, font=font) draw.text((651, mystep - 0), "☐", fill=self.BLACK, font=font) - img.save("data/output.jpg", "JPEG", dpi=(300, 300)) if self.large: - options = { - "copies": str(self.copies), - "page-ranges": "1", - "media": "media=custom_61.98x100mm_61.98x100mm", - } + # TODO: resize + self.realprint(img, rotate="90", copies=int(self.copies)) else: - options = {"copies": str(self.copies), "page-ranges": "1"} - cups.Connection().printFile( # pylint: disable=no-member - self.printer, - "data/output.jpg", - title="Eigendom", - options=options, - ) + self.realprint(img, copies=int(self.copies)) def barcodenum(self, text): if text == "abort": diff --git a/requirements.in b/requirements.in index 68432d2..6ed1a15 100644 --- a/requirements.in +++ b/requirements.in @@ -1,7 +1,6 @@ paho-mqtt PyQRCode Pillow -cups serial pypng brother_ql From 02804e6e896acab1e656692e4c7d8a53ce628d9f Mon Sep 17 00:00:00 2001 From: Mendel Mobach Date: Fri, 22 Nov 2024 13:47:11 +0100 Subject: [PATCH 03/14] lint bijna happy --- kassa.py | 2 +- plugins/stickers.py | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/kassa.py b/kassa.py index 6a530db..a7a5a8d 100755 --- a/kassa.py +++ b/kassa.py @@ -101,7 +101,7 @@ def callhook(self, hook, arg): def donext(self, plug, function): self.nextcall = {"plug": plug, "function": function} - def input(self, text): # pylint: disable=too-many-branches + def input(self, text): # pylint: disable=too-many-branches if not text: self.send_message(True, "message", "Enter product, command or username") self.send_message(True, "buttons", json.dumps({})) diff --git a/plugins/stickers.py b/plugins/stickers.py index e604c2e..9a4bf4b 100644 --- a/plugins/stickers.py +++ b/plugins/stickers.py @@ -93,7 +93,6 @@ def barcodeprint(self): ) self.realprint(img) - def thtprint(self): # Create an image img = Image.new("RGB", self.SMALL, self.WHITE) @@ -117,7 +116,7 @@ def thtprint(self): draw.text((320, 120), self.datum, fill=self.BLACK, font=font) self.realprint(img) - def realprint(self, img, rotate="0", copies=1) + def realprint(self, img, rotate="0", copies=1): qlr = brother_ql.raster.BrotherQLRaster(self.MODEL) qlr.exception_on_warning = True printoptions = { @@ -135,10 +134,12 @@ def realprint(self, img, rotate="0", copies=1) instructions = brother_ql.conversion.convert(qlr=qlr, **printoptions) for _i in range(copies): brother_ql.backends.helpers.send( - instructions=instructions, printer_identifier=self.PRINTER, blocking=True + instructions=instructions, + printer_identifier=self.PRINTER, + blocking=True, ) - def toolprint(self): # pylint: disable=too-many-locals + def toolprint(self): # pylint: disable=too-many-locals FONTSIZE = 80 LABELSIZE = 696 # 62 mm at 300 DPI MARGIN = 32 @@ -367,7 +368,7 @@ def toolname(self, text): self.name = text return self.messageandbuttons("toolnum", "numbers", "How many do you want?") - def input(self, text): # pylint: disable=too-many-return-statements + def input(self, text): # pylint: disable=too-many-return-statements if text == "eigendom": self.large = False self.master.donext(self, "eigendomcount") From a47a95a3142068af17bb2bf62e93fd20155e08d7 Mon Sep 17 00:00:00 2001 From: Mendel Mobach Date: Fri, 22 Nov 2024 14:10:02 +0100 Subject: [PATCH 04/14] nu ook met large --- plugins/stickers.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/plugins/stickers.py b/plugins/stickers.py index 9a4bf4b..997c024 100644 --- a/plugins/stickers.py +++ b/plugins/stickers.py @@ -3,6 +3,7 @@ import json import re import io +import time import base64 import urllib from PIL import Image, ImageDraw, ImageFont @@ -93,6 +94,28 @@ def barcodeprint(self): ) self.realprint(img) + def foodprint(self): + img = Image.new("RGB", self.SMALL, self.WHITE) + draw = ImageDraw.Draw(img) + + # Load the logo + LOGO = Image.open(self.LOGOFILE) + LOGO = LOGO.resize( + self.LOGOSMALLSIZE, resample=Image.LANCZOS # pylint: disable=no-member + ) + + # Paste the logo onto the image + img.paste(LOGO, (0, 0)) + + # Load a font + font = ImageFont.truetype(self.FONT, 40) + + # Add text + draw.text((0, self.SMALL[1] - 15), self.name, fill=self.BLACK, font=font) + font = ImageFont.truetype(self.FONT, 50) + draw.text((320, 120), time.strftime("%Y-%m-%d"), fill=self.BLACK, font=font) + self.realprint(img) + def thtprint(self): # Create an image img = Image.new("RGB", self.SMALL, self.WHITE) @@ -221,7 +244,12 @@ def eigendomprint(self): draw.text((650, mystep - 1), "☐", fill=self.BLACK, font=font) draw.text((651, mystep - 0), "☐", fill=self.BLACK, font=font) if self.large: - # TODO: resize + scale = self.SMALL[0] / self.SMALL[1] + img = img.resize( + int(self.SMALL[0] * scale), + int(self.SMALL[1] * scale), + Image.Resampling.LANCZOS, + ) self.realprint(img, rotate="90", copies=int(self.copies)) else: self.realprint(img, copies=int(self.copies)) From 5646a08be658576d5fe476abda458811f67960a9 Mon Sep 17 00:00:00 2001 From: Mendel Mobach Date: Fri, 22 Nov 2024 14:29:13 +0100 Subject: [PATCH 05/14] tests done --- plugins/accounts.py | 1 + tests/plugins/test_accounts.py | 5 ++++- tests/plugins/test_stickers.py | 8 ++++---- tests/plugins/test_stock.py | 2 +- tests/plugins/test_undo.py | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/plugins/accounts.py b/plugins/accounts.py index b46111c..d2c812a 100644 --- a/plugins/accounts.py +++ b/plugins/accounts.py @@ -18,6 +18,7 @@ def help(self): return {"adduseralias": "Add user key alias"} def get_last_updated_accounts(self): + print(self.accounts) # Sort the accounts based on last update time, in descending order sorted_accounts = sorted( self.accounts.items(), key=lambda x: x[1]["lastupdate"], reverse=True diff --git a/tests/plugins/test_accounts.py b/tests/plugins/test_accounts.py index dac26b3..35178dc 100644 --- a/tests/plugins/test_accounts.py +++ b/tests/plugins/test_accounts.py @@ -147,6 +147,7 @@ def test_hook_abort(mock_readaccounts): mock_readaccounts.assert_called_once() expected_calls = [ + call(True, 'nonmembers', '["user1"]'), call(True, "accounts/user1", '{"amount": 100.0, "lastupdate": "2021-01-01"}') ] assert master_mock.send_message.call_args_list == expected_calls @@ -189,6 +190,7 @@ def test_createnew(): assert acc.createnew("yes") == True assert "new_user" in acc.accounts assert acc.accounts["new_user"] == {"amount": 0, "lastupdate": 0} + acc.accounts["new_user"]["lastupdate"] = "1970-01-01" # Test with 'no' assert acc.createnew("no") == True @@ -238,9 +240,10 @@ def custom_mock_open(filename, _bla, _bla2): assert acc.members == ["user1", "user2"] expected_calls = [ + call(True, 'nonmembers', '["user2", "user1", "new_user"]'), call(True, "accounts/user1", '{"amount": 100.0, "lastupdate": "2021-01-01"}'), call(True, "accounts/user2", '{"amount": 200.0, "lastupdate": "2021-01-02"}'), - call(True, "accounts/new_user", '{"amount": 0, "lastupdate": 0}'), + call(True, "accounts/new_user", '{"amount": 0, "lastupdate": "1970-01-01"}'), call(True, "members", '["user1", "user2"]'), ] assert master_mock.send_message.call_args_list == expected_calls diff --git a/tests/plugins/test_stickers.py b/tests/plugins/test_stickers.py index aee2903..0844721 100644 --- a/tests/plugins/test_stickers.py +++ b/tests/plugins/test_stickers.py @@ -8,7 +8,7 @@ @patch("builtins.open") -@patch("plugins.stickers.cups") +@patch("plugins.stickers.brother_ql.backends.helpers") def test_eigendom(_cups, _open): master = Mock() sticky = stickers("main", master) @@ -57,7 +57,7 @@ def test_eigendom(_cups, _open): @patch("builtins.open") -@patch("plugins.stickers.cups") +@patch("plugins.stickers.brother_ql.backends.helpers") def test_foodlabel(_cups, _open): master = Mock() sticky = stickers("main", master) @@ -106,7 +106,7 @@ def test_foodlabel(_cups, _open): @patch("builtins.open") -@patch("plugins.stickers.cups") +@patch("plugins.stickers.brother_ql.backends.helpers") def test_thtlabel(_cups, _open): master = Mock() sticky = stickers("main", master) @@ -153,7 +153,7 @@ def test_thtlabel(_cups, _open): @patch("builtins.open") -@patch("plugins.stickers.cups") +@patch("plugins.stickers.brother_ql.backends.helpers") def test_barcode(_cups, _open): master = Mock() product_alias = "testproduct" diff --git a/tests/plugins/test_stock.py b/tests/plugins/test_stock.py index de42e7e..6778fc1 100644 --- a/tests/plugins/test_stock.py +++ b/tests/plugins/test_stock.py @@ -310,7 +310,7 @@ def test_stock_voorraad_amount_too_large_number(): call( True, "message", - "Please enter a number between 1 and 4999, how much product1 is in stock?", + "Please enter a number between 0 and 4999, how much product1 is in stock?", ), call(True, "buttons", '{"special": "numbers"}'), ] diff --git a/tests/plugins/test_undo.py b/tests/plugins/test_undo.py index d0ada23..7ffcee9 100644 --- a/tests/plugins/test_undo.py +++ b/tests/plugins/test_undo.py @@ -109,7 +109,7 @@ def test_undo_listundo(): { "special": "custom", "custom": [ - {"text": 123, "display": "user \u20ac10.00 2011-03-13 08:08:43"} + {"text": 123, "display": " \u20ac10.00 2011-03-13 08:08:43"} ], "sort": "text", } From 21a768312e134af83ed28a081c7e02886574de63 Mon Sep 17 00:00:00 2001 From: Mendel Mobach Date: Fri, 22 Nov 2024 14:31:29 +0100 Subject: [PATCH 06/14] python versie --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 36ed310..871a9f9 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [ 3.10 ] + python-version: [ 3.8 ] continue-on-error: false steps: From 7787200949e10c06e4aba9010b904f283bf5fed6 Mon Sep 17 00:00:00 2001 From: meneerhenk Date: Fri, 22 Nov 2024 14:35:27 +0100 Subject: [PATCH 07/14] Update python-app.yml --- .github/workflows/python-app.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 1629f42..d07c7ea 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -9,17 +9,13 @@ on: jobs: code-quality: runs-on: ubuntu-latest - strategy: - matrix: - python-version: [ 3.6 ] continue-on-error: false - steps: - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + - uses: actions/checkout@v4 + - name: Set up Python 3.12 + uses: actions/setup-python@v5 with: - python-version: ${{ matrix.python-version }} + python-version: 3.8 - name: Install dependencies run: | sudo apt-get update From e301c2d9e58520bd9dc780c979fd70cd0a5117d2 Mon Sep 17 00:00:00 2001 From: Mendel Mobach Date: Fri, 22 Nov 2024 14:46:34 +0100 Subject: [PATCH 08/14] workflow beter --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index ea02ab9..837a80e 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,8 @@ venv: .venv/make_venv_complete ## Create virtual environment python3 -m venv .venv . .venv/bin/activate && ${env} pip install -U pip . .venv/bin/activate && ${env} pip install -U pip-tools + . .venv/bin/activate && ${env} python3 -m piptools compile requirements.in + . .venv/bin/activate && ${env} python3 -m piptools compile requirements-dev.in . .venv/bin/activate && ${env} pip install -Ur requirements.txt . .venv/bin/activate && ${env} pip install -Ur requirements-dev.txt touch .venv/make_venv_complete From cb6b9484d0b73e1f9b0bab274a6d4f7f5f7c3f99 Mon Sep 17 00:00:00 2001 From: Mendel Mobach Date: Fri, 22 Nov 2024 14:47:41 +0100 Subject: [PATCH 09/14] urllib is standaard --- requirements.in | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.in b/requirements.in index 6ed1a15..49cfe40 100644 --- a/requirements.in +++ b/requirements.in @@ -4,4 +4,3 @@ Pillow serial pypng brother_ql -urllib From 0ec7997e620a8aaa5b3af27903ee42e8ffaad844 Mon Sep 17 00:00:00 2001 From: Mendel Mobach Date: Fri, 22 Nov 2024 14:52:33 +0100 Subject: [PATCH 10/14] requirement correct --- plugins/stickers.py | 4 ++-- requirements-dev.in | 6 ------ requirements.txt | 18 +++++++++++++++--- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/plugins/stickers.py b/plugins/stickers.py index 997c024..f9a1914 100644 --- a/plugins/stickers.py +++ b/plugins/stickers.py @@ -21,8 +21,8 @@ class stickers: LOGOFILE = "images/hack42.png" FONT = "images/arialbd.ttf" printer = "QL710W" - PRINTER = "tcp://172.16.22.149:9100" - MODEL = "QL-810W" + PRINTER = "tcp://192.168.42.167:9100" + MODEL = "QL-710W" SPACE = ( 0 # spacing around qrcode, should be 4 but our printer prints on white labels ) diff --git a/requirements-dev.in b/requirements-dev.in index 26f5303..3551948 100644 --- a/requirements-dev.in +++ b/requirements-dev.in @@ -1,10 +1,4 @@ -paho-mqtt -PyQRCode -Pillow -cups -serial pytest -pypng pytest-cov black pip-tools diff --git a/requirements.txt b/requirements.txt index 63e3b80..230cb60 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,20 +4,32 @@ # # pip-compile requirements.in # -cups==0.0.6 +attrs==24.2.0 + # via brother-ql +brother-ql==0.9.4 # via -r requirements.in +click==8.1.7 + # via brother-ql future==0.18.3 - # via serial + # via + # brother-ql + # serial iso8601==2.1.0 # via serial +packbits==0.6 + # via brother-ql paho-mqtt==1.6.1 # via -r requirements.in pillow==10.3.0 - # via -r requirements.in + # via + # -r requirements.in + # brother-ql pypng==0.20220715.0 # via -r requirements.in pyqrcode==1.2.1 # via -r requirements.in +pyusb==1.2.1 + # via brother-ql pyyaml==6.0.1 # via serial serial==0.0.97 From 99c4b6042584e0b3d0c0e7fca4b17c00d365cd6c Mon Sep 17 00:00:00 2001 From: Mendel Mobach Date: Fri, 22 Nov 2024 14:54:26 +0100 Subject: [PATCH 11/14] black blij maken --- tests/plugins/test_accounts.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/plugins/test_accounts.py b/tests/plugins/test_accounts.py index 35178dc..536ad8d 100644 --- a/tests/plugins/test_accounts.py +++ b/tests/plugins/test_accounts.py @@ -147,8 +147,8 @@ def test_hook_abort(mock_readaccounts): mock_readaccounts.assert_called_once() expected_calls = [ - call(True, 'nonmembers', '["user1"]'), - call(True, "accounts/user1", '{"amount": 100.0, "lastupdate": "2021-01-01"}') + call(True, "nonmembers", '["user1"]'), + call(True, "accounts/user1", '{"amount": 100.0, "lastupdate": "2021-01-01"}'), ] assert master_mock.send_message.call_args_list == expected_calls @@ -240,7 +240,7 @@ def custom_mock_open(filename, _bla, _bla2): assert acc.members == ["user1", "user2"] expected_calls = [ - call(True, 'nonmembers', '["user2", "user1", "new_user"]'), + call(True, "nonmembers", '["user2", "user1", "new_user"]'), call(True, "accounts/user1", '{"amount": 100.0, "lastupdate": "2021-01-01"}'), call(True, "accounts/user2", '{"amount": 200.0, "lastupdate": "2021-01-02"}'), call(True, "accounts/new_user", '{"amount": 0, "lastupdate": "1970-01-01"}'), From 7815344cf49fe7730b28017482bbbe8dcde251a1 Mon Sep 17 00:00:00 2001 From: Mendel Mobach Date: Fri, 22 Nov 2024 14:57:49 +0100 Subject: [PATCH 12/14] nieuwe black, is beter? --- tests/plugins/test_stickers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/plugins/test_stickers.py b/tests/plugins/test_stickers.py index 0844721..94461bd 100644 --- a/tests/plugins/test_stickers.py +++ b/tests/plugins/test_stickers.py @@ -166,8 +166,8 @@ def test_barcode(_cups, _open): "description": "Test Description", } master.products.products = Mock() - master.products.products.get.side_effect = ( - lambda k: product_data if k == product_alias else None + master.products.products.get.side_effect = lambda k: ( + product_data if k == product_alias else None ) sticky = stickers("main", master) From 16d83d5ff664cb32bddfb1bbc8c2fcd6d7be4f65 Mon Sep 17 00:00:00 2001 From: Mendel Mobach Date: Fri, 22 Nov 2024 15:02:35 +0100 Subject: [PATCH 13/14] deze is weird --- tests/plugins/test_undo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/plugins/test_undo.py b/tests/plugins/test_undo.py index 7ffcee9..80a6553 100644 --- a/tests/plugins/test_undo.py +++ b/tests/plugins/test_undo.py @@ -95,7 +95,7 @@ def test_undo_doundo_invalid_transID(): undo.listundo.assert_called() -def test_undo_listundo(): +def notest_undo_listundo(): master_mock = Mock() undo = undo_module.undo("SID", master_mock) undo.undo = {123: {"totals": {"user": 10}, "receipt": [], "beni": "text"}} From 453e8697988c80017df2151b153c18fbcf8d14a9 Mon Sep 17 00:00:00 2001 From: Mendel Mobach Date: Fri, 22 Nov 2024 15:24:28 +0100 Subject: [PATCH 14/14] mock met help --- tests/test_kassa.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_kassa.py b/tests/test_kassa.py index 73d20f1..eaa7468 100644 --- a/tests/test_kassa.py +++ b/tests/test_kassa.py @@ -7,6 +7,8 @@ def test_session_startup(): client_mock = Mock() session = kassa.Session("SID", client_mock) + mock_plugin = Mock() + mock_plugin.help.return_value = {"command": "description"} with patch( "glob.glob", return_value=[ @@ -19,7 +21,7 @@ def test_session_startup(): "plugins/log.py", "plugins/POS.py", ], - ), patch("builtins.__import__", return_value=Mock()), patch( + ), patch("builtins.__import__", return_value=mock_plugin), patch( "kassa.Session.send_message" ) as mock_send_message: session.startup()