comparison cutils/treesum.py @ 172:804a823c63f5

Now the selection of the default algorithm depends on availiability in hashlib
author Franz Glasner <fzglas.hg@dom66.de>
date Fri, 10 Jan 2025 11:38:31 +0100
parents 8945be6b404e
children e081b6ee5570
comparison
equal deleted inserted replaced
171:7912be4930b4 172:804a823c63f5
38 support them for all supported Python versions. 38 support them for all supported Python versions.
39 39
40 """ 40 """
41 gp.add_argument( 41 gp.add_argument(
42 "--algorithm", "-a", action="store", type=util.argv2algo, 42 "--algorithm", "-a", action="store", type=util.argv2algo,
43 help="1 (aka sha1), 224, 256, 384, 512, " 43 help="1 (aka sha1), 224, 256 (aka sha256), 384, 512 (aka sha512), "
44 "3 (alias for sha3-512), 3-224, 3-256, 3-384, 3-512, " 44 "3 (alias for sha3-512), 3-224, 3-256, 3-384, 3-512, "
45 "blake2b, blake2b-256 (default), blake2s, " 45 "blake2b, blake2b-256, blake2s, "
46 "blake2 (alias for blake2b), " 46 "blake2 (alias for blake2b), "
47 "blake2-256 (alias for blake2b-256), " 47 "blake2-256 (alias for blake2b-256), "
48 "md5") 48 "md5. "
49 "The default depends on availability in hashlib: "
50 "blake2b-256, sha256 or sha1.")
49 gp.add_argument( 51 gp.add_argument(
50 "--append-output", action="store_true", dest="append_output", 52 "--append-output", action="store_true", dest="append_output",
51 help="Append to the output file instead of overwriting it.") 53 help="Append to the output file instead of overwriting it.")
52 gp.add_argument( 54 gp.add_argument(
53 "--base64", action="store_true", 55 "--base64", action="store_true",
203 205
204 return treesum(opts) 206 return treesum(opts)
205 207
206 208
207 def gen_generate_opts(directories=[], 209 def gen_generate_opts(directories=[],
208 algorithm="BLAKE2b-256", 210 algorithm=util.default_algotag(),
209 append_output=False, 211 append_output=False,
210 base64=False, 212 base64=False,
211 comment=[], 213 comment=[],
212 follow_directory_symlinks=False, 214 follow_directory_symlinks=False,
213 full_mode=False, 215 full_mode=False,
219 output=None, 221 output=None,
220 print_size=False, 222 print_size=False,
221 size_only=False): 223 size_only=False):
222 opts = argparse.Namespace( 224 opts = argparse.Namespace(
223 directories=directories, 225 directories=directories,
224 algorithm=(util.algotag2algotype(algorithm), 226 algorithm=util.argv2algo(algorithm),
225 algorithm),
226 append_output=append_output, 227 append_output=append_output,
227 base64=base64, 228 base64=base64,
228 comment=comment, 229 comment=comment,
229 follow_directory_symlinks=follow_directory_symlinks, 230 follow_directory_symlinks=follow_directory_symlinks,
230 logical=logical, 231 logical=logical,
249 250
250 251
251 def generate_treesum(opts): 252 def generate_treesum(opts):
252 # Provide defaults 253 # Provide defaults
253 if not opts.algorithm: 254 if not opts.algorithm:
254 opts.algorithm = util.argv2algo("blake2b-256") 255 opts.algorithm = util.argv2algo(util.default_algotag())
255 if not opts.directories: 256 if not opts.directories:
256 opts.directories.append(".") 257 opts.directories.append(".")
257 258
258 if opts.output is None or opts.output == "-": 259 if opts.output is None or opts.output == "-":
259 if hasattr(sys.stdout, "buffer"): 260 if hasattr(sys.stdout, "buffer"):