Configuration max text length via config file
This commit is contained in:
@@ -119,6 +119,7 @@ class EscPosPrinter(Printer):
|
||||
self.usb_args = {}
|
||||
self.usb_args["idVendor"] = self.vendor_id
|
||||
self.usb_args["idProduct"] = self.device_id
|
||||
self.configuration_file = configuration_file
|
||||
|
||||
try:
|
||||
# This also calls open(), which we need to close()
|
||||
@@ -148,13 +149,13 @@ class EscPosPrinter(Printer):
|
||||
vendor_id=self.vendor_id,
|
||||
product_id=self.device_id,
|
||||
serial_number="",
|
||||
label_type=configuration_file["label_type"],
|
||||
label_type=self.configuration_file["label_type"],
|
||||
)
|
||||
|
||||
# Setting up the printing options.
|
||||
# TODO : Expose this to the web interface
|
||||
p.set(
|
||||
align=configuration_file["align_text"],
|
||||
align=self.configuration_file["align_text"],
|
||||
font="a",
|
||||
bold=False,
|
||||
underline=0,
|
||||
@@ -213,25 +214,23 @@ class EscPosPrinter(Printer):
|
||||
clean_signature = str(signature)
|
||||
|
||||
# Make checks on the size of the message being printed
|
||||
# TODO: make the max length configurable
|
||||
if len(clean_msg) > 4096:
|
||||
if len(clean_msg) > int(self.configuration_file["text_max_length"]):
|
||||
self.app.logger.warning(
|
||||
"Could not print message of this length: " + str(len(clean_msg))
|
||||
)
|
||||
raise RuntimeError(
|
||||
"Could not print message of this length :"
|
||||
+ str(len(clean_msg))
|
||||
+ ", needs to be below 4096 caracters long."
|
||||
+ ", needs to be below %s caracters long.", str(self.configuration_file["text_max_length"])
|
||||
)
|
||||
# TODO: make the max length configurable
|
||||
if len(signature) > 256:
|
||||
if len(signature) > int(self.configuration_file["signature_max_length"]):
|
||||
self.app.logger.warning(
|
||||
"Could not print signature of this length: " + str(len(clean_signature))
|
||||
)
|
||||
raise RuntimeError(
|
||||
"Could not print signature of this length :"
|
||||
+ str(len(clean_signature))
|
||||
+ ", needs to be below 256 caracters long."
|
||||
+ ", needs to be below %s caracters long.", str(self.configuration_file["signature_max_length"])
|
||||
)
|
||||
|
||||
# Do the actual printing
|
||||
@@ -256,17 +255,17 @@ class EscPosPrinter(Printer):
|
||||
def _print_img(self, path, signature="", center=True, process=False):
|
||||
clean_signature = str(signature)
|
||||
|
||||
# TODO: make the max length configurable
|
||||
if len(signature) > 256:
|
||||
if len(signature) > int(self.configuration_file["signature_max_length"]):
|
||||
self.app.logger.warning(
|
||||
"Could not print signature of this length: " + str(len(clean_signature))
|
||||
)
|
||||
raise ValueError(
|
||||
raise RuntimeError(
|
||||
"Could not print signature of this length :"
|
||||
+ str(len(clean_signature))
|
||||
+ ", needs to be below 256 caracters long."
|
||||
+ ", needs to be below %s caracters long.", str(self.configuration_file["signature_max_length"])
|
||||
)
|
||||
|
||||
|
||||
if not os.path.isfile(str(path)):
|
||||
self.app.logger.warning("File does not exist : " + str(path))
|
||||
raise OSError(
|
||||
|
||||
Reference in New Issue
Block a user