# HG changeset patch # User Franz Glasner # Date 1642550613 -3600 # Node ID b25ef7293bf2e4eb87a376532da064e24b9e39da # Parent 26a8d4e7c8ee698cf4d1f4a499465c8abb4e3937 Enhance shasum.py to allow it to be used as Python module from within other programs more easily diff -r 26a8d4e7c8ee -r b25ef7293bf2 shasum.py --- a/shasum.py Wed Jan 19 00:40:34 2022 +0100 +++ b/shasum.py Wed Jan 19 01:03:33 2022 +0100 @@ -97,6 +97,26 @@ if not opts.algorithm: opts.algorithm = argv2algo("1") + return shasum(opts) + + +def gen_opts(files=[], algorithm="SHA1", bsd=False, text_mode=False, + checklist=False, check=False): + if text_mode: + raise ValueError("text mode not supported") + if checklist and check: + raise ValueError("only one of `checklist' or `check' is allowed") + opts = argparse.Namespace(files=files, + algorithm=(algotag2algotype(algorithm), + algorithm), + bsd=bsd, + checklist=checklist, + check=check, + text_mode=False) + return opts + + +def shasum(opts): if opts.check: return verify_digests_from_files(opts) elif opts.checklist: