bug fixes & module rename -> brother_ql.backends.helpers
The rename was:
brother_ql.{printing,discovering} -> brother_ql.backends.helpers
This commit is contained in:
@@ -1,7 +1,10 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
"""
|
"""
|
||||||
The implementation of printing with the brother_ql package.
|
Helpers for the subpackage brother_ql.backends
|
||||||
|
|
||||||
|
* device discovery
|
||||||
|
* printing
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging, time
|
import logging, time
|
||||||
@@ -11,17 +14,28 @@ from brother_ql.reader import interpret_response
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
def send(instructions, printer_identifier=None, backend_name=None, blocking=True):
|
def discover(backend_identifier='linux_kernel'):
|
||||||
|
|
||||||
|
be = backend_factory(backend_identifier)
|
||||||
|
list_available_devices = be['list_available_devices']
|
||||||
|
BrotherQLBackend = be['backend_class']
|
||||||
|
|
||||||
|
available_devices = list_available_devices()
|
||||||
|
return available_devices
|
||||||
|
|
||||||
|
def send(instructions, printer_identifier=None, backend_identifier=None, blocking=True):
|
||||||
"""
|
"""
|
||||||
instructions: Bytes containing the instructions to be sent to the printer.
|
Send instruction bytes to a printer.
|
||||||
printer_identifier: String descriptor for the printer.
|
|
||||||
backend_name: Can enforce the use of a specific backend.
|
:param bytes instructions: The instructions to be sent to the printer.
|
||||||
blocking: Boolean indicating whether the print() call should wait for completion.
|
:param str printer_identifier: Identifier for the printer.
|
||||||
|
:param str backend_identifier: Can enforce the use of a specific backend.
|
||||||
|
:param bool blocking: Indicates whether the function call should block while waiting for the completion of the printing.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
selected_backend = None
|
selected_backend = None
|
||||||
if backend_name:
|
if backend_identifier:
|
||||||
selected_backend = backend_name
|
selected_backend = backend_identifier
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
selected_backend = guess_backend(printer_identifier)
|
selected_backend = guess_backend(printer_identifier)
|
||||||
@@ -7,8 +7,8 @@ Testing the packaged version of the Linux Kernel backend
|
|||||||
import argparse, logging, sys
|
import argparse, logging, sys
|
||||||
|
|
||||||
from brother_ql.backends import backend_factory, guess_backend, available_backends
|
from brother_ql.backends import backend_factory, guess_backend, available_backends
|
||||||
from brother_ql.printing import send
|
from brother_ql.backends.helpers import discover, send
|
||||||
from brother_ql.discovering import discover, pretty_print_discovered_devices
|
from brother_ql.output_helpers import log_discovered_devices, textual_description_discovered_devices
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -60,12 +60,11 @@ def main():
|
|||||||
|
|
||||||
# List any printers found, if explicitly asked to do so or if no identifier has been provided.
|
# List any printers found, if explicitly asked to do so or if no identifier has been provided.
|
||||||
if args.list_printers or not args.printer:
|
if args.list_printers or not args.printer:
|
||||||
available_devices = discover(backend=selected_backend)
|
available_devices = discover(backend_identifier=selected_backend)
|
||||||
pretty_print_discovered_devices(available_devices)
|
log_discovered_devices(available_devices)
|
||||||
|
|
||||||
if args.list_printers:
|
if args.list_printers:
|
||||||
for printer in available_devices:
|
print(textual_description_discovered_devices(available_devices))
|
||||||
print(printer['identifier'])
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
# Determine the identifier. Either selecting the explicitly stated one or using the first found device.
|
# Determine the identifier. Either selecting the explicitly stated one or using the first found device.
|
||||||
@@ -81,6 +80,6 @@ def main():
|
|||||||
identifier = args.printer
|
identifier = args.printer
|
||||||
|
|
||||||
# Finally, do the actual printing.
|
# Finally, do the actual printing.
|
||||||
send(instructions=content, printer_identifier=identifier, backend_name=selected_backend, block=True)
|
send(instructions=content, printer_identifier=identifier, backend_identifier=selected_backend, blocking=True)
|
||||||
|
|
||||||
if __name__ == "__main__": main()
|
if __name__ == "__main__": main()
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
"""
|
|
||||||
Printer device discovery using the different brother_ql.backends
|
|
||||||
"""
|
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from brother_ql.backends import backend_factory, guess_backend, available_backends
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
def discover(backend_name='linux_kernel'):
|
|
||||||
|
|
||||||
be = backend_factory(selected_backend)
|
|
||||||
list_available_devices = be['list_available_devices']
|
|
||||||
BrotherQLBackend = be['backend_class']
|
|
||||||
|
|
||||||
available_devices = list_available_devices()
|
|
||||||
return available_devices
|
|
||||||
|
|
||||||
def pretty_print_discovered_devices(available_devices):
|
|
||||||
for ad in available_devices:
|
|
||||||
result = {'model': 'unknown'}
|
|
||||||
result.update(ad)
|
|
||||||
logger.info(" Found a label printer: {identifier} (model: {model})".format(**result))
|
|
||||||
|
|
||||||
for printer in available_devices:
|
|
||||||
print(printer['identifier'])
|
|
||||||
sys.exit(0)
|
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
|
from brother_ql.devicedependent import label_type_specs
|
||||||
|
from brother_ql.devicedependent import DIE_CUT_LABEL, ENDLESS_LABEL, ROUND_DIE_CUT_LABEL
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
def textual_label_description(labels_to_include):
|
||||||
|
output = "Supported label sizes:\n"
|
||||||
|
output = ""
|
||||||
|
fmt = " {label_size:9s} {dots_printable:14s} {label_descr:26s}\n"
|
||||||
|
output += fmt.format(label_size="Name", dots_printable="Printable px", label_descr="Description")
|
||||||
|
#output += fmt.format(label_size="", dots_printable="width x height", label_descr="")
|
||||||
|
for label_size in labels_to_include:
|
||||||
|
s = label_type_specs[label_size]
|
||||||
|
if s['kind'] in (DIE_CUT_LABEL, ROUND_DIE_CUT_LABEL):
|
||||||
|
dp_fmt = "{0:4d} x {1:4d}"
|
||||||
|
elif s['kind'] == ENDLESS_LABEL:
|
||||||
|
dp_fmt = "{0:4d}"
|
||||||
|
else:
|
||||||
|
dp_fmt = " - unknown - "
|
||||||
|
dots_printable = dp_fmt.format(*s['dots_printable'])
|
||||||
|
label_descr = s['name']
|
||||||
|
output += fmt.format(label_size=label_size, dots_printable=dots_printable, label_descr=label_descr)
|
||||||
|
return output
|
||||||
|
|
||||||
|
def log_discovered_devices(available_devices, level=logging.INFO):
|
||||||
|
for ad in available_devices:
|
||||||
|
result = {'model': 'unknown'}
|
||||||
|
result.update(ad)
|
||||||
|
logger.log(level, " Found a label printer: {identifier} (model: {model})".format(**result))
|
||||||
|
|
||||||
|
def textual_description_discovered_devices(available_devices):
|
||||||
|
output = ""
|
||||||
|
for ad in available_devices:
|
||||||
|
output += ad['identifier']
|
||||||
|
return output
|
||||||
Reference in New Issue
Block a user