|
16 | 16 | from collections import namedtuple |
17 | 17 | from selenium import webdriver |
18 | 18 | from pypdf import PdfReader, PdfWriter |
19 | | -from tinkerforge_util.colored import red, green, blink, cyan |
| 19 | +from tinkerforge_util.colored import red, green, blink, cyan, yellow |
20 | 20 | import tinkerforge_util as tfutil |
21 | 21 |
|
22 | 22 | tfutil.create_parent_module(__file__, 'provisioning') |
@@ -698,55 +698,61 @@ def led_wrap(): |
698 | 698 | print(f"Printing report {report_path_pdf}") |
699 | 699 |
|
700 | 700 | if os.system(f'pdftops {report_path_pdf} - | lpr') != 0: |
701 | | - fatal_error(f"Could not print report") |
| 701 | + fatal_error("Could not print report") |
702 | 702 |
|
703 | 703 | drilling_template_path = os.path.join(WARP_CHARGER_DIRECTORY, 'documents', f'WARP{scanner.qr_hw_version.replace(".0", "").replace(".", "")}_Bohrschablone.pdf') |
704 | 704 |
|
705 | 705 | print(f"Printing drilling template {drilling_template_path}") |
706 | 706 |
|
707 | 707 | if os.system(f'pdftops {drilling_template_path} - | lpr -o scaling=100') != 0: |
708 | | - fatal_error(f"Could not print drilling template") |
| 708 | + fatal_error("Could not print drilling template") |
709 | 709 |
|
710 | 710 | if not scanner.qr_shipping: |
711 | | - print(cyan(f'No shipping')) |
| 711 | + print(cyan('No shipping')) |
712 | 712 | else: |
713 | 713 | print(cyan(f'Shipping order {scanner.qr_order_id}')) |
714 | 714 |
|
715 | | - packing_slip_path = f"{report_path_prefix}_packing_slip.pdf" |
716 | | - shipping_label_path = f"{report_path_prefix}_shipping_label.pdf" |
| 715 | + shipping_success = False |
717 | 716 |
|
718 | 717 | try: |
719 | | - output = subprocess.check_output(f'./ship_order.py --output-prefix={report_path_prefix} {scanner.qr_order_id}', stderr=subprocess.STDOUT, shell=True).rstrip() |
| 718 | + output = subprocess.check_output(f'./ship_order.py --output-prefix={report_path_prefix} {scanner.qr_order_id}', stderr=subprocess.STDOUT, shell=True).decode('utf-8').rstrip() |
| 719 | + shipping_success = True |
720 | 720 | except subprocess.CalledProcessError as e: |
721 | | - print(e.output) |
722 | | - fatal_error(f"Could not ship order") |
723 | | - except: |
724 | | - fatal_error(f"Could not ship order") |
| 721 | + if e.output == b'Error: NOT INCLUDED\n': |
| 722 | + output = yellow('Shipping skipped due to potentially malformed shipping address') |
| 723 | + else: |
| 724 | + output = yellow(f'Shipping skipped due to error: {e.output}') |
| 725 | + except Exception as e: |
| 726 | + output = yellow(f'Shipping skipped due to error: {e}') |
| 727 | + |
| 728 | + orig_print(output) |
725 | 729 |
|
726 | | - print(output.decode('utf-8')) |
| 730 | + if shipping_success: |
| 731 | + packing_slip_path = f"{report_path_prefix}_packing_slip.pdf" |
| 732 | + shipping_label_path = f"{report_path_prefix}_shipping_label.pdf" |
727 | 733 |
|
728 | | - files_to_commit.append(packing_slip_path) |
729 | | - files_to_commit.append(shipping_label_path) |
| 734 | + files_to_commit.append(packing_slip_path) |
| 735 | + files_to_commit.append(shipping_label_path) |
730 | 736 |
|
731 | | - print(f"Printing packing slip {packing_slip_path}") |
| 737 | + print(f"Printing packing slip {packing_slip_path}") |
732 | 738 |
|
733 | | - folding_marks_path = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'folding_marks.pdf')) |
734 | | - folding_marks = PdfReader(folding_marks_path).pages[0] |
| 739 | + folding_marks_path = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'folding_marks.pdf')) |
| 740 | + folding_marks = PdfReader(folding_marks_path).pages[0] |
735 | 741 |
|
736 | | - pdf_writer = PdfWriter(clone_from=packing_slip_path) |
| 742 | + pdf_writer = PdfWriter(clone_from=packing_slip_path) |
737 | 743 |
|
738 | | - for page in pdf_writer.pages: |
739 | | - page.merge_page(folding_marks, over=False) |
| 744 | + for page in pdf_writer.pages: |
| 745 | + page.merge_page(folding_marks, over=False) |
740 | 746 |
|
741 | | - pdf_writer.write(packing_slip_path) |
| 747 | + pdf_writer.write(packing_slip_path) |
742 | 748 |
|
743 | | - if os.system(f'pdftops {packing_slip_path} - | lpr') != 0: |
744 | | - fatal_error(f"Could not print packing slip") |
| 749 | + if os.system(f'pdftops {packing_slip_path} - | lpr') != 0: |
| 750 | + fatal_error("Could not print packing slip") |
745 | 751 |
|
746 | | - print(f"Printing shipping slip {shipping_label_path}") |
| 752 | + print(f"Printing shipping slip {shipping_label_path}") |
747 | 753 |
|
748 | | - if os.system(f'pdftops {shipping_label_path} - | lpr -P Wallbox-DHL') != 0: |
749 | | - fatal_error(f"Could not print shipping label") |
| 754 | + if os.system(f'pdftops {shipping_label_path} - | lpr -P Wallbox-DHL') != 0: |
| 755 | + fatal_error("Could not print shipping label") |
750 | 756 |
|
751 | 757 | print('Done!') |
752 | 758 | except BaseException as e: |
|
0 commit comments