minor, use sys.exit print shorthand
diff --git a/mingw-ldd.py b/mingw-ldd.py index abc3d78..f5556ab 100755 --- a/mingw-ldd.py +++ b/mingw-ldd.py
@@ -47,8 +47,7 @@ try: return type2arch[pe.PE_TYPE] except KeyError: - sys.stderr.write('Error: unknown architecture') - sys.exit(1) + sys.exit ('Error: unknown architecture') if __name__ == '__main__': filename = sys.argv[1]
diff --git a/src/gen-arabic-table.py b/src/gen-arabic-table.py index f910d41..e4a4ddf 100755 --- a/src/gen-arabic-table.py +++ b/src/gen-arabic-table.py
@@ -11,8 +11,7 @@ import io, os.path, sys if len (sys.argv) != 4: - print (__doc__, file=sys.stderr) - sys.exit (1) + sys.exit (__doc__) files = [io.open (x, encoding='utf-8') for x in sys.argv[1:]]
diff --git a/src/gen-emoji-table.py b/src/gen-emoji-table.py index 6d5ca6e..5b78bd3 100755 --- a/src/gen-emoji-table.py +++ b/src/gen-emoji-table.py
@@ -12,8 +12,7 @@ import packTab if len (sys.argv) != 2: - print(__doc__, file=sys.stderr) - sys.exit (1) + sys.exit (__doc__) f = open(sys.argv[1]) header = [f.readline () for _ in range(10)]
diff --git a/src/gen-harfbuzzcc.py b/src/gen-harfbuzzcc.py index c0ac7d7..b4f24af 100755 --- a/src/gen-harfbuzzcc.py +++ b/src/gen-harfbuzzcc.py
@@ -5,7 +5,7 @@ import io, os, re, sys if len (sys.argv) < 3: - sys.exit(__doc__) + sys.exit (__doc__) output_file = sys.argv[1] source_paths = sys.argv[2:]
diff --git a/src/gen-indic-table.py b/src/gen-indic-table.py index edc898b..c45e99b 100755 --- a/src/gen-indic-table.py +++ b/src/gen-indic-table.py
@@ -11,8 +11,7 @@ import io, sys if len (sys.argv) != 4: - print (__doc__, file=sys.stderr) - sys.exit (1) + sys.exit (__doc__) ALLOWED_SINGLES = [0x00A0, 0x25CC] ALLOWED_BLOCKS = [
diff --git a/src/gen-tag-table.py b/src/gen-tag-table.py index 41baff3..e78389c 100755 --- a/src/gen-tag-table.py +++ b/src/gen-tag-table.py
@@ -36,8 +36,7 @@ import unicodedata if len (sys.argv) != 3: - print (__doc__, file=sys.stderr) - sys.exit (1) + sys.exit (__doc__) from html import unescape def html_unescape (parser, entity):
diff --git a/src/gen-ucd-table.py b/src/gen-ucd-table.py index 02c7ebd..6612250 100755 --- a/src/gen-ucd-table.py +++ b/src/gen-ucd-table.py
@@ -11,8 +11,7 @@ logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO) if len (sys.argv) not in (2, 3): - print(__doc__, file=sys.stderr) - sys.exit(1) + sys.exit (__doc__) # https://github.com/harfbuzz/packtab import packTab
diff --git a/src/gen-use-table.py b/src/gen-use-table.py index 26eb0a5..4845c19 100755 --- a/src/gen-use-table.py +++ b/src/gen-use-table.py
@@ -14,8 +14,7 @@ import sys if len (sys.argv) != 5: - print (__doc__, file=sys.stderr) - sys.exit (1) + sys.exit (__doc__) BLACKLISTED_BLOCKS = ["Thai", "Lao"]
diff --git a/src/gen-vowel-constraints.py b/src/gen-vowel-constraints.py index e758ea0..4e17173 100755 --- a/src/gen-vowel-constraints.py +++ b/src/gen-vowel-constraints.py
@@ -23,8 +23,7 @@ import sys if len (sys.argv) != 3: - print (__doc__, file=sys.stderr) - sys.exit (1) + sys.exit (__doc__) with io.open (sys.argv[2], encoding='utf-8') as f: scripts_header = [f.readline () for i in range (2)]
diff --git a/test/fuzzing/run-draw-fuzzer-tests.py b/test/fuzzing/run-draw-fuzzer-tests.py index 9fd21b6..7f40cf8 100755 --- a/test/fuzzing/run-draw-fuzzer-tests.py +++ b/test/fuzzing/run-draw-fuzzer-tests.py
@@ -28,9 +28,8 @@ if not os.path.exists (hb_draw_fuzzer): if len (sys.argv) == 1 or not os.path.exists (sys.argv[1]): - print ("""Failed to find hb-draw-fuzzer binary automatically, + sys.exit ("""Failed to find hb-draw-fuzzer binary automatically, please provide it as the first argument to the tool""") - sys.exit (1) hb_draw_fuzzer = sys.argv[1] @@ -42,8 +41,7 @@ if os.environ.get ('RUN_VALGRIND', ''): valgrind = shutil.which ('valgrind') if valgrind is None: - print ("""Valgrind requested but not found.""") - sys.exit (1) + sys.exit ("""Valgrind requested but not found.""") if libtool is None: print ("""Valgrind support is currently autotools only and needs libtool but not found.""") @@ -69,5 +67,4 @@ if fails: - print ("%i draw fuzzer related tests failed." % fails) - sys.exit (1) + sys.exit ("%d draw fuzzer related tests failed." % fails)
diff --git a/test/fuzzing/run-shape-fuzzer-tests.py b/test/fuzzing/run-shape-fuzzer-tests.py index 3c99942..7e2ef22 100755 --- a/test/fuzzing/run-shape-fuzzer-tests.py +++ b/test/fuzzing/run-shape-fuzzer-tests.py
@@ -28,9 +28,8 @@ if not os.path.exists (hb_shape_fuzzer): if len (sys.argv) == 1 or not os.path.exists (sys.argv[1]): - print ("""Failed to find hb-shape-fuzzer binary automatically, + sys.exit ("""Failed to find hb-shape-fuzzer binary automatically, please provide it as the first argument to the tool""") - sys.exit (1) hb_shape_fuzzer = sys.argv[1] @@ -42,8 +41,7 @@ if os.environ.get ('RUN_VALGRIND', ''): valgrind = shutil.which ('valgrind') if valgrind is None: - print ("""Valgrind requested but not found.""") - sys.exit (1) + sys.exit ("""Valgrind requested but not found.""") if libtool is None: print ("""Valgrind support is currently autotools only and needs libtool but not found.""") @@ -68,5 +66,4 @@ if fails: - print ("%i shape fuzzer related tests failed." % fails) - sys.exit (1) + sys.exit ("%d shape fuzzer related tests failed." % fails)
diff --git a/test/fuzzing/run-subset-fuzzer-tests.py b/test/fuzzing/run-subset-fuzzer-tests.py index 75eba78..5fd547d 100755 --- a/test/fuzzing/run-subset-fuzzer-tests.py +++ b/test/fuzzing/run-subset-fuzzer-tests.py
@@ -28,9 +28,8 @@ if not os.path.exists (hb_subset_fuzzer): if len (sys.argv) < 2 or not os.path.exists (sys.argv[1]): - print ("""Failed to find hb-subset-fuzzer binary automatically, + sys.exit ("""Failed to find hb-subset-fuzzer binary automatically, please provide it as the first argument to the tool""") - sys.exit (1) hb_subset_fuzzer = sys.argv[1] @@ -42,8 +41,7 @@ if os.environ.get('RUN_VALGRIND', ''): valgrind = shutil.which ('valgrind') if valgrind is None: - print ("""Valgrind requested but not found.""") - sys.exit (1) + sys.exit ("""Valgrind requested but not found.""") if libtool is None: print ("""Valgrind support is currently autotools only and needs libtool but not found.""") @@ -75,5 +73,4 @@ run_dir (os.path.join (srcdir, "fonts")) if fails: - print ("%i subset fuzzer related tests failed." % fails) - sys.exit (1) + sys.exit ("%d subset fuzzer related tests failed." % fails)
diff --git a/test/shaping/data/text-rendering-tests/extract-tests.py b/test/shaping/data/text-rendering-tests/extract-tests.py index 7f26329..61566fc 100755 --- a/test/shaping/data/text-rendering-tests/extract-tests.py +++ b/test/shaping/data/text-rendering-tests/extract-tests.py
@@ -57,4 +57,5 @@ opts = '--variations=%s' % variations print ("../fonts/%s:%s:%s:*" % (font, opts, unistr(text))) -sys.exit(0 if found else 1) +if not found: + sys.exit (1)
diff --git a/test/shaping/hb-diff b/test/shaping/hb-diff index 4c33bab..15a1e27 100755 --- a/test/shaping/hb-diff +++ b/test/shaping/hb-diff
@@ -4,7 +4,6 @@ import sys, os if len (sys.argv) < 2: - print ("usage: %s FILES..." % sys.argv[0]) - sys.exit (1) + sys.exit ("usage: %s FILES..." % sys.argv[0]) ZipDiffer.diff_files (FileHelpers.open_file_or_stdin (f) for f in sys.argv[1:])
diff --git a/test/shaping/hb_test_tools.py b/test/shaping/hb_test_tools.py index b1fb0bb..a9368ad 100644 --- a/test/shaping/hb_test_tools.py +++ b/test/shaping/hb_test_tools.py
@@ -145,8 +145,7 @@ sys.stdout.writelines ([symbols[i], l]) except IOError as e: if e.errno != errno.EPIPE: - print ("%s: %s: %s" % (sys.argv[0], e.filename, e.strerror), file=sys.stderr) - sys.exit (1) + sys.exit ("%s: %s: %s" % (sys.argv[0], e.filename, e.strerror)) class DiffFilters: @@ -321,8 +320,7 @@ def process_multiple_files (callback, mnemonic = "FILE"): if "--help" in sys.argv: - print ("Usage: %s %s..." % (sys.argv[0], mnemonic)) - sys.exit (1) + sys.exit ("Usage: %s %s..." % (sys.argv[0], mnemonic)) try: files = sys.argv[1:] if len (sys.argv) > 1 else ['-'] @@ -330,23 +328,20 @@ callback (FileHelpers.open_file_or_stdin (s)) except IOError as e: if e.errno != errno.EPIPE: - print ("%s: %s: %s" % (sys.argv[0], e.filename, e.strerror), file=sys.stderr) - sys.exit (1) + sys.exit ("%s: %s: %s" % (sys.argv[0], e.filename, e.strerror)) @staticmethod def process_multiple_args (callback, mnemonic): if len (sys.argv) == 1 or "--help" in sys.argv: - print ("Usage: %s %s..." % (sys.argv[0], mnemonic)) - sys.exit (1) + sys.exit ("Usage: %s %s..." % (sys.argv[0], mnemonic)) try: for s in sys.argv[1:]: callback (s) except IOError as e: if e.errno != errno.EPIPE: - print ("%s: %s: %s" % (sys.argv[0], e.filename, e.strerror), file=sys.stderr) - sys.exit (1) + sys.exit ("%s: %s: %s" % (sys.argv[0], e.filename, e.strerror)) @staticmethod def filter_multiple_strings_or_stdin (callback, mnemonic, \ @@ -354,9 +349,12 @@ concat_separator = False): if "--help" in sys.argv: - print ("Usage:\n %s %s...\nor:\n %s\n\nWhen called with no arguments, input is read from standard input." \ - % (sys.argv[0], mnemonic, sys.argv[0])) - sys.exit (1) + sys.exit ("""Usage: + %s %s... +or: + %s +When called with no arguments, input is read from standard input. +""" % (sys.argv[0], mnemonic, sys.argv[0])) try: if len (sys.argv) == 1: @@ -374,8 +372,7 @@ print (separator.join (callback (x) for x in (args))) except IOError as e: if e.errno != errno.EPIPE: - print ("%s: %s: %s" % (sys.argv[0], e.filename, e.strerror), file=sys.stderr) - sys.exit (1) + sys.exit ("%s: %s: %s" % (sys.argv[0], e.filename, e.strerror)) class Unicode: @@ -448,8 +445,7 @@ if not os.path.exists (s): if strict: - print ("%s: %s does not exist" % (sys.argv[0], s), file=sys.stderr) - sys.exit (1) + sys.exit ("%s: %s does not exist" % (sys.argv[0], s)) return s = os.path.normpath (s) @@ -464,8 +460,7 @@ yield p except IOError: if strict: - print ("%s: %s does not exist" % (sys.argv[0], os.path.join (s, "MANIFEST")), file=sys.stderr) - sys.exit (1) + sys.exit ("%s: %s does not exist" % (sys.argv[0], os.path.join (s, "MANIFEST"))) return else: yield s
diff --git a/test/shaping/run-tests.py b/test/shaping/run-tests.py index 33ceac8..292bd7f 100755 --- a/test/shaping/run-tests.py +++ b/test/shaping/run-tests.py
@@ -11,8 +11,7 @@ args = args[1:] if not args or args[0].find('hb-shape') == -1 or not os.path.exists (args[0]): - print ("""First argument does not seem to point to usable hb-shape.""") - sys.exit (1) + sys.exit ("""First argument does not seem to point to usable hb-shape.""") hb_shape, args = args[0], args[1:] def cmd(command):
diff --git a/test/subset/run-tests.py b/test/subset/run-tests.py index 4846aea..5ec2978 100755 --- a/test/subset/run-tests.py +++ b/test/subset/run-tests.py
@@ -127,13 +127,11 @@ args = sys.argv[1:] if not args or sys.argv[1].find ('hb-subset') == -1 or not os.path.exists (sys.argv[1]): - print ("First argument does not seem to point to usable hb-subset.") - sys.exit (1) + sys.exit ("First argument does not seem to point to usable hb-subset.") hb_subset, args = args[0], args[1:] if not len (args): - print ("No tests supplied.") - sys.exit (1) + sys.exit ("No tests supplied.") has_ots = has_ots() @@ -146,7 +144,6 @@ fails += run_test (test, has_ots) if fails != 0: - print (str (fails) + " test(s) failed.") - sys.exit(1) + sys.exit ("%d test(s) failed." % fails) else: print ("All tests passed.")