changeset 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
files cutils/treesum.py
diffstat 1 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/cutils/treesum.py	Wed Mar 26 23:06:05 2025 +0100
+++ b/cutils/treesum.py	Wed Mar 26 23:42:08 2025 +0100
@@ -166,6 +166,13 @@
             help="Put the checksum into given file. "
                  "If not given or if it is given as `-' then stdout is used.")
         gp.add_argument(
+            "--output-style", dest="output_style", default="tagged",
+            choices=("tagged", "tag"),
+            help="""
+Select the output style: "tagged" or "tag" selects BSD style tagged format.
+Default is "tagged".
+""")
+        gp.add_argument(
             "--physical", "-P", action=SymlinkAction, dest="follow_symlinks",
             const=FollowSymlinkConfig(False, False, False),
             help="""Do not follow any symbolic links whether they are given
@@ -429,6 +436,7 @@
                       mmap=None,
                       mtime=False,
                       output=None,
+                      output_style="tagged",
                       print_size=False,
                       size_only=False,
                       utf8=False):
@@ -446,6 +454,9 @@
                     "every kind of every item in `fnmatch_filters' must be"
                     " \"include\", \"exclude\" or \"accept-treesum\""
                 )
+    if output_tyle not in ("tagged", "tag"):
+        raise ValueError(
+            "given output_style `%s' not allowed" % (output_style,))
 
     # Not following symlinks to files is not yet supported: reset to True
 #    if not follow_symlinks.file:
@@ -469,6 +480,7 @@
         metadata_mode=mode,
         metadata_mtime=mtime,
         output=output,
+        output_style=output_style,
         print_size=print_size,
         size_only=size_only,
         utf8=utf8)
@@ -516,6 +528,8 @@
     fnmatcher = fnmatch.FnMatcher.build_from_commandline_patterns(
         opts.fnmatch_filters)
 
+    assert opts.output_style in ("tagged", "tag")
+
     with out_cm as outfp:
         writer = TaggedTreesumWriter(outfp)
         for d in opts.directories: