Mercurial > hgrepos > Python > apps > py-cutils
comparison cutils/treesum.py @ 346:d47965f97abb
treesum: Now handle all help related stuff in main()
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Tue, 01 Apr 2025 18:49:27 +0200 |
| parents | 0a58948df713 |
| children | 3f4840eeb0f4 |
comparison
equal
deleted
inserted
replaced
| 345:7117f06fefb0 | 346:d47965f97abb |
|---|---|
| 328 elif opts.help_command == "patterns": | 328 elif opts.help_command == "patterns": |
| 329 patparser.print_help() | 329 patparser.print_help() |
| 330 else: | 330 else: |
| 331 parser.print_help() | 331 parser.print_help() |
| 332 return 0 | 332 return 0 |
| 333 elif opts.subcommand == "patterns": | |
| 334 patparser.print_help() | |
| 335 return 0 | |
| 333 | 336 |
| 334 # Reparse strictly | 337 # Reparse strictly |
| 335 opts = parser.parse_args(args=argv) | 338 opts = parser.parse_args(args=argv) |
| 336 | 339 |
| 337 # Minimal logging -- just for debugging - not for more "normal" use | 340 # Minimal logging -- just for debugging - not for more "normal" use |
| 340 stream=sys.stderr, | 343 stream=sys.stderr, |
| 341 format="[%(asctime)s][%(levelname)s][%(process)d:%(name)s] %(message)s" | 344 format="[%(asctime)s][%(levelname)s][%(process)d:%(name)s] %(message)s" |
| 342 ) | 345 ) |
| 343 logging.captureWarnings(True) | 346 logging.captureWarnings(True) |
| 344 | 347 |
| 345 return treesum(opts, patparser=patparser) | 348 return treesum(opts) |
| 346 | 349 |
| 347 | 350 |
| 348 FollowSymlinkConfig = collections.namedtuple("FollowSymlinkConfig", | 351 FollowSymlinkConfig = collections.namedtuple("FollowSymlinkConfig", |
| 349 ["command_line", | 352 ["command_line", |
| 350 "directory", | 353 "directory", |
| 515 digest_files=digest_files, | 518 digest_files=digest_files, |
| 516 print_only_last_block=last) | 519 print_only_last_block=last) |
| 517 return opts | 520 return opts |
| 518 | 521 |
| 519 | 522 |
| 520 def treesum(opts, patparser=None): | 523 def treesum(opts): |
| 521 # XXX TBD: opts.check and opts.checklist (as in shasum.py) | 524 # XXX TBD: opts.check and opts.checklist (as in shasum.py) |
| 522 if opts.subcommand in ("generate", "gen"): | 525 if opts.subcommand in ("generate", "gen"): |
| 523 return generate_treesum(opts) | 526 return generate_treesum(opts) |
| 524 elif opts.subcommand == "info": | 527 elif opts.subcommand == "info": |
| 525 return print_treesum_digestfile_infos(opts) | 528 return print_treesum_digestfile_infos(opts) |
| 526 elif opts.subcommand == "patterns": | |
| 527 patparser.print_help() | |
| 528 else: | 529 else: |
| 530 # | |
| 531 # NOTE: Subcommands for printing help (e.g. "patterns") should | |
| 532 # be handled in the caller. | |
| 533 # | |
| 529 raise RuntimeError( | 534 raise RuntimeError( |
| 530 "command `{}' not yet handled".format(opts.subcommand)) | 535 "command `{}' not handled".format(opts.subcommand)) |
| 531 | 536 |
| 532 | 537 |
| 533 def generate_treesum(opts): | 538 def generate_treesum(opts): |
| 534 # Provide defaults | 539 # Provide defaults |
| 535 if not opts.algorithm: | 540 if not opts.algorithm: |
