Skip to content

Commit 9222d19

Browse files
committed
provisioning: Make shipping errors non fatal
1 parent e706086 commit 9222d19

1 file changed

Lines changed: 32 additions & 26 deletions

File tree

provisioning/provision_stage_2_warp2.py

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from collections import namedtuple
1717
from selenium import webdriver
1818
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
2020
import tinkerforge_util as tfutil
2121

2222
tfutil.create_parent_module(__file__, 'provisioning')
@@ -698,55 +698,61 @@ def led_wrap():
698698
print(f"Printing report {report_path_pdf}")
699699

700700
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")
702702

703703
drilling_template_path = os.path.join(WARP_CHARGER_DIRECTORY, 'documents', f'WARP{scanner.qr_hw_version.replace(".0", "").replace(".", "")}_Bohrschablone.pdf')
704704

705705
print(f"Printing drilling template {drilling_template_path}")
706706

707707
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")
709709

710710
if not scanner.qr_shipping:
711-
print(cyan(f'No shipping'))
711+
print(cyan('No shipping'))
712712
else:
713713
print(cyan(f'Shipping order {scanner.qr_order_id}'))
714714

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
717716

718717
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
720720
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)
725729

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"
727733

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)
730736

731-
print(f"Printing packing slip {packing_slip_path}")
737+
print(f"Printing packing slip {packing_slip_path}")
732738

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]
735741

736-
pdf_writer = PdfWriter(clone_from=packing_slip_path)
742+
pdf_writer = PdfWriter(clone_from=packing_slip_path)
737743

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)
740746

741-
pdf_writer.write(packing_slip_path)
747+
pdf_writer.write(packing_slip_path)
742748

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")
745751

746-
print(f"Printing shipping slip {shipping_label_path}")
752+
print(f"Printing shipping slip {shipping_label_path}")
747753

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")
750756

751757
print('Done!')
752758
except BaseException as e:

0 commit comments

Comments
 (0)