@@ -505,45 +505,48 @@ def render_text(lines):
505
505
render_engines .append (PictureRenderEngine (picture ))
506
506
507
507
if batch :
508
- text_accumulator : List [str ] = []
509
- qr_accumulator : List [str ] = []
510
-
511
- def flush_text ():
512
- nonlocal text_accumulator
513
- if len (text_accumulator ) > 0 :
514
- render_text (text_accumulator )
515
- text_accumulator = []
516
-
517
- def flush_qr ():
518
- nonlocal qr_accumulator
519
- if len (qr_accumulator ) > 0 :
508
+ accumulator : List [str ] = []
509
+ accumulator_type : str = "empty"
510
+
511
+ def flush_all ():
512
+ nonlocal accumulator
513
+ nonlocal accumulator_type
514
+ if accumulator_type == "text" :
515
+ render_text (accumulator )
516
+ elif accumulator_type == "qr" :
520
517
render_engines .append (
521
- QrRenderEngine (qr_callback ("\n " .join (qr_accumulator )))
518
+ QrRenderEngine (qr_callback ("\n " .join (accumulator )))
522
519
)
523
- qr_accumulator = []
524
520
525
- def flush_both ():
526
- flush_text ()
527
- flush_qr ()
521
+ accumulator = []
522
+ accumulator_type = "empty"
523
+
524
+ # Verify version
525
+ line = sys .stdin .readline ().strip ()
526
+ parts = line .split (":" , 1 )
527
+ if not (parts [0 ] == "LABELLE-LABEL-SPEC-VERSION" and parts [1 ] == "1" ):
528
+ err_console = Console (stderr = True )
529
+ err_console .print (
530
+ "Error: Batch doesn't begin with LABELLE-LABEL-SPEC-VERSION:1"
531
+ )
532
+ raise typer .Exit ()
528
533
529
534
for line in sys .stdin :
530
535
line = line .rstrip ("\r \n " )
531
536
parts = line .split (":" , 1 )
532
- if parts [0 ] == "TEXTSTART" :
533
- flush_both ()
534
- text_accumulator .append (parts [1 ])
535
- elif parts [0 ] == "TEXTADD" :
536
- flush_qr ()
537
- text_accumulator .append (parts [1 ])
538
- elif parts [0 ] == "QRSTART" :
539
- flush_both ()
540
- qr_accumulator .append (parts [1 ])
541
- elif parts [0 ] == "QRADD" :
542
- flush_text ()
543
- qr_accumulator .append (parts [1 ])
537
+ if parts [0 ] == "TEXT" :
538
+ flush_all ()
539
+ accumulator_type = "text"
540
+ accumulator .append (parts [1 ])
541
+ elif parts [0 ] == "QR" :
542
+ flush_all ()
543
+ accumulator_type = "qr"
544
+ accumulator .append (parts [1 ])
545
+ elif parts [0 ] == "NEWLINE" :
546
+ accumulator .append (parts [1 ])
544
547
else :
545
548
print ("WARNING: invalid command" , line )
546
- flush_both ()
549
+ flush_all ()
547
550
548
551
if fixed_length is None :
549
552
min_label_mm_len = min_length
0 commit comments