# HG changeset patch # User Franz Glasner # Date 1607120550 -3600 # Node ID 285848db0b52af4a9124abbea150f53173a19b79 # Parent 184ab1da13077cb22d619013b71fe42d837ae6f0 When verifying/checking digests: also print the digest tag used diff -r 184ab1da1307 -r 285848db0b52 shasum.py --- a/shasum.py Fri Dec 04 23:06:48 2020 +0100 +++ b/shasum.py Fri Dec 04 23:22:30 2020 +0100 @@ -116,8 +116,8 @@ for checkline in sys.stdin: if not checkline: continue - r, fn = handle_checkline(opts, checkline) - print("{}: {}".format(fn, r.upper())) + r, fn, tag = handle_checkline(opts, checkline) + print("{}: {}: {}".format(tag, fn, r.upper())) if r != "ok" and exit_code == 0: exit_code = 1 else: @@ -126,8 +126,8 @@ for checkline in checkfile: if not checkline: continue - r, fn = handle_checkline(opts, checkline) - print("{}: {}".format(fn, r.upper())) + r, fn, tag = handle_checkline(opts, checkline) + print("{}: {}: {}".format(tag, fn, r.upper())) if r != "ok" and exit_code == 0: exit_code = 1 return exit_code @@ -135,20 +135,23 @@ def handle_checkline(opts, line): """ - :return: a tuple with static "ok", "missing", or "failed" and the filename - :rtype: tuple(str, str) + :return: a tuple with static "ok", "missing", or "failed", the filename and + the digest used + :rtype: tuple(str, str, str) """ # determine checkfile format (BSD or coreutils) # BSD? mo = re.search(r"\A(\S+)\s*\((.*)\)\s*=\s*(.+)\n?\Z", line) if mo: - algo = algotag2algotype(mo.group(1)) + tag = mo.group(1) + algo = algotag2algotype(tag) fn = mo.group(2) digest = mo.group(3) else: mo = re.search(r"([^\ ]+) [\*\ ]?(.+)\n?\Z", line) if mo: + tag = opts.algorithm[1] algo = opts.algorithm[0] fn = mo.group(2) digest = mo.group(1) @@ -159,11 +162,11 @@ with open(fn, "rb") as input: d = compute_digest(algo, input) if d.lower() == digest.lower(): - return ("ok", fn) + return ("ok", fn, tag) else: - return ("failed", fn) + return ("failed", fn, tag) except EnvironmentError: - return ("missing", fn) + return ("missing", fn, tag) def argv2algo(s):