From 7554f618ecfbc0ba07937c7167ca6b456d55d712 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Thu, 28 May 2020 22:51:29 +0430 Subject: [PATCH] minor, use sys.exit print shorthand --- mingw-ldd.py | 3 +- src/gen-arabic-table.py | 3 +- src/gen-emoji-table.py | 3 +- src/gen-harfbuzzcc.py | 2 +- src/gen-indic-table.py | 3 +- src/gen-tag-table.py | 3 +- src/gen-ucd-table.py | 3 +- src/gen-use-table.py | 3 +- src/gen-vowel-constraints.py | 3 +- test/fuzzing/run-draw-fuzzer-tests.py | 9 ++--- test/fuzzing/run-shape-fuzzer-tests.py | 9 ++--- test/fuzzing/run-subset-fuzzer-tests.py | 9 ++--- .../text-rendering-tests/extract-tests.py | 3 +- test/shaping/hb-diff | 3 +- test/shaping/hb_test_tools.py | 33 ++++++++----------- test/shaping/run-tests.py | 3 +- test/subset/run-tests.py | 9 ++--- 17 files changed, 39 insertions(+), 65 deletions(-) diff --git a/mingw-ldd.py b/mingw-ldd.py index abc3d7861..f5556ab4b 100755 --- a/mingw-ldd.py +++ b/mingw-ldd.py @@ -47,8 +47,7 @@ def get_arch(filename): 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 f910d419e..e4a4ddf46 100755 --- a/src/gen-arabic-table.py +++ b/src/gen-arabic-table.py @@ -11,8 +11,7 @@ Input files: 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 6d5ca6e34..5b78bd3a3 100755 --- a/src/gen-emoji-table.py +++ b/src/gen-emoji-table.py @@ -12,8 +12,7 @@ from collections import OrderedDict 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 c0ac7d71b..b4f24aff0 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 edc898b31..c45e99b8c 100755 --- a/src/gen-indic-table.py +++ b/src/gen-indic-table.py @@ -11,8 +11,7 @@ Input files: 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 41baff3f3..e78389c11 100755 --- a/src/gen-tag-table.py +++ b/src/gen-tag-table.py @@ -36,8 +36,7 @@ import sys 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 02c7ebd16..6612250cc 100755 --- a/src/gen-ucd-table.py +++ b/src/gen-ucd-table.py @@ -11,8 +11,7 @@ import logging 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 26eb0a521..4845c1981 100755 --- a/src/gen-use-table.py +++ b/src/gen-use-table.py @@ -14,8 +14,7 @@ import io 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 e758ea00c..4e17173f9 100755 --- a/src/gen-vowel-constraints.py +++ b/src/gen-vowel-constraints.py @@ -23,8 +23,7 @@ import io 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 9fd21b6da..7f40cf838 100755 --- a/test/fuzzing/run-draw-fuzzer-tests.py +++ b/test/fuzzing/run-draw-fuzzer-tests.py @@ -28,9 +28,8 @@ hb_draw_fuzzer = os.path.join (top_builddir, "hb-draw-fuzzer" + EXEEXT) 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 @@ valgrind = None 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 @@ for file in os.listdir (parent_path): 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 3c99942f9..7e2ef220f 100755 --- a/test/fuzzing/run-shape-fuzzer-tests.py +++ b/test/fuzzing/run-shape-fuzzer-tests.py @@ -28,9 +28,8 @@ hb_shape_fuzzer = os.path.join (top_builddir, "hb-shape-fuzzer" + EXEEXT) 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 @@ valgrind = None 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 @@ for file in os.listdir (parent_path): 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 75eba78e3..5fd547d02 100755 --- a/test/fuzzing/run-subset-fuzzer-tests.py +++ b/test/fuzzing/run-subset-fuzzer-tests.py @@ -28,9 +28,8 @@ hb_subset_fuzzer = os.path.join (top_builddir, "hb-subset-fuzzer" + EXEEXT) 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 @@ valgrind = None 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, "..", "subset", "data", "fonts")) 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 7f26329f8..61566fc62 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 @@ for elt in html.findall(".//*[@class='expected-no-crash'][@ft:id]", namespaces): 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 4c33bab53..15a1e2725 100755 --- a/test/shaping/hb-diff +++ b/test/shaping/hb-diff @@ -4,7 +4,6 @@ from hb_test_tools import * 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 b1fb0bbb4..a9368adbd 100644 --- a/test/shaping/hb_test_tools.py +++ b/test/shaping/hb_test_tools.py @@ -145,8 +145,7 @@ class ZipDiffer: 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 @@ class UtilMains: 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 @@ class UtilMains: 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 @@ class UtilMains: 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 @@ class UtilMains: 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 @@ class Manifest: 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 @@ class Manifest: 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 33ceac836..292bd7f1b 100755 --- a/test/shaping/run-tests.py +++ b/test/shaping/run-tests.py @@ -11,8 +11,7 @@ if len (args) and args[0] == "--reference": 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 4846aea8e..5ec297805 100755 --- a/test/subset/run-tests.py +++ b/test/subset/run-tests.py @@ -127,13 +127,11 @@ def check_ots (path): 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 @@ for path in args: 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.")