From 467c15ef0f07d1fbb2e3492c219b190998046191 Mon Sep 17 00:00:00 2001 From: Philipp Klaus Date: Tue, 19 Sep 2017 21:06:39 +0200 Subject: [PATCH] raise exception (instead of sys.exit()) in create_label() create_label() is the most important function to be used (imported) by other Python scripts and packages. It shouldn't force its calling code or program to terminate in case of invalid input. --- brother_ql/brother_ql_create.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brother_ql/brother_ql_create.py b/brother_ql/brother_ql_create.py index 00e407c..bd71c8d 100755 --- a/brother_ql/brother_ql_create.py +++ b/brother_ql/brother_ql_create.py @@ -108,7 +108,7 @@ def create_label(qlr, image, label_size, threshold=70, cut=True, dither=False, c elif int(rotate) != 0: im = im.rotate(rotate, expand=True) if im.size[0] != dots_printable[0] or im.size[1] != dots_printable[1]: - sys.exit("Check your image dimensions: %s. Expecting: %s" % (im.size, dots_printable)) + raise ValueError("Bad image dimensions: %s. Expecting: %s." % (im.size, dots_printable)) new_im = Image.new(im.mode, (device_pixel_width, dots_printable[1]), (255,)*len(im.mode)) new_im.paste(im, (device_pixel_width-im.size[0]-right_margin_dots, 0)) im = new_im