comparison shasum.py @ 20:8f0241ed4a00

Do not append "-" to an empty FILE list any more but check explicitely for an empty list
author Franz Glasner <fzglas.hg@dom66.de>
date Sat, 05 Dec 2020 12:54:44 +0100
parents 2f9e702e3f7a
children f2d634270e1c
comparison
equal deleted inserted replaced
19:2f9e702e3f7a 20:8f0241ed4a00
71 sys.exit(78) # :manpage:`sysexits(3)` EX_CONFIG 71 sys.exit(78) # :manpage:`sysexits(3)` EX_CONFIG
72 72
73 if not opts.algorithm: 73 if not opts.algorithm:
74 opts.algorithm = argv2algo("1") 74 opts.algorithm = argv2algo("1")
75 75
76 if not opts.files:
77 opts.files.append('-')
78 if opts.check: 76 if opts.check:
79 return verify_digests_from_files(opts) 77 return verify_digests_from_files(opts)
80 else: 78 else:
81 return generate_digests(opts) 79 return generate_digests(opts)
82 80
84 def generate_digests(opts): 82 def generate_digests(opts):
85 if opts.bsd: 83 if opts.bsd:
86 out = out_bsd 84 out = out_bsd
87 else: 85 else:
88 out = out_std 86 out = out_std
89 if len(opts.files) == 1 and opts.files[0] == '-': 87 if not opts.files or (len(opts.files) == 1 and opts.files[0] == '-'):
90 if PY2: 88 if PY2:
91 if sys.platform == "win32": 89 if sys.platform == "win32":
92 import os, msvcrt # noqa: E401 90 import os, msvcrt # noqa: E401
93 msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) 91 msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
94 source = sys.stdin 92 source = sys.stdin
110 return 0 108 return 0
111 109
112 110
113 def verify_digests_from_files(opts): 111 def verify_digests_from_files(opts):
114 exit_code = 0 112 exit_code = 0
115 if len(opts.files) == 1 and opts.files[0] == '-': 113 if not opts.files or (len(opts.files) == 1 and opts.files[0] == '-'):
116 for checkline in sys.stdin: 114 for checkline in sys.stdin:
117 if not checkline: 115 if not checkline:
118 continue 116 continue
119 r, fn, tag = handle_checkline(opts, checkline) 117 r, fn, tag = handle_checkline(opts, checkline)
120 print("{}: {}: {}".format(tag, fn, r.upper())) 118 print("{}: {}: {}".format(tag, fn, r.upper()))