Mercurial > hgrepos > Python > apps > py-cutils
comparison cutils/treesum.py @ 327:8e62738e7469
treesum: implement option "--output-style".
Currently only the existing output writer implementing the BSD style
tagged output is allowed.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Wed, 26 Mar 2025 23:42:08 +0100 |
| parents | a464f36fffcb |
| children | 97bba2295eb3 |
comparison
equal
deleted
inserted
replaced
| 326:a464f36fffcb | 327:8e62738e7469 |
|---|---|
| 163 help="Dont use mmap.") | 163 help="Dont use mmap.") |
| 164 gp.add_argument( | 164 gp.add_argument( |
| 165 "--output", "-o", action="store", metavar="OUTPUT", | 165 "--output", "-o", action="store", metavar="OUTPUT", |
| 166 help="Put the checksum into given file. " | 166 help="Put the checksum into given file. " |
| 167 "If not given or if it is given as `-' then stdout is used.") | 167 "If not given or if it is given as `-' then stdout is used.") |
| 168 gp.add_argument( | |
| 169 "--output-style", dest="output_style", default="tagged", | |
| 170 choices=("tagged", "tag"), | |
| 171 help=""" | |
| 172 Select the output style: "tagged" or "tag" selects BSD style tagged format. | |
| 173 Default is "tagged". | |
| 174 """) | |
| 168 gp.add_argument( | 175 gp.add_argument( |
| 169 "--physical", "-P", action=SymlinkAction, dest="follow_symlinks", | 176 "--physical", "-P", action=SymlinkAction, dest="follow_symlinks", |
| 170 const=FollowSymlinkConfig(False, False, False), | 177 const=FollowSymlinkConfig(False, False, False), |
| 171 help="""Do not follow any symbolic links whether they are given | 178 help="""Do not follow any symbolic links whether they are given |
| 172 on the command line or when walking the directory tree. | 179 on the command line or when walking the directory tree. |
| 427 minimal=None, | 434 minimal=None, |
| 428 mode=False, | 435 mode=False, |
| 429 mmap=None, | 436 mmap=None, |
| 430 mtime=False, | 437 mtime=False, |
| 431 output=None, | 438 output=None, |
| 439 output_style="tagged", | |
| 432 print_size=False, | 440 print_size=False, |
| 433 size_only=False, | 441 size_only=False, |
| 434 utf8=False): | 442 utf8=False): |
| 435 if not isinstance(follow_symlinks, FollowSymlinkConfig): | 443 if not isinstance(follow_symlinks, FollowSymlinkConfig): |
| 436 raise TypeError("`follow_symlinks' must be a FollowSymlinkConfig") | 444 raise TypeError("`follow_symlinks' must be a FollowSymlinkConfig") |
| 444 if f[0] not in ("exclude", "include"): | 452 if f[0] not in ("exclude", "include"): |
| 445 raise ValueError( | 453 raise ValueError( |
| 446 "every kind of every item in `fnmatch_filters' must be" | 454 "every kind of every item in `fnmatch_filters' must be" |
| 447 " \"include\", \"exclude\" or \"accept-treesum\"" | 455 " \"include\", \"exclude\" or \"accept-treesum\"" |
| 448 ) | 456 ) |
| 457 if output_tyle not in ("tagged", "tag"): | |
| 458 raise ValueError( | |
| 459 "given output_style `%s' not allowed" % (output_style,)) | |
| 449 | 460 |
| 450 # Not following symlinks to files is not yet supported: reset to True | 461 # Not following symlinks to files is not yet supported: reset to True |
| 451 # if not follow_symlinks.file: | 462 # if not follow_symlinks.file: |
| 452 # follow_symlinks = follow_symlinks._make([follow_symlinks.command_line, | 463 # follow_symlinks = follow_symlinks._make([follow_symlinks.command_line, |
| 453 # follow_symlinks.directory, | 464 # follow_symlinks.directory, |
| 467 mmap=mmap, | 478 mmap=mmap, |
| 468 metadata_full_mode=full_mode, | 479 metadata_full_mode=full_mode, |
| 469 metadata_mode=mode, | 480 metadata_mode=mode, |
| 470 metadata_mtime=mtime, | 481 metadata_mtime=mtime, |
| 471 output=output, | 482 output=output, |
| 483 output_style=output_style, | |
| 472 print_size=print_size, | 484 print_size=print_size, |
| 473 size_only=size_only, | 485 size_only=size_only, |
| 474 utf8=utf8) | 486 utf8=utf8) |
| 475 return opts | 487 return opts |
| 476 | 488 |
| 513 else: | 525 else: |
| 514 out_cm = open(opts.output, "wb") | 526 out_cm = open(opts.output, "wb") |
| 515 | 527 |
| 516 fnmatcher = fnmatch.FnMatcher.build_from_commandline_patterns( | 528 fnmatcher = fnmatch.FnMatcher.build_from_commandline_patterns( |
| 517 opts.fnmatch_filters) | 529 opts.fnmatch_filters) |
| 530 | |
| 531 assert opts.output_style in ("tagged", "tag") | |
| 518 | 532 |
| 519 with out_cm as outfp: | 533 with out_cm as outfp: |
| 520 writer = TaggedTreesumWriter(outfp) | 534 writer = TaggedTreesumWriter(outfp) |
| 521 for d in opts.directories: | 535 for d in opts.directories: |
| 522 V1DirectoryTreesumGenerator( | 536 V1DirectoryTreesumGenerator( |
