brother_ql_print's instruction_file argument now accepts - for stdin

This commit is contained in:
Philipp Klaus
2016-12-29 09:09:22 +01:00
parent 5e7855eecf
commit 6e757e1ba9
+11 -4
View File
@@ -28,6 +28,15 @@ def main():
if not args.list_printers and not args.instruction_file: if not args.list_printers and not args.instruction_file:
parser.error("the following arguments are required: instruction_file") parser.error("the following arguments are required: instruction_file")
if args.instruction_file == '-':
try:
content = sys.stdin.buffer.read()
except AttributeError:
content = sys.stdin.read()
else:
with open(args.instruction_file, 'rb') as f:
content = f.read()
level = logging.DEBUG if args.debug else logging.WARNING level = logging.DEBUG if args.debug else logging.WARNING
logging.basicConfig(level=level) logging.basicConfig(level=level)
if args.backend == 'network': if args.backend == 'network':
@@ -67,10 +76,8 @@ def main():
printer = BrotherQLBackend(string_descr) printer = BrotherQLBackend(string_descr)
start = time.time() start = time.time()
with open(args.instruction_file, 'rb') as f: logger.info('Sending instructions to the printer. Total: %d bytes.', len(content))
content = f.read() printer.write(content)
logger.info('Sending instructions to the printer. Total: %d bytes.', len(content))
printer.write(content)
if selected_backend == 'network': if selected_backend == 'network':
""" No need to wait for completion. The network backend doesn't support readback. """ """ No need to wait for completion. The network backend doesn't support readback. """
return return