changeset 45:b25ef7293bf2

Enhance shasum.py to allow it to be used as Python module from within other programs more easily
author Franz Glasner <fzglas.hg@dom66.de>
date Wed, 19 Jan 2022 01:03:33 +0100
parents 26a8d4e7c8ee
children dc198b661149
files shasum.py
diffstat 1 files changed, 20 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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: