Mercurial > hgrepos > Python > apps > py-cutils
comparison cutils/shasum.py @ 90:42419f57eda9
Allow to control the use of mmap from the command-line
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 21 Apr 2022 09:16:21 +0200 |
| parents | 72684020f2f3 |
| children | 8352da172a3e |
comparison
equal
deleted
inserted
replaced
| 89:72684020f2f3 | 90:42419f57eda9 |
|---|---|
| 84 "--checklist-allow-distinfo", action="store_true", | 84 "--checklist-allow-distinfo", action="store_true", |
| 85 dest="allow_distinfo", | 85 dest="allow_distinfo", |
| 86 help='Allow FreeBSD "distinfo" formatted checklists: ignore SIZE and TIMESTAMP lines.') | 86 help='Allow FreeBSD "distinfo" formatted checklists: ignore SIZE and TIMESTAMP lines.') |
| 87 | 87 |
| 88 aparser.add_argument( | 88 aparser.add_argument( |
| 89 "--mmap", action="store_true", dest="mmap", default=None, | |
| 90 help="""Use mmap if available. Default is to determine automatically | |
| 91 from the filesize.""") | |
| 92 aparser.add_argument( | |
| 93 "--no-mmap", action="store_false", dest="mmap", default=None, | |
| 94 help="Dont use mmap.") | |
| 95 | |
| 96 aparser.add_argument( | |
| 89 "--reverse", "-r", action="store_false", dest="bsd", default=False, | 97 "--reverse", "-r", action="store_false", dest="bsd", default=False, |
| 90 help="Explicitely select normal coreutils style output (to be option compatible with BSD style commands and :command:`openssl dgst -r`)") | 98 help="Explicitely select normal coreutils style output (to be option compatible with BSD style commands and :command:`openssl dgst -r`)") |
| 91 aparser.add_argument( | 99 aparser.add_argument( |
| 92 "--tag", action="store_true", dest="bsd", default=False, | 100 "--tag", action="store_true", dest="bsd", default=False, |
| 93 help="Alias for the `--bsd' option (to be compatible with :command:`b2sum`)") | 101 help="Alias for the `--bsd' option (to be compatible with :command:`b2sum`)") |
| 165 True, | 173 True, |
| 166 opts.base64) | 174 opts.base64) |
| 167 else: | 175 else: |
| 168 for fn in opts.files: | 176 for fn in opts.files: |
| 169 out(opts.dest or sys.stdout, | 177 out(opts.dest or sys.stdout, |
| 170 compute_digest_file(opts.algorithm[0], fn), | 178 compute_digest_file(opts.algorithm[0], fn, |
| 179 use_mmap=opts.mmap), | |
| 171 fn, | 180 fn, |
| 172 opts.algorithm[1], | 181 opts.algorithm[1], |
| 173 True, | 182 True, |
| 174 opts.base64) | 183 opts.base64) |
| 175 return 0 | 184 return 0 |
| 245 if pl is None: | 254 if pl is None: |
| 246 print("{}: MISSING".format(fn), file=dest) | 255 print("{}: MISSING".format(fn), file=dest) |
| 247 exit_code = 1 | 256 exit_code = 1 |
| 248 else: | 257 else: |
| 249 tag, algo, cl_filename, cl_digest = pl | 258 tag, algo, cl_filename, cl_digest = pl |
| 250 computed_digest = compute_digest_file(algo, fn) | 259 computed_digest = compute_digest_file(algo, fn, |
| 260 use_mmap=opts.mmap) | |
| 251 if compare_digests_equal(computed_digest, cl_digest, algo): | 261 if compare_digests_equal(computed_digest, cl_digest, algo): |
| 252 res = "OK" | 262 res = "OK" |
| 253 else: | 263 else: |
| 254 exit_code = 1 | 264 exit_code = 1 |
| 255 res = "FAILED" | 265 res = "FAILED" |
| 301 tag, algo, fn, digest = parts | 311 tag, algo, fn, digest = parts |
| 302 if tag in ("SIZE", "TIMESTAMP"): | 312 if tag in ("SIZE", "TIMESTAMP"): |
| 303 assert opts.allow_distinfo | 313 assert opts.allow_distinfo |
| 304 return (None, None, tag) | 314 return (None, None, tag) |
| 305 try: | 315 try: |
| 306 d = compute_digest_file(algo, fn) | 316 d = compute_digest_file(algo, fn, use_mmap=opts.mmap) |
| 307 if compare_digests_equal(d, digest, algo): | 317 if compare_digests_equal(d, digest, algo): |
| 308 return ("ok", fn, tag) | 318 return ("ok", fn, tag) |
| 309 else: | 319 else: |
| 310 return ("failed", fn, tag) | 320 return ("failed", fn, tag) |
| 311 except EnvironmentError: | 321 except EnvironmentError: |
