Mercurial > hgrepos > Python > apps > py-cutils
comparison shasum.py @ 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 | d856432a1cbb |
| children | 5bec7a5d894a |
comparison
equal
deleted
inserted
replaced
| 44:26a8d4e7c8ee | 45:b25ef7293bf2 |
|---|---|
| 95 sys.exit(64) # :manpage:`sysexits(3)` EX_USAGE | 95 sys.exit(64) # :manpage:`sysexits(3)` EX_USAGE |
| 96 | 96 |
| 97 if not opts.algorithm: | 97 if not opts.algorithm: |
| 98 opts.algorithm = argv2algo("1") | 98 opts.algorithm = argv2algo("1") |
| 99 | 99 |
| 100 return shasum(opts) | |
| 101 | |
| 102 | |
| 103 def gen_opts(files=[], algorithm="SHA1", bsd=False, text_mode=False, | |
| 104 checklist=False, check=False): | |
| 105 if text_mode: | |
| 106 raise ValueError("text mode not supported") | |
| 107 if checklist and check: | |
| 108 raise ValueError("only one of `checklist' or `check' is allowed") | |
| 109 opts = argparse.Namespace(files=files, | |
| 110 algorithm=(algotag2algotype(algorithm), | |
| 111 algorithm), | |
| 112 bsd=bsd, | |
| 113 checklist=checklist, | |
| 114 check=check, | |
| 115 text_mode=False) | |
| 116 return opts | |
| 117 | |
| 118 | |
| 119 def shasum(opts): | |
| 100 if opts.check: | 120 if opts.check: |
| 101 return verify_digests_from_files(opts) | 121 return verify_digests_from_files(opts) |
| 102 elif opts.checklist: | 122 elif opts.checklist: |
| 103 return verify_digests_with_checklist(opts) | 123 return verify_digests_with_checklist(opts) |
| 104 else: | 124 else: |
