Mercurial > hgrepos > Python > apps > py-cutils
diff cutils/treesum.py @ 150:f84cf853da22
Implement "--minimal [TAG]" for treesum.
Product minimal output only.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Fri, 03 Jan 2025 23:08:02 +0100 |
| parents | f717854be1de |
| children | b26c4290e928 |
line wrap: on
line diff
--- a/cutils/treesum.py Fri Jan 03 17:16:05 2025 +0100 +++ b/cutils/treesum.py Fri Jan 03 23:08:02 2025 +0100 @@ -70,6 +70,10 @@ " Note that this is a different setting as to follow symbolic" " links to directories when traversing a directory tree.") gp.add_argument( + "--minimal", nargs="?", const="", default=None, metavar="TAG", + help="Produce minimal output only. If a TAG is given and not " + "empty use it as the leading \"ROOT (<TAG>)\" output.") + gp.add_argument( "--mmap", action="store_true", dest="mmap", default=None, help="Use mmap if available. Default is to determine " "automatically from the filesize.") @@ -178,6 +182,7 @@ comment=[], follow_directory_symlinks=False, logical=None, + minimal=None, mmap=None, output=None): opts = argparse.Namespace( @@ -189,6 +194,7 @@ comment=comment, follow_directory_symlinks=follow_directory_symlinks, logical=logical, + minimal=minimal, mmap=mmap, output=output) return opts @@ -226,12 +232,13 @@ generate_treesum_for_directory( outfp, d, opts.algorithm, opts.mmap, opts.base64, opts.logical, opts.follow_directory_symlinks, + minimal=opts.minimal, comment=opts.comment) def generate_treesum_for_directory( outfp, root, algorithm, use_mmap, use_base64, handle_root_logical, - follow_directory_symlinks, comment=None): + follow_directory_symlinks, minimal=None, comment=None): """ :param outfp: a *binary* file with a "write()" and a "flush()" method @@ -250,17 +257,24 @@ outfp.write(format_bsd_line("FLAGS", ",".join(flags), None, False)) outfp.flush() - # Write execution timestamps in POSIX epoch and ISO format - ts = time.time() - outfp.write(format_bsd_line("TIMESTAMP", ts, None, False)) - ts = (datetime.datetime.utcfromtimestamp(ts)).isoformat("T") - outfp.write(format_bsd_line("ISOTIMESTAMP", ts, None, False)) - outfp.flush() + if minimal is None: + # Write execution timestamps in POSIX epoch and ISO format + ts = time.time() + outfp.write(format_bsd_line("TIMESTAMP", ts, None, False)) + ts = (datetime.datetime.utcfromtimestamp(ts)).isoformat("T") + outfp.write(format_bsd_line("ISOTIMESTAMP", ts, None, False)) + outfp.flush() - if comment: - for line in comment: - outfp.write(format_bsd_line("COMMENT", None, line, False)) - outfp.write(format_bsd_line("ROOT", None, root, False)) + if comment: + for line in comment: + outfp.write(format_bsd_line("COMMENT", None, line, False)) + + if minimal is not None: + outfp.write( + format_bsd_line( + "ROOT", None, minimal if minimal else "", False)) + else: + outfp.write(format_bsd_line("ROOT", None, root, False)) outfp.flush() dir_digests = {}
