annotate cutils/treesum.py @ 223:61e5b1c2685c

Commentx
author Franz Glasner <fzglas.hg@dom66.de>
date Sat, 25 Jan 2025 14:22:34 +0100
parents ca9d5a0dc9bb
children 07a0bc723139
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
124
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2 # :-
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
3 # :Copyright: (c) 2020-2025 Franz Glasner
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
4 # :License: BSD-3-Clause
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
5 # :-
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
6 r"""Generate and verify checksums for directory trees.
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
7
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
8 """
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
9
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
10 from __future__ import print_function, absolute_import
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
11
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
12
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
13 __all__ = []
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
14
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
15
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
16 import argparse
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
17 import base64
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
18 import binascii
210
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
19 import collections
128
7c646921a479 Add TIMESTAMP and ISOTIMESTAMP to the output
Franz Glasner <fzglas.hg@dom66.de>
parents: 127
diff changeset
20 import datetime
176
7f5d05a625fd Implement preconditions for some debug logging
Franz Glasner <fzglas.hg@dom66.de>
parents: 174
diff changeset
21 import logging
124
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
22 import os
188
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
23 import re
157
27d1aaf5fe39 Implement "--mode" flag for "treesum.py" to consider file portable mode bits
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
24 import stat
124
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
25 import sys
128
7c646921a479 Add TIMESTAMP and ISOTIMESTAMP to the output
Franz Glasner <fzglas.hg@dom66.de>
parents: 127
diff changeset
26 import time
179
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
27 import zlib
124
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
28
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
29 from . import (__version__, __revision__)
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
30 from . import util
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
31 from .util import cm
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
32 from .util import digest
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
33 from .util import walk
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
34
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
35
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
36 def main(argv=None):
142
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
37
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
38 def _populate_generate_arguments(gp):
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
39 """Use to populate command aliases.
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
40
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
41 This is because :class:`argparse.ArgumentParser` does not
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
42 support them for all supported Python versions.
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
43
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
44 """
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
45 gp.add_argument(
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
46 "--algorithm", "-a", action="store", type=util.argv2algo,
172
804a823c63f5 Now the selection of the default algorithm depends on availiability in hashlib
Franz Glasner <fzglas.hg@dom66.de>
parents: 170
diff changeset
47 help="1 (aka sha1), 224, 256 (aka sha256), 384, 512 (aka sha512), "
142
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
48 "3 (alias for sha3-512), 3-224, 3-256, 3-384, 3-512, "
172
804a823c63f5 Now the selection of the default algorithm depends on availiability in hashlib
Franz Glasner <fzglas.hg@dom66.de>
parents: 170
diff changeset
49 "blake2b, blake2b-256, blake2s, "
142
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
50 "blake2 (alias for blake2b), "
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
51 "blake2-256 (alias for blake2b-256), "
172
804a823c63f5 Now the selection of the default algorithm depends on availiability in hashlib
Franz Glasner <fzglas.hg@dom66.de>
parents: 170
diff changeset
52 "md5. "
804a823c63f5 Now the selection of the default algorithm depends on availiability in hashlib
Franz Glasner <fzglas.hg@dom66.de>
parents: 170
diff changeset
53 "The default depends on availability in hashlib: "
804a823c63f5 Now the selection of the default algorithm depends on availiability in hashlib
Franz Glasner <fzglas.hg@dom66.de>
parents: 170
diff changeset
54 "blake2b-256, sha256 or sha1.")
142
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
55 gp.add_argument(
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
56 "--append-output", action="store_true", dest="append_output",
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
57 help="Append to the output file instead of overwriting it.")
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
58 gp.add_argument(
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
59 "--base64", action="store_true",
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
60 help="Output checksums in base64 notation, not hexadecimal "
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
61 "(OpenBSD).")
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
62 gp.add_argument(
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
63 "--comment", action="append", default=[],
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
64 help="Put given comment COMMENT into the output as \"COMMENT\". "
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
65 "Can be given more than once.")
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
66 gp.add_argument(
210
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
67 "--follow-directory-symlinks", "-l", action=SymlinkAction,
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
68 const="follow-directory-symlinks",
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
69 default=FollowSymlinkConfig(False, False, True),
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
70 dest="follow_symlinks",
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
71 help="""Follow symbolic links to directories when walking a
217
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
72 directory tree. Augments --physical and -p.""")
210
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
73 gp.add_argument(
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
74 "--follow-file-symlinks", action=SymlinkAction,
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
75 const="follow-file-symlinks",
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
76 default=FollowSymlinkConfig(False, False, True),
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
77 dest="follow_symlinks",
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
78 help="""Follow symbolic links to files when walking a
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
79 directory tree. Augments --physical.""")
142
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
80 gp.add_argument(
158
d8cdd1985d43 Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents: 157
diff changeset
81 "--full-mode", action="store_true", dest="metadata_full_mode",
d8cdd1985d43 Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents: 157
diff changeset
82 help="Consider all mode bits as returned from stat(2) when "
d8cdd1985d43 Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents: 157
diff changeset
83 "computing directory digests. "
d8cdd1985d43 Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents: 157
diff changeset
84 "Note that mode bits on symbolic links itself are not "
d8cdd1985d43 Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents: 157
diff changeset
85 "considered.")
d8cdd1985d43 Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents: 157
diff changeset
86 gp.add_argument(
205
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
87 "--generator", choices=("normal", "full", "none"),
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
88 default="normal",
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
89 help="""Put a `GENERATOR' line into the output.
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
90 `full' prints full Python and OS/platform version information,
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
91 `normal' prints just whether Python 2 or Python 3 is used, and `none'
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
92 suppresses the output completely. The default is `normal'.""")
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
93 gp.add_argument(
210
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
94 "--logical", "-L", action=SymlinkAction, dest="follow_symlinks",
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
95 const=FollowSymlinkConfig(True, True, True),
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
96 help="""Follow symbolic links everywhere: on command line
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
97 arguments and -- while walking -- directory and file symbolic links.
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
98 Overwrites any other symlink related options
217
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
99 (--physical,-p, no-follow-directory-symlinks, no-follow-file-symlinks,
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
100 et al.).
210
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
101 """)
142
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
102 gp.add_argument(
150
f84cf853da22 Implement "--minimal [TAG]" for treesum.
Franz Glasner <fzglas.hg@dom66.de>
parents: 149
diff changeset
103 "--minimal", nargs="?", const="", default=None, metavar="TAG",
f84cf853da22 Implement "--minimal [TAG]" for treesum.
Franz Glasner <fzglas.hg@dom66.de>
parents: 149
diff changeset
104 help="Produce minimal output only. If a TAG is given and not "
f84cf853da22 Implement "--minimal [TAG]" for treesum.
Franz Glasner <fzglas.hg@dom66.de>
parents: 149
diff changeset
105 "empty use it as the leading \"ROOT (<TAG>)\" output.")
f84cf853da22 Implement "--minimal [TAG]" for treesum.
Franz Glasner <fzglas.hg@dom66.de>
parents: 149
diff changeset
106 gp.add_argument(
142
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
107 "--mmap", action="store_true", dest="mmap", default=None,
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
108 help="Use mmap if available. Default is to determine "
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
109 "automatically from the filesize.")
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
110 gp.add_argument(
157
27d1aaf5fe39 Implement "--mode" flag for "treesum.py" to consider file portable mode bits
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
111 "--mode", action="store_true", dest="metadata_mode",
158
d8cdd1985d43 Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents: 157
diff changeset
112 help="Consider the permission bits of stat(2) using S_IMODE (i.e. "
157
27d1aaf5fe39 Implement "--mode" flag for "treesum.py" to consider file portable mode bits
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
113 "all bits without the filetype bits) when "
158
d8cdd1985d43 Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents: 157
diff changeset
114 "computing directory digests. Note that mode bits on "
d8cdd1985d43 Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents: 157
diff changeset
115 "symbolic links itself are not considered.")
157
27d1aaf5fe39 Implement "--mode" flag for "treesum.py" to consider file portable mode bits
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
116 gp.add_argument(
151
b26c4290e928 Implement "--mtime" for treesum to include a file's mtime in a directory digest.
Franz Glasner <fzglas.hg@dom66.de>
parents: 150
diff changeset
117 "--mtime", action="store_true", dest="metadata_mtime",
b26c4290e928 Implement "--mtime" for treesum to include a file's mtime in a directory digest.
Franz Glasner <fzglas.hg@dom66.de>
parents: 150
diff changeset
118 help="Consider the mtime of files (non-directories) when "
b26c4290e928 Implement "--mtime" for treesum to include a file's mtime in a directory digest.
Franz Glasner <fzglas.hg@dom66.de>
parents: 150
diff changeset
119 "generating digests for directories. Digests for files are "
b26c4290e928 Implement "--mtime" for treesum to include a file's mtime in a directory digest.
Franz Glasner <fzglas.hg@dom66.de>
parents: 150
diff changeset
120 "not affected.")
b26c4290e928 Implement "--mtime" for treesum to include a file's mtime in a directory digest.
Franz Glasner <fzglas.hg@dom66.de>
parents: 150
diff changeset
121 gp.add_argument(
210
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
122 "--no-follow-directory-symlinks", action=SymlinkAction,
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
123 const="no-follow-directory-symlinks",
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
124 dest="follow_symlinks",
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
125 help="""Do not follow symbolic links to directories when walking a
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
126 directory tree. Augments --logical.""")
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
127 gp.add_argument(
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
128 "--no-follow-file-symlinks", action=SymlinkAction,
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
129 const="no-follow-file-symlinks",
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
130 dest="follow_symlinks",
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
131 help="""Dont follow symbolic links to files when walking a
217
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
132 directory tree. Augments --logical and -p.""")
210
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
133 gp.add_argument(
142
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
134 "--no-mmap", action="store_false", dest="mmap", default=None,
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
135 help="Dont use mmap.")
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
136 gp.add_argument(
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
137 "--output", "-o", action="store", metavar="OUTPUT",
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
138 help="Put the checksum into given file. "
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
139 "If not given or if it is given as `-' then stdout is used.")
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
140 gp.add_argument(
210
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
141 "--physical", "-P", action=SymlinkAction, dest="follow_symlinks",
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
142 const=FollowSymlinkConfig(False, False, False),
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
143 help="""Do not follow any symbolic links whether they are given
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
144 on the command line or when walking the directory tree.
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
145 Overwrites any other symlink related options
217
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
146 (--logical, -p, follow-directory-symlinks, follow-file-symlinks, et al.).
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
147 This is the default.""")
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
148 gp.add_argument(
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
149 "-p", action=SymlinkAction, dest="follow_symlinks",
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
150 const=FollowSymlinkConfig(False, False, True),
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
151 help="""Do not follow any symbolic links to directories,
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
152 whether they are given on the command line or when walking the directory tree,
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
153 but follow symbolic links to files.
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
154 Overwrites any other symlink related options
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
155 (--logical, --physical, follow-directory-symlinks, no-follow-file-symlinks,
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
156 et al.).
210
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
157 This is the default.""")
142
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
158 gp.add_argument(
168
bcc4441cf216 Implement "--print-size" to print file and accumulated directory sizes also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 161
diff changeset
159 "--print-size", action="store_true",
bcc4441cf216 Implement "--print-size" to print file and accumulated directory sizes also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 161
diff changeset
160 help="""Print the size of a file or the accumulated sizes of
bcc4441cf216 Implement "--print-size" to print file and accumulated directory sizes also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 161
diff changeset
161 directory content into the output also.
bcc4441cf216 Implement "--print-size" to print file and accumulated directory sizes also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 161
diff changeset
162 The size is not considered when computing digests. For symbolic links
bcc4441cf216 Implement "--print-size" to print file and accumulated directory sizes also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 161
diff changeset
163 the size is not printed also.""")
bcc4441cf216 Implement "--print-size" to print file and accumulated directory sizes also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 161
diff changeset
164 gp.add_argument(
170
8945be6b404e Mode for treesum.py to print only the size of files and the accumulated size of a directory: --size-only.
Franz Glasner <fzglas.hg@dom66.de>
parents: 169
diff changeset
165 "--size-only", action="store_true",
8945be6b404e Mode for treesum.py to print only the size of files and the accumulated size of a directory: --size-only.
Franz Glasner <fzglas.hg@dom66.de>
parents: 169
diff changeset
166 help="""Print only the size of files and for each directory its
8945be6b404e Mode for treesum.py to print only the size of files and the accumulated size of a directory: --size-only.
Franz Glasner <fzglas.hg@dom66.de>
parents: 169
diff changeset
167 accumulated directory size. Digests are not computed.""")
8945be6b404e Mode for treesum.py to print only the size of files and the accumulated size of a directory: --size-only.
Franz Glasner <fzglas.hg@dom66.de>
parents: 169
diff changeset
168 gp.add_argument(
202
b9b38584919b First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents: 200
diff changeset
169 "--utf8", "--utf-8", action="store_true",
b9b38584919b First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents: 200
diff changeset
170 help="""Encode all file paths using UTF-8 instead of
b9b38584919b First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents: 200
diff changeset
171 the filesystem encoding. Add some error tag into the path if it cannot
b9b38584919b First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents: 200
diff changeset
172 representated in Unicode cleanly.""")
b9b38584919b First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents: 200
diff changeset
173 gp.add_argument(
142
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
174 "directories", nargs="*", metavar="DIRECTORY")
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
175
190
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
176 def _populate_info_arguments(ip):
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
177 ip.add_argument(
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
178 "--last", action="store_true", dest="print_only_last_block",
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
179 help="Print only the last block of every given input file")
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
180 ip.add_argument(
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
181 "digest_files", nargs="+", metavar="TREESUM-DIGEST-FILE")
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
182
142
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
183 parser = argparse.ArgumentParser(
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
184 description="Generate and verify checksums for directory trees.",
148
17d6e760143f Optimize help / usage output for the global options.
Franz Glasner <fzglas.hg@dom66.de>
parents: 147
diff changeset
185 fromfile_prefix_chars='@',
17d6e760143f Optimize help / usage output for the global options.
Franz Glasner <fzglas.hg@dom66.de>
parents: 147
diff changeset
186 add_help=False)
142
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
187
148
17d6e760143f Optimize help / usage output for the global options.
Franz Glasner <fzglas.hg@dom66.de>
parents: 147
diff changeset
188 #
153
3505406ef9f3 Comment
Franz Glasner <fzglas.hg@dom66.de>
parents: 152
diff changeset
189 # Global options for all sub-commands.
3505406ef9f3 Comment
Franz Glasner <fzglas.hg@dom66.de>
parents: 152
diff changeset
190 # In a group because this allows a customized title.
148
17d6e760143f Optimize help / usage output for the global options.
Franz Glasner <fzglas.hg@dom66.de>
parents: 147
diff changeset
191 #
17d6e760143f Optimize help / usage output for the global options.
Franz Glasner <fzglas.hg@dom66.de>
parents: 147
diff changeset
192 gparser = parser.add_argument_group(title="Global Options")
17d6e760143f Optimize help / usage output for the global options.
Franz Glasner <fzglas.hg@dom66.de>
parents: 147
diff changeset
193 gparser.add_argument(
191
1b8bc876146a Make "--debug" a global argument in treeview
Franz Glasner <fzglas.hg@dom66.de>
parents: 190
diff changeset
194 "--debug", action="store_true",
1b8bc876146a Make "--debug" a global argument in treeview
Franz Glasner <fzglas.hg@dom66.de>
parents: 190
diff changeset
195 help="Activate debug logging to stderr")
1b8bc876146a Make "--debug" a global argument in treeview
Franz Glasner <fzglas.hg@dom66.de>
parents: 190
diff changeset
196 gparser.add_argument(
142
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
197 "-v", "--version", action="version",
148
17d6e760143f Optimize help / usage output for the global options.
Franz Glasner <fzglas.hg@dom66.de>
parents: 147
diff changeset
198 version="%s (rv:%s)" % (__version__, __revision__),
17d6e760143f Optimize help / usage output for the global options.
Franz Glasner <fzglas.hg@dom66.de>
parents: 147
diff changeset
199 help="Show program's version number and exit")
17d6e760143f Optimize help / usage output for the global options.
Franz Glasner <fzglas.hg@dom66.de>
parents: 147
diff changeset
200 gparser.add_argument(
17d6e760143f Optimize help / usage output for the global options.
Franz Glasner <fzglas.hg@dom66.de>
parents: 147
diff changeset
201 "-h", "--help", action="help",
17d6e760143f Optimize help / usage output for the global options.
Franz Glasner <fzglas.hg@dom66.de>
parents: 147
diff changeset
202 help="Show this help message and exit")
142
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
203
148
17d6e760143f Optimize help / usage output for the global options.
Franz Glasner <fzglas.hg@dom66.de>
parents: 147
diff changeset
204 #
17d6e760143f Optimize help / usage output for the global options.
Franz Glasner <fzglas.hg@dom66.de>
parents: 147
diff changeset
205 # Subcommands
17d6e760143f Optimize help / usage output for the global options.
Franz Glasner <fzglas.hg@dom66.de>
parents: 147
diff changeset
206 #
142
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
207 subparsers = parser.add_subparsers(
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
208 dest="subcommand",
145
073e0faea599 Optimize help output for subcommands
Franz Glasner <fzglas.hg@dom66.de>
parents: 144
diff changeset
209 title="Commands",
142
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
210 description="This tool uses subcommands. "
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
211 "To see detailed help for a specific subcommand use "
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
212 "the -h/--help option after the subcommand name. "
148
17d6e760143f Optimize help / usage output for the global options.
Franz Glasner <fzglas.hg@dom66.de>
parents: 147
diff changeset
213 "A list of valid commands and their short descriptions "
17d6e760143f Optimize help / usage output for the global options.
Franz Glasner <fzglas.hg@dom66.de>
parents: 147
diff changeset
214 "is listed below:",
145
073e0faea599 Optimize help output for subcommands
Franz Glasner <fzglas.hg@dom66.de>
parents: 144
diff changeset
215 metavar="COMMAND")
124
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
216
142
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
217 genparser = subparsers.add_parser(
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
218 "generate",
190
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
219 help="Generate checksums for directory trees",
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
220 description="Generate checksums for directory trees.")
142
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
221 _populate_generate_arguments(genparser)
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
222 # And an alias for "generate"
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
223 genparser2 = subparsers.add_parser(
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
224 "gen",
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
225 help="Alias for \"generate\"",
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
226 description="Generate checksums for directory trees. "
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
227 "This is an alias to \"generate\".")
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
228 _populate_generate_arguments(genparser2)
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
229
190
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
230 infoparser = subparsers.add_parser(
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
231 "info",
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
232 help="Print some information from given treesum digest file",
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
233 description="""Print some informations from given treesum digest files
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
234 to stdout."""
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
235 )
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
236 _populate_info_arguments(infoparser)
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
237
147
ed35f3c9e2b5 Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents: 146
diff changeset
238 hparser = subparsers.add_parser(
ed35f3c9e2b5 Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents: 146
diff changeset
239 "help",
ed35f3c9e2b5 Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents: 146
diff changeset
240 help="Show this help message or a subcommand's help and exit",
ed35f3c9e2b5 Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents: 146
diff changeset
241 description="Show this help message or a subcommand's help and exit.")
ed35f3c9e2b5 Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents: 146
diff changeset
242 hparser.add_argument("help_command", nargs='?', metavar="COMMAND")
ed35f3c9e2b5 Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents: 146
diff changeset
243
ed35f3c9e2b5 Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents: 146
diff changeset
244 vparser = subparsers.add_parser(
144
b39f8082ced1 Make a "version" subcommand to also print the program's version number for "treesum"
Franz Glasner <fzglas.hg@dom66.de>
parents: 143
diff changeset
245 "version",
b39f8082ced1 Make a "version" subcommand to also print the program's version number for "treesum"
Franz Glasner <fzglas.hg@dom66.de>
parents: 143
diff changeset
246 help="Show the program's version number and exit",
b39f8082ced1 Make a "version" subcommand to also print the program's version number for "treesum"
Franz Glasner <fzglas.hg@dom66.de>
parents: 143
diff changeset
247 description="Show the program's version number and exit.")
b39f8082ced1 Make a "version" subcommand to also print the program's version number for "treesum"
Franz Glasner <fzglas.hg@dom66.de>
parents: 143
diff changeset
248
147
ed35f3c9e2b5 Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents: 146
diff changeset
249 # Parse leniently to just check for "version" and/or help
146
7d8df8311e3b Optimize argument parsing for the "version" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 145
diff changeset
250 opts, _dummy = parser.parse_known_args(args=argv)
124
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
251
144
b39f8082ced1 Make a "version" subcommand to also print the program's version number for "treesum"
Franz Glasner <fzglas.hg@dom66.de>
parents: 143
diff changeset
252 if opts.subcommand == "version":
b39f8082ced1 Make a "version" subcommand to also print the program's version number for "treesum"
Franz Glasner <fzglas.hg@dom66.de>
parents: 143
diff changeset
253 print("%s (rv:%s)" % (__version__, __revision__),
b39f8082ced1 Make a "version" subcommand to also print the program's version number for "treesum"
Franz Glasner <fzglas.hg@dom66.de>
parents: 143
diff changeset
254 file=sys.stdout)
174
fc1055878775 Use "return 0" instead of "sys.exit(0)" when printing version and help#
Franz Glasner <fzglas.hg@dom66.de>
parents: 173
diff changeset
255 return 0
147
ed35f3c9e2b5 Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents: 146
diff changeset
256 if opts.subcommand == "help":
ed35f3c9e2b5 Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents: 146
diff changeset
257 if not opts.help_command:
ed35f3c9e2b5 Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents: 146
diff changeset
258 parser.print_help()
ed35f3c9e2b5 Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents: 146
diff changeset
259 else:
ed35f3c9e2b5 Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents: 146
diff changeset
260 if opts.help_command == "generate":
ed35f3c9e2b5 Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents: 146
diff changeset
261 genparser.print_help()
ed35f3c9e2b5 Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents: 146
diff changeset
262 elif opts.help_command == "gen":
ed35f3c9e2b5 Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents: 146
diff changeset
263 genparser2.print_help()
190
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
264 elif opts.help_command == "info":
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
265 infoparser.print_help()
147
ed35f3c9e2b5 Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents: 146
diff changeset
266 elif opts.help_command == "version":
ed35f3c9e2b5 Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents: 146
diff changeset
267 vparser.print_help()
ed35f3c9e2b5 Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents: 146
diff changeset
268 elif opts.help_command == "help":
ed35f3c9e2b5 Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents: 146
diff changeset
269 hparser.print_help()
ed35f3c9e2b5 Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents: 146
diff changeset
270 else:
ed35f3c9e2b5 Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents: 146
diff changeset
271 parser.print_help()
174
fc1055878775 Use "return 0" instead of "sys.exit(0)" when printing version and help#
Franz Glasner <fzglas.hg@dom66.de>
parents: 173
diff changeset
272 return 0
144
b39f8082ced1 Make a "version" subcommand to also print the program's version number for "treesum"
Franz Glasner <fzglas.hg@dom66.de>
parents: 143
diff changeset
273
146
7d8df8311e3b Optimize argument parsing for the "version" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 145
diff changeset
274 # Reparse strictly
7d8df8311e3b Optimize argument parsing for the "version" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 145
diff changeset
275 opts = parser.parse_args(args=argv)
7d8df8311e3b Optimize argument parsing for the "version" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 145
diff changeset
276
176
7f5d05a625fd Implement preconditions for some debug logging
Franz Glasner <fzglas.hg@dom66.de>
parents: 174
diff changeset
277 # Minimal logging -- just for debugging - not for more "normal" use
7f5d05a625fd Implement preconditions for some debug logging
Franz Glasner <fzglas.hg@dom66.de>
parents: 174
diff changeset
278 logging.basicConfig(
7f5d05a625fd Implement preconditions for some debug logging
Franz Glasner <fzglas.hg@dom66.de>
parents: 174
diff changeset
279 level=logging.DEBUG if opts.debug else logging.WARNING,
7f5d05a625fd Implement preconditions for some debug logging
Franz Glasner <fzglas.hg@dom66.de>
parents: 174
diff changeset
280 stream=sys.stderr,
7f5d05a625fd Implement preconditions for some debug logging
Franz Glasner <fzglas.hg@dom66.de>
parents: 174
diff changeset
281 format="[%(asctime)s][%(levelname)s][%(process)d:%(name)s] %(message)s"
7f5d05a625fd Implement preconditions for some debug logging
Franz Glasner <fzglas.hg@dom66.de>
parents: 174
diff changeset
282 )
7f5d05a625fd Implement preconditions for some debug logging
Franz Glasner <fzglas.hg@dom66.de>
parents: 174
diff changeset
283 logging.captureWarnings(True)
7f5d05a625fd Implement preconditions for some debug logging
Franz Glasner <fzglas.hg@dom66.de>
parents: 174
diff changeset
284
124
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
285 return treesum(opts)
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
286
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
287
210
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
288 FollowSymlinkConfig = collections.namedtuple("FollowSymlinkConfig",
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
289 ["command_line",
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
290 "directory",
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
291 "file"])
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
292
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
293
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
294 class SymlinkAction(argparse.Action):
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
295
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
296 """`type' is fixed here.
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
297 `dest' is a tuple with three items:
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
298
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
299 1. follow symlinks on the command line
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
300 2. follow directory symlinks while walking
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
301 3. follow file symlinks while walking (not yet implemented)
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
302
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
303 """
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
304
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
305 def __init__(self, *args, **kwargs):
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
306 if "nargs" in kwargs:
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
307 raise ValueError("`nargs' not allowed")
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
308 if "type" in kwargs:
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
309 raise ValueError("`type' not allowed")
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
310 c = kwargs.get("const", None)
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
311 if c is None:
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
312 raise ValueError("a const value is needed")
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
313 if (not isinstance(c, FollowSymlinkConfig)
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
314 and c not in ("follow-directory-symlinks",
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
315 "no-follow-directory-symlinks",
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
316 "follow-file-symlinks",
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
317 "no-follow-file-symlinks")):
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
318 raise ValueError(
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
319 "invalid value for the `const' configuration value")
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
320 default = kwargs.get("default", None)
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
321 if (default is not None
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
322 and not isinstance(default, FollowSymlinkConfig)):
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
323 raise TypeError("invalid type for `default'")
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
324 kwargs["nargs"] = 0
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
325 super(SymlinkAction, self).__init__(*args, **kwargs)
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
326
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
327 def __call__(self, parser, namespace, values, option_string=None):
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
328 curval = getattr(namespace, self.dest, None)
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
329 if curval is None:
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
330 curval = FollowSymlinkConfig(False, False, True)
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
331 if isinstance(self.const, FollowSymlinkConfig):
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
332 curval = self.const
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
333 else:
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
334 if self.const == "follow-directory-symlinks":
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
335 curval = FollowSymlinkConfig(
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
336 curval.command_line, True, curval.file)
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
337 elif self.const == "no-follow-directory-symlinks":
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
338 curval = FollowSymlinkConfig(
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
339 curval.command_line, False, curval.file)
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
340 elif self.const == "follow-file-symlinks":
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
341 curval = FollowSymlinkConfig(
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
342 curval.command_line, curval.directory, True)
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
343 elif self.const == "no-follow-file-symlinks":
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
344 curval = FollowSymlinkConfig(
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
345 curval.command_line, curval.directory, False)
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
346 else:
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
347 assert False, "Implementation error: not yet implemented"
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
348
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
349 # Not following symlinks to files is not yet supported: reset to True
217
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
350 # if not curval.file:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
351 # curval = FollowSymlinkConfig(
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
352 # curval.command_line, curval.directory, True)
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
353 # logging.warning("Coercing options to `follow-file-symlinks'")
210
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
354 setattr(namespace, self.dest, curval)
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
355
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
356
142
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
357 def gen_generate_opts(directories=[],
172
804a823c63f5 Now the selection of the default algorithm depends on availiability in hashlib
Franz Glasner <fzglas.hg@dom66.de>
parents: 170
diff changeset
358 algorithm=util.default_algotag(),
142
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
359 append_output=False,
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
360 base64=False,
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
361 comment=[],
210
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
362 follow_symlinks=FollowSymlinkConfig(False, False, False),
158
d8cdd1985d43 Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents: 157
diff changeset
363 full_mode=False,
205
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
364 generator="normal",
142
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
365 logical=None,
150
f84cf853da22 Implement "--minimal [TAG]" for treesum.
Franz Glasner <fzglas.hg@dom66.de>
parents: 149
diff changeset
366 minimal=None,
157
27d1aaf5fe39 Implement "--mode" flag for "treesum.py" to consider file portable mode bits
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
367 mode=False,
142
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
368 mmap=None,
151
b26c4290e928 Implement "--mtime" for treesum to include a file's mtime in a directory digest.
Franz Glasner <fzglas.hg@dom66.de>
parents: 150
diff changeset
369 mtime=False,
168
bcc4441cf216 Implement "--print-size" to print file and accumulated directory sizes also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 161
diff changeset
370 output=None,
170
8945be6b404e Mode for treesum.py to print only the size of files and the accumulated size of a directory: --size-only.
Franz Glasner <fzglas.hg@dom66.de>
parents: 169
diff changeset
371 print_size=False,
202
b9b38584919b First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents: 200
diff changeset
372 size_only=False,
b9b38584919b First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents: 200
diff changeset
373 utf8=False):
210
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
374 if not isinstance(follow_symlinks, FollowSymlinkConfig):
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
375 raise TypeError("`follow_symlinks' must be a FollowSymlinkConfig")
217
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
376 # Not following symlinks to files is not yet supported: reset to True
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
377 # if not follow_symlinks.file:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
378 # follow_symlinks = follow_symlinks._make([follow_symlinks.command_line,
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
379 # follow_symlinks.directory,
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
380 # True])
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
381 # logging.warning("Coercing to follow-symlinks-file")
131
3a18d71d7c50 Implement --follow-directory-symlinks when walking a directory tree
Franz Glasner <fzglas.hg@dom66.de>
parents: 130
diff changeset
382 opts = argparse.Namespace(
3a18d71d7c50 Implement --follow-directory-symlinks when walking a directory tree
Franz Glasner <fzglas.hg@dom66.de>
parents: 130
diff changeset
383 directories=directories,
172
804a823c63f5 Now the selection of the default algorithm depends on availiability in hashlib
Franz Glasner <fzglas.hg@dom66.de>
parents: 170
diff changeset
384 algorithm=util.argv2algo(algorithm),
131
3a18d71d7c50 Implement --follow-directory-symlinks when walking a directory tree
Franz Glasner <fzglas.hg@dom66.de>
parents: 130
diff changeset
385 append_output=append_output,
3a18d71d7c50 Implement --follow-directory-symlinks when walking a directory tree
Franz Glasner <fzglas.hg@dom66.de>
parents: 130
diff changeset
386 base64=base64,
135
dbf27681a1f6 Allow to put comments into the output with "--comment"
Franz Glasner <fzglas.hg@dom66.de>
parents: 134
diff changeset
387 comment=comment,
210
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
388 follow_symlinks=follow_symlinks,
205
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
389 generator=generator,
131
3a18d71d7c50 Implement --follow-directory-symlinks when walking a directory tree
Franz Glasner <fzglas.hg@dom66.de>
parents: 130
diff changeset
390 logical=logical,
150
f84cf853da22 Implement "--minimal [TAG]" for treesum.
Franz Glasner <fzglas.hg@dom66.de>
parents: 149
diff changeset
391 minimal=minimal,
131
3a18d71d7c50 Implement --follow-directory-symlinks when walking a directory tree
Franz Glasner <fzglas.hg@dom66.de>
parents: 130
diff changeset
392 mmap=mmap,
158
d8cdd1985d43 Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents: 157
diff changeset
393 metadata_full_mode=full_mode,
157
27d1aaf5fe39 Implement "--mode" flag for "treesum.py" to consider file portable mode bits
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
394 metadata_mode=mode,
151
b26c4290e928 Implement "--mtime" for treesum to include a file's mtime in a directory digest.
Franz Glasner <fzglas.hg@dom66.de>
parents: 150
diff changeset
395 metadata_mtime=mtime,
168
bcc4441cf216 Implement "--print-size" to print file and accumulated directory sizes also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 161
diff changeset
396 output=output,
170
8945be6b404e Mode for treesum.py to print only the size of files and the accumulated size of a directory: --size-only.
Franz Glasner <fzglas.hg@dom66.de>
parents: 169
diff changeset
397 print_size=print_size,
202
b9b38584919b First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents: 200
diff changeset
398 size_only=size_only,
b9b38584919b First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents: 200
diff changeset
399 utf8=utf8)
124
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
400 return opts
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
401
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
402
190
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
403 def gen_info_opts(digest_files=[], last=False):
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
404 opts = argparse.Namespace(
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
405 digest_files=digest_files,
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
406 print_only_last_block=last)
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
407 return opts
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
408
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
409
124
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
410 def treesum(opts):
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
411 # XXX TBD: opts.check and opts.checklist (as in shasum.py)
142
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
412 if opts.subcommand in ("generate", "gen"):
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
413 return generate_treesum(opts)
190
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
414 elif opts.subcommand == "info":
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
415 return print_treesum_digestfile_infos(opts)
142
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
416 else:
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
417 raise RuntimeError(
71747e45b52c Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents: 137
diff changeset
418 "command `{}' not yet handled".format(opts.subcommand))
124
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
419
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
420
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
421 def generate_treesum(opts):
149
f717854be1de Put the defaults generation when generating directory digests into "generate_treesum()" instead of "main()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 148
diff changeset
422 # Provide defaults
f717854be1de Put the defaults generation when generating directory digests into "generate_treesum()" instead of "main()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 148
diff changeset
423 if not opts.algorithm:
172
804a823c63f5 Now the selection of the default algorithm depends on availiability in hashlib
Franz Glasner <fzglas.hg@dom66.de>
parents: 170
diff changeset
424 opts.algorithm = util.argv2algo(util.default_algotag())
124
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
425 if not opts.directories:
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
426 opts.directories.append(".")
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
427
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
428 if opts.output is None or opts.output == "-":
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
429 if hasattr(sys.stdout, "buffer"):
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
430 out_cm = cm.nullcontext(sys.stdout.buffer)
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
431 else:
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
432 out_cm = cm.nullcontext(sys.stdout)
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
433 else:
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
434 if opts.append_output:
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
435 out_cm = open(opts.output, "ab")
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
436 else:
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
437 out_cm = open(opts.output, "wb")
179
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
438 out_cm = CRC32Output(out_cm)
124
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
439
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
440 with out_cm as outfp:
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
441 for d in opts.directories:
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
442 V1DirectoryTreesumGenerator(
202
b9b38584919b First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents: 200
diff changeset
443 opts.algorithm, opts.mmap, opts.base64,
210
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
444 opts.follow_symlinks,
205
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
445 opts.generator,
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
446 opts.metadata_mode,
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
447 opts.metadata_full_mode,
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
448 opts.metadata_mtime,
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
449 opts.size_only,
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
450 opts.print_size,
202
b9b38584919b First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents: 200
diff changeset
451 opts.utf8,
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
452 minimal=opts.minimal).generate(
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
453 outfp, d, comment=opts.comment)
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
454
124
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
455
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
456 class V1DirectoryTreesumGenerator(object):
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
457
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
458 def __init__(self, algorithm, use_mmap, use_base64,
210
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
459 follow_symlinks,
205
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
460 with_generator,
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
461 with_metadata_mode, with_metadata_full_mode,
202
b9b38584919b First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents: 200
diff changeset
462 with_metadata_mtime, size_only, print_size, utf8_mode,
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
463 minimal=None,):
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
464 super(V1DirectoryTreesumGenerator, self).__init__()
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
465 self._algorithm = algorithm
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
466 self._use_mmap = use_mmap
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
467 self._use_base64 = use_base64
210
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
468 self._follow_symlinks = follow_symlinks
205
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
469 self._with_generator = with_generator
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
470 self._with_metadata_mode = with_metadata_mode
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
471 self._with_metadata_full_mode = with_metadata_full_mode
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
472 self._with_metadata_mtime = with_metadata_mtime
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
473 self._size_only = size_only
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
474 self._print_size = print_size
202
b9b38584919b First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents: 200
diff changeset
475 self._utf8_mode = utf8_mode
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
476 self._minimal = minimal
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
477
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
478 def generate(self, outfp, root, comment=None):
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
479 """
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
480
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
481 :param outfp: a *binary* file with a "write()" and a "flush()" method
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
482
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
483 """
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
484 self._outfp = outfp
179
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
485 self._outfp.resetdigest()
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
486 self._outfp.write(format_bsd_line("VERSION", "1", None, False))
198
c1e875ba4bdc Put the effective filesystem encoding into the treesum digest file using FSENCODING = <encoding>
Franz Glasner <fzglas.hg@dom66.de>
parents: 197
diff changeset
487 self._outfp.write(format_bsd_line(
200
22f92bf3572c Print the FSENCODING in uppdercase characters always.
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
488 "FSENCODING", util.n(walk.getfsencoding().upper()), None, False))
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
489 self._outfp.flush()
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
490
205
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
491 if self._with_generator == "none":
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
492 pass # do nothing
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
493 elif self._with_generator == "normal":
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
494 self._outfp.write(format_bsd_line(
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
495 "GENERATOR", None, b"PY2" if util.PY2 else b"PY3", False))
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
496 elif self._with_generator == "full":
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
497 import platform
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
498 info = "%s %s, %s" % (platform.python_implementation(),
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
499 platform.python_version(),
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
500 platform.platform())
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
501 self._outfp.write(format_bsd_line(
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
502 "GENERATOR", None, info.encode("utf-8"), False))
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
503 else:
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
504 raise NotImplementedError(
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
505 "not implemented: %s" % (self._with_generator,))
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
506
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
507 #
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
508 # Note: Given non-default flags that are relevant for
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
509 # directory traversal.
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
510 #
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
511 flags = []
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
512 if self._with_metadata_full_mode:
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
513 flags.append("with-metadata-fullmode")
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
514 elif self._with_metadata_mode:
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
515 flags.append("with-metadata-mode")
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
516 if self._with_metadata_mtime:
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
517 flags.append("with-metadata-mtime")
219
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
518 flags.append("follow-symlinks-commandline"
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
519 if self._follow_symlinks.command_line
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
520 else "no-follow-symlinks-commandline")
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
521 flags.append("follow-symlinks-directory"
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
522 if self._follow_symlinks.directory
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
523 else "no-follow-symlinks-directory")
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
524 flags.append("follow-symlinks-file"
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
525 if self._follow_symlinks.file
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
526 else "no-follow-symlinks-file")
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
527 if self._size_only:
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
528 flags.append("size-only")
219
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
529 flags.append("utf8-encoding" if self._utf8_mode else "fs-encoding")
211
5bb0b25f8e99 FIX: FLAGS output: wrong "else" for "utf-8-mode" and "print-size"
Franz Glasner <fzglas.hg@dom66.de>
parents: 210
diff changeset
530 if self._print_size:
5bb0b25f8e99 FIX: FLAGS output: wrong "else" for "utf-8-mode" and "print-size"
Franz Glasner <fzglas.hg@dom66.de>
parents: 210
diff changeset
531 flags.append("print-size")
219
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
532 flags.sort()
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
533 self._outfp.write(
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
534 format_bsd_line("FLAGS", ",".join(flags), None, False))
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
535
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
536 if self._minimal is None:
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
537 # Write execution timestamps in POSIX epoch and ISO format
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
538 ts = int(time.time())
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
539 self._outfp.write(format_bsd_line("TIMESTAMP", ts, None, False))
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
540 ts = (datetime.datetime.utcfromtimestamp(ts)).isoformat("T")
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
541 self._outfp.write(format_bsd_line("ISOTIMESTAMP", ts, None, False))
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
542
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
543 if comment:
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
544 for line in comment:
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
545 self._outfp.write(
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
546 format_bsd_line("COMMENT", None, line, False))
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
547
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
548 if self._minimal is not None:
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
549 self._outfp.write(format_bsd_line(
204
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
550 "ROOT",
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
551 None,
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
552 (walk.WalkDirEntry.alt_u8(self._minimal)
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
553 if self._minimal else b""),
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
554 False))
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
555 else:
204
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
556 self._outfp.write(format_bsd_line(
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
557 "ROOT", None, walk.WalkDirEntry.alt_u8(root), False))
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
558 self._outfp.flush()
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
559
210
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
560 if not self._follow_symlinks.command_line and os.path.islink(root):
202
b9b38584919b First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents: 200
diff changeset
561 linktgt = walk.WalkDirEntry.from_readlink(os.readlink(root))
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
562 linkdgst = self._algorithm[0]()
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
563 linkdgst.update(
202
b9b38584919b First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents: 200
diff changeset
564 util.interpolate_bytes(
b9b38584919b First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents: 200
diff changeset
565 b"%d:%s,", len(linktgt.fspath), linktgt.fspath))
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
566 dir_dgst = self._algorithm[0]()
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
567 dir_dgst.update(b"1:L,")
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
568 dir_dgst.update(
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
569 util.interpolate_bytes(
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
570 b"%d:%s,", len(linkdgst.digest()), linkdgst.digest()))
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
571 if self._size_only:
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
572 self._outfp.write(
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
573 format_bsd_line(
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
574 "SIZE",
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
575 None,
193
fb36e71f6ba8 Change: path indicators for symlinks: ./@ -> ./@/ and /./@ -> /./@/
Franz Glasner <fzglas.hg@dom66.de>
parents: 191
diff changeset
576 "./@/",
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
577 False,
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
578 0))
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
579 else:
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
580 self._outfp.write(
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
581 format_bsd_line(
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
582 self._algorithm[1],
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
583 dir_dgst.digest(),
193
fb36e71f6ba8 Change: path indicators for symlinks: ./@ -> ./@/ and /./@ -> /./@/
Franz Glasner <fzglas.hg@dom66.de>
parents: 191
diff changeset
584 "./@/",
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
585 self._use_base64))
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
586 self._outfp.flush()
179
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
587 self._outfp.write(format_bsd_line(
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
588 "CRC32", self._outfp.hexcrcdigest(), None, False))
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
589 return
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
590
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
591 self._generate(os.path.normpath(root), tuple())
179
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
592 self._outfp.write(format_bsd_line(
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
593 "CRC32", self._outfp.hexcrcdigest(), None, False))
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
594
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
595 def _generate(self, root, top):
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
596 logging.debug("Handling %s/%r", root, top)
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
597 path = os.path.join(root, *top) if top else root
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
598 with walk.ScanDir(path) as dirscan:
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
599 fsobjects = list(dirscan)
202
b9b38584919b First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents: 200
diff changeset
600 if self._utf8_mode:
221
ca9d5a0dc9bb Rename WalkDirEntry.sort_key and WalkDirEntry.alt_sort_key
Franz Glasner <fzglas.hg@dom66.de>
parents: 220
diff changeset
601 fsobjects.sort(key=walk.WalkDirEntry.sort_key_u8)
202
b9b38584919b First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents: 200
diff changeset
602 else:
221
ca9d5a0dc9bb Rename WalkDirEntry.sort_key and WalkDirEntry.alt_sort_key
Franz Glasner <fzglas.hg@dom66.de>
parents: 220
diff changeset
603 fsobjects.sort(key=walk.WalkDirEntry.sort_key_fs)
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
604 dir_dgst = self._algorithm[0]()
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
605 dir_size = 0
204
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
606 dir_tainted = False
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
607 for fso in fsobjects:
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
608 if fso.is_dir:
210
1be3af138183 Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
609 if fso.is_symlink and not self._follow_symlinks.directory:
202
b9b38584919b First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents: 200
diff changeset
610 linktgt = walk.WalkDirEntry.from_readlink(
b9b38584919b First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents: 200
diff changeset
611 os.readlink(fso.path))
b9b38584919b First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents: 200
diff changeset
612 # linktgt = util.fsencode(os.readlink(fso.path)))
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
613 linkdgst = self._algorithm[0]()
204
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
614 if self._utf8_mode:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
615 if linktgt.u8path is None:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
616 dir_tainted = True
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
617 linkdgst.update(util.interpolate_bytes(
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
618 b"%d:%s,",
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
619 len(linktgt.alt_u8path),
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
620 linktgt.alt_u8path))
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
621 else:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
622 linkdgst.update(util.interpolate_bytes(
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
623 b"%d:%s,",
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
624 len(linktgt.u8path),
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
625 linktgt.u8path))
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
626 if fso.u8name is None:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
627 dir_tainted = True
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
628 dir_dgst.update(util.interpolate_bytes(
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
629 b"1:S,%d:%s,",
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
630 len(fso.alt_u8name),
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
631 fso.alt_u8name))
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
632 else:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
633 dir_dgst.update(util.interpolate_bytes(
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
634 b"1:S,%d:%s,", len(fso.u8name), fso.u8name))
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
635 else:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
636 if linktgt.fspath is None:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
637 dir_tainted = True
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
638 linkdgst.update(util.interpolate_bytes(
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
639 b"%d:%s,",
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
640 len(linktgt.alt_fspath),
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
641 linktgt.alt_fspath))
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
642 else:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
643 linkdgst.update(util.interpolate_bytes(
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
644 b"%d:%s,",
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
645 len(linktgt.fspath),
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
646 linktgt.fspath))
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
647 if fso.fsname is None:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
648 dir_tainted = True
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
649 dir_dgst.update(util.interpolate_bytes(
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
650 b"1:S,%d:%s,",
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
651 len(fso.alt_fsname),
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
652 fso.alt_fsname))
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
653 else:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
654 dir_dgst.update(util.interpolate_bytes(
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
655 b"1:S,%d:%s,", len(fso.fsname), fso.fsname))
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
656 #
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
657 # - no mtime and no mode for symlinks
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
658 # - also does not count for dir_size
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
659 #
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
660 dir_dgst.update(util.interpolate_bytes(
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
661 b"%d:%s,",
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
662 len(linkdgst.digest()), linkdgst.digest()))
204
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
663 opath = join_output_path(top, fso.name)
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
664 if self._utf8_mode:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
665 opath = walk.WalkDirEntry.alt_u8(opath)
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
666 else:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
667 opath = walk.WalkDirEntry.alt_fs(opath)
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
668 if self._size_only:
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
669 self._outfp.write(format_bsd_line(
218
dee891ed2307 FIX: Output of symlinks was not converted property but was written in bytes repr
Franz Glasner <fzglas.hg@dom66.de>
parents: 217
diff changeset
670 "SIZE", None,
dee891ed2307 FIX: Output of symlinks was not converted property but was written in bytes repr
Franz Glasner <fzglas.hg@dom66.de>
parents: 217
diff changeset
671 util.interpolate_bytes(b"%s/./@/", opath),
dee891ed2307 FIX: Output of symlinks was not converted property but was written in bytes repr
Franz Glasner <fzglas.hg@dom66.de>
parents: 217
diff changeset
672 False, 0))
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
673 else:
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
674 self._outfp.write(format_bsd_line(
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
675 self._algorithm[1],
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
676 linkdgst.digest(),
218
dee891ed2307 FIX: Output of symlinks was not converted property but was written in bytes repr
Franz Glasner <fzglas.hg@dom66.de>
parents: 217
diff changeset
677 util.interpolate_bytes(b"%s/./@/", opath),
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
678 self._use_base64))
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
679 self._outfp.flush()
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
680 else:
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
681 #
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
682 # Follow the symlink to dir or handle a "real" directory
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
683 #
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
684
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
685 # Get subdir data from recursing into it
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
686 sub_dir_dgst, sub_dir_size = self._generate(
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
687 root, top + (fso.name, ))
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
688
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
689 dir_size += sub_dir_size
204
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
690 if self._utf8_mode:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
691 if fso.u8name is None:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
692 dir_tainted = True
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
693 dir_dgst.update(util.interpolate_bytes(
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
694 b"1:d,%d:%s,",
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
695 len(fso.alt_u8name),
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
696 fso.alt_u8name))
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
697 else:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
698 dir_dgst.update(util.interpolate_bytes(
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
699 b"1:d,%d:%s,", len(fso.u8name), fso.u8name))
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
700 else:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
701 if fso.fsname is None:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
702 dir_tainted = True
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
703 dir_dgst.update(util.interpolate_bytes(
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
704 b"1:d,%d:%s,",
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
705 len(fso.alt_fsname),
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
706 fso.alt_fsname))
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
707 else:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
708 dir_dgst.update(util.interpolate_bytes(
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
709 b"1:d,%d:%s,", len(fso.fsname), fso.fsname))
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
710 dir_dgst.update(util.interpolate_bytes(
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
711 b"%d:%s,", len(sub_dir_dgst), sub_dir_dgst))
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
712 if self._with_metadata_full_mode:
188
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
713 modestr = util.b(normalized_mode_str(fso.stat.st_mode))
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
714 dir_dgst.update(util.interpolate_bytes(
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
715 b"8:fullmode,%d:%s,", len(modestr), modestr))
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
716 elif self._with_metadata_mode:
188
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
717 modestr = util.b(normalized_compatible_mode_str(
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
718 fso.stat.st_mode))
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
719 dir_dgst.update(util.interpolate_bytes(
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
720 b"4:mode,%d:%s,", len(modestr), modestr))
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
721 else:
217
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
722 if fso.is_symlink and not self._follow_symlinks.file:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
723 linktgt = walk.WalkDirEntry.from_readlink(
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
724 os.readlink(fso.path))
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
725 # linktgt = util.fsencode(os.readlink(fso.path)))
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
726 linkdgst = self._algorithm[0]()
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
727 if self._utf8_mode:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
728 if linktgt.u8path is None:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
729 dir_tainted = True
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
730 linkdgst.update(util.interpolate_bytes(
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
731 b"%d:%s,",
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
732 len(linktgt.alt_u8path),
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
733 linktgt.alt_u8path))
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
734 else:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
735 linkdgst.update(util.interpolate_bytes(
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
736 b"%d:%s,",
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
737 len(linktgt.u8path),
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
738 linktgt.u8path))
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
739 if fso.u8name is None:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
740 dir_tainted = True
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
741 dir_dgst.update(util.interpolate_bytes(
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
742 b"1:F,%d:%s,",
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
743 len(fso.alt_u8name),
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
744 fso.alt_u8name))
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
745 else:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
746 dir_dgst.update(util.interpolate_bytes(
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
747 b"1:F,%d:%s,", len(fso.u8name), fso.u8name))
204
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
748 else:
217
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
749 if linktgt.fspath is None:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
750 dir_tainted = True
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
751 linkdgst.update(util.interpolate_bytes(
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
752 b"%d:%s,",
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
753 len(linktgt.alt_fspath),
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
754 linktgt.alt_fspath))
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
755 else:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
756 linkdgst.update(util.interpolate_bytes(
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
757 b"%d:%s,",
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
758 len(linktgt.fspath),
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
759 linktgt.fspath))
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
760 if fso.fsname is None:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
761 dir_tainted = True
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
762 dir_dgst.update(util.interpolate_bytes(
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
763 b"1:F,%d:%s,",
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
764 len(fso.alt_fsname),
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
765 fso.alt_fsname))
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
766 else:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
767 dir_dgst.update(util.interpolate_bytes(
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
768 b"1:F,%d:%s,", len(fso.fsname), fso.fsname))
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
769 #
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
770 # - no mtime and no mode for symlinks
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
771 # - also does not count for dir_size
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
772 #
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
773 dir_dgst.update(util.interpolate_bytes(
217
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
774 b"%d:%s,",
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
775 len(linkdgst.digest()), linkdgst.digest()))
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
776 opath = join_output_path(top, fso.name)
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
777 if self._utf8_mode:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
778 opath = walk.WalkDirEntry.alt_u8(opath)
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
779 else:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
780 opath = walk.WalkDirEntry.alt_fs(opath)
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
781 if self._size_only:
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
782 self._outfp.write(format_bsd_line(
218
dee891ed2307 FIX: Output of symlinks was not converted property but was written in bytes repr
Franz Glasner <fzglas.hg@dom66.de>
parents: 217
diff changeset
783 "SIZE", None,
dee891ed2307 FIX: Output of symlinks was not converted property but was written in bytes repr
Franz Glasner <fzglas.hg@dom66.de>
parents: 217
diff changeset
784 util.interpolate_bytes(b"%s/./@", opath),
dee891ed2307 FIX: Output of symlinks was not converted property but was written in bytes repr
Franz Glasner <fzglas.hg@dom66.de>
parents: 217
diff changeset
785 False, 0))
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
786 else:
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
787 self._outfp.write(format_bsd_line(
217
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
788 self._algorithm[1],
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
789 linkdgst.digest(),
218
dee891ed2307 FIX: Output of symlinks was not converted property but was written in bytes repr
Franz Glasner <fzglas.hg@dom66.de>
parents: 217
diff changeset
790 util.interpolate_bytes(b"%s/./@", opath),
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
791 self._use_base64))
217
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
792 self._outfp.flush()
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
793 else:
223
61e5b1c2685c Commentx
Franz Glasner <fzglas.hg@dom66.de>
parents: 221
diff changeset
794 #
61e5b1c2685c Commentx
Franz Glasner <fzglas.hg@dom66.de>
parents: 221
diff changeset
795 # Follow the symlink to file or handle a "real" file
61e5b1c2685c Commentx
Franz Glasner <fzglas.hg@dom66.de>
parents: 221
diff changeset
796 #
61e5b1c2685c Commentx
Franz Glasner <fzglas.hg@dom66.de>
parents: 221
diff changeset
797
217
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
798 if self._utf8_mode:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
799 if fso.u8name is None:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
800 dir_tainted = True
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
801 dir_dgst.update(util.interpolate_bytes(
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
802 b"1:f,%d:%s,",
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
803 len(fso.alt_u8name),
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
804 fso.alt_u8name))
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
805 else:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
806 dir_dgst.update(util.interpolate_bytes(
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
807 b"1:f,%d:%s,", len(fso.u8name), fso.u8name))
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
808 else:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
809 if fso.fsname is None:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
810 dir_tainted = True
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
811 dir_dgst.update(util.interpolate_bytes(
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
812 b"1:f,%d:%s,",
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
813 len(fso.alt_fsname),
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
814 fso.alt_fsname))
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
815 else:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
816 dir_dgst.update(util.interpolate_bytes(
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
817 b"1:f,%d:%s,", len(fso.fsname), fso.fsname))
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
818 dir_size += fso.stat.st_size
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
819 if self._with_metadata_mtime:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
820 mtime = datetime.datetime.utcfromtimestamp(
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
821 int(fso.stat.st_mtime))
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
822 mtime = util.b(mtime.isoformat("T") + "Z")
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
823 dir_dgst.update(util.interpolate_bytes(
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
824 b"5:mtime,%d:%s,", len(mtime), mtime))
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
825 if self._with_metadata_full_mode:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
826 modestr = util.b(normalized_mode_str(fso.stat.st_mode))
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
827 dir_dgst.update(util.interpolate_bytes(
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
828 b"8:fullmode,%d:%s,", len(modestr), modestr))
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
829 elif self._with_metadata_mode:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
830 modestr = util.b(normalized_compatible_mode_str(
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
831 fso.stat.st_mode))
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
832 dir_dgst.update(util.interpolate_bytes(
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
833 b"4:mode,%d:%s,", len(modestr), modestr))
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
834 if not self._size_only:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
835 dgst = digest.compute_digest_file(
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
836 self._algorithm[0],
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
837 fso.path,
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
838 use_mmap=self._use_mmap)
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
839 dir_dgst.update(util.interpolate_bytes(
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
840 b"%d:%s,", len(dgst), dgst))
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
841 opath = join_output_path(top, fso.name)
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
842 if self._utf8_mode:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
843 opath = walk.WalkDirEntry.alt_u8(opath)
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
844 else:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
845 opath = walk.WalkDirEntry.alt_fs(opath)
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
846 if self._size_only:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
847 self._outfp.write(format_bsd_line(
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
848 "SIZE", None, opath, False, fso.stat.st_size))
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
849 else:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
850 if self._print_size:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
851 self._outfp.write(format_bsd_line(
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
852 self._algorithm[1],
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
853 dgst, opath,
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
854 self._use_base64,
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
855 fso.stat.st_size))
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
856 else:
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
857 self._outfp.write(format_bsd_line(
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
858 self._algorithm[1], dgst, opath,
8e38c07c4b85 Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents: 213
diff changeset
859 self._use_base64))
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
860 self._outfp.flush()
204
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
861 opath = join_output_path(top, None)
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
862 if opath:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
863 if self._utf8_mode:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
864 opath = walk.WalkDirEntry.alt_u8(opath)
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
865 else:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
866 opath = walk.WalkDirEntry.alt_fs(opath)
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
867 if self._size_only:
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
868 self._outfp.write(format_bsd_line(
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
869 "SIZE", None, opath, False, dir_size))
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
870 else:
204
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
871 if dir_tainted:
219
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
872 #
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
873 # IMPORTANT: Print errors BEFORE the associated digest line.
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
874 # Otherwise the "info" command has a problem.
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
875 #
204
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
876 self._outfp.write(format_bsd_line(
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
877 b"ERROR", None, b"directory is tainted", False, None))
213
5a2d9ec204ce Also log filename problems to stderr
Franz Glasner <fzglas.hg@dom66.de>
parents: 211
diff changeset
878 logging.error("Directory has filename problems: %r", opath)
177
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
879 if self._print_size:
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
880 self._outfp.write(format_bsd_line(
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
881 self._algorithm[1], dir_dgst.digest(), opath,
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
882 self._use_base64, dir_size))
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
883 else:
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
884 self._outfp.write(format_bsd_line(
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
885 self._algorithm[1], dir_dgst.digest(), opath,
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
886 self._use_base64))
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
887 self._outfp.flush()
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
888 return (dir_dgst.digest(), dir_size)
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
889
089c40240061 Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents: 176
diff changeset
890
204
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
891 def join_output_path(top, name):
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
892 if name is None:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
893 # a path for a directory is to be computed
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
894 if top:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
895 if isinstance(top[0], bytes):
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
896 return b"/".join(top) + b"/"
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
897 else:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
898 return u"/".join(top) + u"/"
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
899 else:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
900 return b""
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
901 else:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
902 # a path for a normal file is to be computed
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
903 if top:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
904 if isinstance(name, bytes):
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
905 return b"/".join(top) + b"/" + name
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
906 else:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
907 return u"/".join(top) + u"/" + name
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
908 else:
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
909 return name
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
910
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
911
179
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
912 class CRC32Output(object):
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
913
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
914 """Wrapper for a minimal binary file contextmanager that calculates
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
915 the CRC32 of the written bytes on the fly.
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
916
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
917 Also acts as context manager proxy for the given context manager.
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
918
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
919 """
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
920
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
921 __slots__ = ("_fp_cm", "_fp", "_crc32")
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
922
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
923 def __init__(self, fp_cm):
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
924 self._fp_cm = fp_cm
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
925 self._fp = None
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
926 self.resetdigest()
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
927
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
928 def __enter__(self):
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
929 assert self._fp is None
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
930 self._fp = self._fp_cm.__enter__()
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
931 return self
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
932
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
933 def __exit__(self, *args):
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
934 rv = self._fp_cm.__exit__(*args)
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
935 self._fp = None
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
936 return rv
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
937
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
938 def write(self, what):
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
939 self._fp.write(what)
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
940 self._crc32 = zlib.crc32(what, self._crc32)
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
941
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
942 def flush(self):
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
943 self._fp.flush()
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
944
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
945 def resetdigest(self):
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
946 """Reset the current CRC digest"""
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
947 self._crc32 = zlib.crc32(b"")
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
948
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
949 def hexcrcdigest(self):
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
950 """
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
951
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
952 :rtype: str
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
953
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
954 """
197
48e2610978e5 Return the CRC-32 digest on Python2 as unsigned int instead of a signed one.
Franz Glasner <fzglas.hg@dom66.de>
parents: 193
diff changeset
955 return (hex(self.crcdigest())[2:]).upper()
179
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
956
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
957 def crcdigest(self):
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
958 """
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
959
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
960 :rtype: int
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
961
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
962 """
197
48e2610978e5 Return the CRC-32 digest on Python2 as unsigned int instead of a signed one.
Franz Glasner <fzglas.hg@dom66.de>
parents: 193
diff changeset
963 if util.PY2:
207
0e8c12ff0f41 FIX: For Python2.7 correct the CRC only if is < 0
Franz Glasner <fzglas.hg@dom66.de>
parents: 206
diff changeset
964 if self._crc32 < 0:
0e8c12ff0f41 FIX: For Python2.7 correct the CRC only if is < 0
Franz Glasner <fzglas.hg@dom66.de>
parents: 206
diff changeset
965 # Return the bitpattern as unsigned 32-bit number
0e8c12ff0f41 FIX: For Python2.7 correct the CRC only if is < 0
Franz Glasner <fzglas.hg@dom66.de>
parents: 206
diff changeset
966 return (~self._crc32 ^ 0xFFFFFFFF)
0e8c12ff0f41 FIX: For Python2.7 correct the CRC only if is < 0
Franz Glasner <fzglas.hg@dom66.de>
parents: 206
diff changeset
967 else:
0e8c12ff0f41 FIX: For Python2.7 correct the CRC only if is < 0
Franz Glasner <fzglas.hg@dom66.de>
parents: 206
diff changeset
968 return self._crc32
197
48e2610978e5 Return the CRC-32 digest on Python2 as unsigned int instead of a signed one.
Franz Glasner <fzglas.hg@dom66.de>
parents: 193
diff changeset
969 else:
48e2610978e5 Return the CRC-32 digest on Python2 as unsigned int instead of a signed one.
Franz Glasner <fzglas.hg@dom66.de>
parents: 193
diff changeset
970 return self._crc32
179
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
971
53614a724bf0 Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents: 178
diff changeset
972
158
d8cdd1985d43 Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents: 157
diff changeset
973 def normalized_compatible_mode_str(mode):
157
27d1aaf5fe39 Implement "--mode" flag for "treesum.py" to consider file portable mode bits
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
974 # XXX FIXME: Windows and "executable"
27d1aaf5fe39 Implement "--mode" flag for "treesum.py" to consider file portable mode bits
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
975 modebits = stat.S_IMODE(mode)
27d1aaf5fe39 Implement "--mode" flag for "treesum.py" to consider file portable mode bits
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
976 modestr = "%o" % (modebits,)
27d1aaf5fe39 Implement "--mode" flag for "treesum.py" to consider file portable mode bits
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
977 if not modestr.startswith("0"):
27d1aaf5fe39 Implement "--mode" flag for "treesum.py" to consider file portable mode bits
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
978 modestr = "0" + modestr
27d1aaf5fe39 Implement "--mode" flag for "treesum.py" to consider file portable mode bits
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
979 return modestr
27d1aaf5fe39 Implement "--mode" flag for "treesum.py" to consider file portable mode bits
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
980
27d1aaf5fe39 Implement "--mode" flag for "treesum.py" to consider file portable mode bits
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
981
158
d8cdd1985d43 Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents: 157
diff changeset
982 def normalized_mode_str(mode):
d8cdd1985d43 Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents: 157
diff changeset
983 modestr = "%o" % (mode,)
d8cdd1985d43 Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents: 157
diff changeset
984 if not modestr.startswith("0"):
d8cdd1985d43 Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents: 157
diff changeset
985 modestr = "0" + modestr
d8cdd1985d43 Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents: 157
diff changeset
986 return modestr
d8cdd1985d43 Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents: 157
diff changeset
987
d8cdd1985d43 Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents: 157
diff changeset
988
170
8945be6b404e Mode for treesum.py to print only the size of files and the accumulated size of a directory: --size-only.
Franz Glasner <fzglas.hg@dom66.de>
parents: 169
diff changeset
989 def format_bsd_line(what, value, filename, use_base64, size=None):
188
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
990 ls = util.b(os.linesep)
170
8945be6b404e Mode for treesum.py to print only the size of files and the accumulated size of a directory: --size-only.
Franz Glasner <fzglas.hg@dom66.de>
parents: 169
diff changeset
991 if not isinstance(what, bytes):
8945be6b404e Mode for treesum.py to print only the size of files and the accumulated size of a directory: --size-only.
Franz Glasner <fzglas.hg@dom66.de>
parents: 169
diff changeset
992 what = what.encode("ascii")
8945be6b404e Mode for treesum.py to print only the size of files and the accumulated size of a directory: --size-only.
Franz Glasner <fzglas.hg@dom66.de>
parents: 169
diff changeset
993 if what == b"TIMESTAMP":
129
bdd8ea43074b Output FLAGS as line "FLAGS = ..." instead of "FLAGS (...)"
Franz Glasner <fzglas.hg@dom66.de>
parents: 128
diff changeset
994 assert filename is None
173
e081b6ee5570 treesum.py now runs on Python3.4 also: use a workaround for its missing byte % formatting.
Franz Glasner <fzglas.hg@dom66.de>
parents: 172
diff changeset
995 return util.interpolate_bytes(b"TIMESTAMP = %d%s", value, ls)
198
c1e875ba4bdc Put the effective filesystem encoding into the treesum digest file using FSENCODING = <encoding>
Franz Glasner <fzglas.hg@dom66.de>
parents: 197
diff changeset
996 if what in (b"FSENCODING", b"ISOTIMESTAMP", b"FLAGS", b"VERSION",
c1e875ba4bdc Put the effective filesystem encoding into the treesum digest file using FSENCODING = <encoding>
Franz Glasner <fzglas.hg@dom66.de>
parents: 197
diff changeset
997 b"CRC32"):
129
bdd8ea43074b Output FLAGS as line "FLAGS = ..." instead of "FLAGS (...)"
Franz Glasner <fzglas.hg@dom66.de>
parents: 128
diff changeset
998 assert filename is None
188
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
999 return util.interpolate_bytes(b"%s = %s%s", what, util.b(value), ls)
129
bdd8ea43074b Output FLAGS as line "FLAGS = ..." instead of "FLAGS (...)"
Franz Glasner <fzglas.hg@dom66.de>
parents: 128
diff changeset
1000 assert filename is not None
205
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
1001 if what in (b"COMMENT", b"ERROR", b"GENERATOR"):
188
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1002 return util.interpolate_bytes(
204
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
1003 b"%s (%s)%s", what, util.b(filename, "utf-8"), ls)
124
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1004 if not isinstance(filename, bytes):
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1005 filename = util.fsencode(filename)
170
8945be6b404e Mode for treesum.py to print only the size of files and the accumulated size of a directory: --size-only.
Franz Glasner <fzglas.hg@dom66.de>
parents: 169
diff changeset
1006 if what == b"SIZE":
173
e081b6ee5570 treesum.py now runs on Python3.4 also: use a workaround for its missing byte % formatting.
Franz Glasner <fzglas.hg@dom66.de>
parents: 172
diff changeset
1007 return util.interpolate_bytes(b"SIZE (%s) = %d%s", filename, size, ls)
128
7c646921a479 Add TIMESTAMP and ISOTIMESTAMP to the output
Franz Glasner <fzglas.hg@dom66.de>
parents: 127
diff changeset
1008 if value is None:
173
e081b6ee5570 treesum.py now runs on Python3.4 also: use a workaround for its missing byte % formatting.
Franz Glasner <fzglas.hg@dom66.de>
parents: 172
diff changeset
1009 return util.interpolate_bytes(b"%s (%s)%s", what, filename, ls)
124
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1010 if use_base64:
128
7c646921a479 Add TIMESTAMP and ISOTIMESTAMP to the output
Franz Glasner <fzglas.hg@dom66.de>
parents: 127
diff changeset
1011 value = base64.b64encode(value)
124
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1012 else:
128
7c646921a479 Add TIMESTAMP and ISOTIMESTAMP to the output
Franz Glasner <fzglas.hg@dom66.de>
parents: 127
diff changeset
1013 value = binascii.hexlify(value)
193
fb36e71f6ba8 Change: path indicators for symlinks: ./@ -> ./@/ and /./@ -> /./@/
Franz Glasner <fzglas.hg@dom66.de>
parents: 191
diff changeset
1014 if filename != b"./@/":
127
6a50d02fe0ca Change the filename output: make it more consistent
Franz Glasner <fzglas.hg@dom66.de>
parents: 125
diff changeset
1015 filename = util.normalize_filename(filename, True)
168
bcc4441cf216 Implement "--print-size" to print file and accumulated directory sizes also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 161
diff changeset
1016 if size is None:
173
e081b6ee5570 treesum.py now runs on Python3.4 also: use a workaround for its missing byte % formatting.
Franz Glasner <fzglas.hg@dom66.de>
parents: 172
diff changeset
1017 return util.interpolate_bytes(
e081b6ee5570 treesum.py now runs on Python3.4 also: use a workaround for its missing byte % formatting.
Franz Glasner <fzglas.hg@dom66.de>
parents: 172
diff changeset
1018 b"%s (%s) = %s%s", what, filename, value, ls)
168
bcc4441cf216 Implement "--print-size" to print file and accumulated directory sizes also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 161
diff changeset
1019 else:
173
e081b6ee5570 treesum.py now runs on Python3.4 also: use a workaround for its missing byte % formatting.
Franz Glasner <fzglas.hg@dom66.de>
parents: 172
diff changeset
1020 return util.interpolate_bytes(
e081b6ee5570 treesum.py now runs on Python3.4 also: use a workaround for its missing byte % formatting.
Franz Glasner <fzglas.hg@dom66.de>
parents: 172
diff changeset
1021 b"%s (%s) = %s,%d%s", what, filename, value, size, ls)
124
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1022
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1023
188
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1024 class TreesumReader(object):
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1025
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1026 """Reader to read and/or verify treesum digest files.
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1027
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1028 Supports the iterator and context manager protocol.
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1029
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1030 """
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1031
204
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
1032 PATTERN0 = re.compile(br"\A[ \t]*\r?\n\Z") # empty lines
198
c1e875ba4bdc Put the effective filesystem encoding into the treesum digest file using FSENCODING = <encoding>
Franz Glasner <fzglas.hg@dom66.de>
parents: 197
diff changeset
1033 PATTERN1 = re.compile(br"\A(VERSION|FSENCODING|FLAGS|TIMESTAMP|ISOTIMESTAMP|CRC32)[ \t]*=[ \t]*([^ \t]+)[ \t]*\r?\n\Z") # noqa: E501 line too long
205
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
1034 PATTERN2 = re.compile(br"\A(ROOT|COMMENT|ERROR|GENERATOR)[ \t]*\((.*)\)[ \t]*\r?\n\Z") # noqa: E501 line too long
204
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
1035 PATTERN3 = re.compile(br"\ASIZE[ \t]*\((.*)\)[ \t]*=[ \t]*(\d+)[ \t]*\r?\n\Z") # noqa: E501 line too long
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
1036 PATTERN4 = re.compile(br"\A([A-Za-z0-9_-]+)[ \t]*\((.*)\)[ \t]*=[ \t]*([A-Za-z0-9=+/]+)(,(\d+))?[ \t]*\r?\n\Z") # noqa: E501 line too long
188
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1037
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1038 def __init__(self, _fp, _filename, _own_fp):
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1039 self._fp = _fp
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1040 self._own_fp = _own_fp
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1041 self._filename = _filename
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1042 self._line_no = 0
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1043 self._reset_crc()
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1044 self._expect_crc = None # NOTE: tristate: None is different from False
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1045 self._current_algo_name = self._current_algo_digest_size = None
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1046
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1047 @classmethod
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1048 def from_path(cls_, path):
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1049 """Open file at `path` and return a reader that owns the file object"""
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1050 return cls_(open(path, "rb"), path, True)
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1051
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1052 @classmethod
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1053 def from_binary_buffer(cls_, binary_fp, filename):
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1054 return cls_(binary_fp, filename, False)
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1055
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1056 def __enter__(self):
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1057 return self
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1058
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1059 def __exit__(self, *args):
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1060 self.close()
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1061
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1062 def close(self):
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1063 if self._fp is not None:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1064 try:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1065 if self._own_fp:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1066 self._fp.close()
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1067 finally:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1068 self._fp = None
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1069
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1070 def __iter__(self):
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1071 return self
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1072
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1073 def __next__(self):
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1074 rec = self.read_record()
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1075 if rec is None:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1076 raise StopIteration()
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1077 return rec
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1078
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1079 if util.PY2:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1080 next = __next__
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1081
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1082 def all_records(self):
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1083 """Iterator over all remaining records"""
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1084 while True:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1085 rec = self.read_record()
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1086 if rec is None:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1087 return
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1088 yield rec
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1089
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1090 def read_record(self):
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1091 """Read and parse the "next" line.
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1092
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1093 :returns: `None` at EOF or the parsed contents of the line
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1094 :rtype: tuple or None
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1095
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1096 """
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1097 # Loop to skip empty lines
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1098 while True:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1099 line = self._get_next_line()
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1100 if not line:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1101 #
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1102 # Skip for empty files at the very beginning.
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1103 # Check only after the first VERSION line.
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1104 #
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1105 if self._expect_crc is not None:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1106 if self._expect_crc:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1107 logging.warning("CRC32 is missing at EOF")
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1108 return None
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1109 if not self.PATTERN0.search(line):
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1110 break
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1111 self._update_crc(line)
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1112 #
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1113 # At the beginning transparently skip an eventually embedded signify
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1114 # signature
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1115 #
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1116 if self._line_no == 1:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1117 if line.startswith(b"untrusted comment: "):
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1118 line = self._get_next_line()
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1119 if not line.endswith(b"\n"):
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1120 raise binascii.Error("No valid signify signature value")
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1121 # Try to decode for an early error check
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1122 base64.b64decode(line[:-1])
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1123 mo = self.PATTERN1.search(line)
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1124 if mo:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1125 if mo.group(1) == b"VERSION":
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1126 if self._expect_crc:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1127 logging.warning("CRC32 missing before line %d",
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1128 self._line_no)
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1129 self._reset_crc()
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1130 self._expect_crc = True
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1131 self._update_crc(line)
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1132 return ("VERSION", util.n(mo.group(2)))
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1133 if mo.group(1) == b"CRC32":
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1134 # TODO: check
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1135 if self._expect_crc is None:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1136 logging.warning("Lone CRC32 before VERSION in line %d",
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1137 self._line_no)
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1138 else:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1139 if self._expect_crc:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1140 if (self._hex_crc()
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1141 != mo.group(2).decode("latin1").upper()):
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1142 logging.warning(
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1143 "CRC32 mismatch in line %d:"
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1144 " expected: %s, given: %s",
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1145 self._line_no,
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1146 self._hex_crc(),
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1147 mo.group(2).decode("latin1").upper())
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1148 else:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1149 logging.warning("CRC32 before VERSION in line %d",
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1150 self._line_no)
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1151 # Do not update the CRC here but reset the state
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1152 self._expect_crc = False
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1153 return ("CRC32", util.n(mo.group(2)))
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1154 else:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1155 self._update_crc(line)
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1156 return (util.n(mo.group(1)), util.n(mo.group(2)))
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1157 else:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1158 mo = self.PATTERN2.search(line)
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1159 if mo:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1160 self._update_crc(line)
205
63088d3675bb Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 204
diff changeset
1161 if mo.group(1) in (b"COMMENT", b"ERROR", b"GENERATOR"):
204
07f1d79e6674 Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
1162 return (util.u(mo.group(1)), util.u(mo.group(2), "utf-8"))
188
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1163 elif mo.group(1) == b"ROOT":
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1164 return ("ROOT", mo.group(2))
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1165 assert False, line
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1166 else:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1167 mo = self.PATTERN3.search(line)
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1168 if mo:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1169 self._update_crc(line)
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1170 return ("SIZE", mo.group(1), int(util.n(mo.group(2)), 10))
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1171 else:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1172 mo = self.PATTERN4.search(line)
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1173 if mo:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1174 self._update_crc(line)
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1175 algo_name = util.n(mo.group(1))
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1176 if (len(mo.group(3)) ==
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1177 2 * self._get_digest_size(algo_name)):
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1178 # hex
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1179 digest = binascii.unhexlify(mo.group(3))
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1180 else:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1181 # base64
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1182 digest = base64.b64decode(mo.group(3))
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1183 if mo.group(4):
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1184 size = int(util.n(mo.group(5)), 10)
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1185 else:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1186 size = None
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1187 return (algo_name, mo.group(2), digest, size)
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1188 else:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1189 assert False, line
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1190 return line
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1191
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1192 def _get_next_line(self):
189
959c6d37b014 Extend the max line length to read to 4096, which is something along PATH_MAX onn Linux
Franz Glasner <fzglas.hg@dom66.de>
parents: 188
diff changeset
1193 line = self._fp.readline(4096) # along PATH_MAX on Linux
188
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1194 if line:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1195 self._line_no += 1
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1196 return line
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1197
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1198 def _reset_crc(self):
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1199 self._crc32 = zlib.crc32(b"")
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1200
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1201 def _update_crc(self, data):
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1202 self._crc32 = zlib.crc32(data, self._crc32)
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1203
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1204 def _hex_crc(self):
206
73d22943da5a FIX: CRC-32 validation on Python2.7: normalize to positive numbers
Franz Glasner <fzglas.hg@dom66.de>
parents: 205
diff changeset
1205 return (hex(self._get_crc())[2:]).upper()
73d22943da5a FIX: CRC-32 validation on Python2.7: normalize to positive numbers
Franz Glasner <fzglas.hg@dom66.de>
parents: 205
diff changeset
1206
73d22943da5a FIX: CRC-32 validation on Python2.7: normalize to positive numbers
Franz Glasner <fzglas.hg@dom66.de>
parents: 205
diff changeset
1207 def _get_crc(self):
73d22943da5a FIX: CRC-32 validation on Python2.7: normalize to positive numbers
Franz Glasner <fzglas.hg@dom66.de>
parents: 205
diff changeset
1208 """Get the current CRC always as positive number with the same bit#
73d22943da5a FIX: CRC-32 validation on Python2.7: normalize to positive numbers
Franz Glasner <fzglas.hg@dom66.de>
parents: 205
diff changeset
1209 pattern because Python2 yields negative numbers also.
73d22943da5a FIX: CRC-32 validation on Python2.7: normalize to positive numbers
Franz Glasner <fzglas.hg@dom66.de>
parents: 205
diff changeset
1210
73d22943da5a FIX: CRC-32 validation on Python2.7: normalize to positive numbers
Franz Glasner <fzglas.hg@dom66.de>
parents: 205
diff changeset
1211 :return: The current CRC value as positive number on all Python
73d22943da5a FIX: CRC-32 validation on Python2.7: normalize to positive numbers
Franz Glasner <fzglas.hg@dom66.de>
parents: 205
diff changeset
1212 versions
73d22943da5a FIX: CRC-32 validation on Python2.7: normalize to positive numbers
Franz Glasner <fzglas.hg@dom66.de>
parents: 205
diff changeset
1213 :rtype: int
73d22943da5a FIX: CRC-32 validation on Python2.7: normalize to positive numbers
Franz Glasner <fzglas.hg@dom66.de>
parents: 205
diff changeset
1214
73d22943da5a FIX: CRC-32 validation on Python2.7: normalize to positive numbers
Franz Glasner <fzglas.hg@dom66.de>
parents: 205
diff changeset
1215 """
73d22943da5a FIX: CRC-32 validation on Python2.7: normalize to positive numbers
Franz Glasner <fzglas.hg@dom66.de>
parents: 205
diff changeset
1216 if util.PY2:
207
0e8c12ff0f41 FIX: For Python2.7 correct the CRC only if is < 0
Franz Glasner <fzglas.hg@dom66.de>
parents: 206
diff changeset
1217 if self._crc32 < 0:
0e8c12ff0f41 FIX: For Python2.7 correct the CRC only if is < 0
Franz Glasner <fzglas.hg@dom66.de>
parents: 206
diff changeset
1218 # Return the bitpattern as unsigned 32-bit number
0e8c12ff0f41 FIX: For Python2.7 correct the CRC only if is < 0
Franz Glasner <fzglas.hg@dom66.de>
parents: 206
diff changeset
1219 return (~self._crc32 ^ 0xFFFFFFFF)
0e8c12ff0f41 FIX: For Python2.7 correct the CRC only if is < 0
Franz Glasner <fzglas.hg@dom66.de>
parents: 206
diff changeset
1220 else:
0e8c12ff0f41 FIX: For Python2.7 correct the CRC only if is < 0
Franz Glasner <fzglas.hg@dom66.de>
parents: 206
diff changeset
1221 return self._crc32
206
73d22943da5a FIX: CRC-32 validation on Python2.7: normalize to positive numbers
Franz Glasner <fzglas.hg@dom66.de>
parents: 205
diff changeset
1222 else:
73d22943da5a FIX: CRC-32 validation on Python2.7: normalize to positive numbers
Franz Glasner <fzglas.hg@dom66.de>
parents: 205
diff changeset
1223 return self._crc32
188
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1224
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1225 def _get_digest_size(self, algo_name):
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1226 if self._current_algo_name == algo_name:
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1227 return self._current_algo_digest_size
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1228 h = util.algotag2algotype(algo_name)()
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1229 self._current_algo_name = algo_name
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1230 self._current_algo_digest_size = h.digest_size
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1231 return self._current_algo_digest_size
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1232
2784fdcc99e5 Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents: 179
diff changeset
1233
190
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1234 def print_treesum_digestfile_infos(opts):
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1235 print_infos_for_digestfile(opts.digest_files, opts.print_only_last_block)
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1236
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1237
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1238 def print_infos_for_digestfile(digest_files, print_only_last_block=True):
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1239 for fn in digest_files:
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1240 if fn == "-":
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1241 if util.PY2:
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1242 reader = TreesumReader.from_binary_buffer(sys.stdin)
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1243 else:
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1244 reader = TreesumReader.from_binary_buffer(sys.stdin.buffer)
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1245 else:
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1246 reader = TreesumReader.from_path(fn)
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1247
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1248 with reader:
208
85e7edea8ac7 Print the filesystem encoding and the generator in the "info" output also
Franz Glasner <fzglas.hg@dom66.de>
parents: 207
diff changeset
1249 root = generator = flags = fsencoding = algorithm = digest \
85e7edea8ac7 Print the filesystem encoding and the generator in the "info" output also
Franz Glasner <fzglas.hg@dom66.de>
parents: 207
diff changeset
1250 = size = None
219
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
1251 errors = set()
190
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1252 comments = []
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1253 in_block = False
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1254 block_no = 0
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1255 for record in reader:
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1256 if record[0] == "VERSION":
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1257 assert record[1] == "1"
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1258 # start a new block
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1259 in_block = True
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1260 block_no += 1
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1261 root = flags = algorithm = digest = size = None
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1262 comments = []
208
85e7edea8ac7 Print the filesystem encoding and the generator in the "info" output also
Franz Glasner <fzglas.hg@dom66.de>
parents: 207
diff changeset
1263 elif record[0] == "GENERATOR":
85e7edea8ac7 Print the filesystem encoding and the generator in the "info" output also
Franz Glasner <fzglas.hg@dom66.de>
parents: 207
diff changeset
1264 generator = record[1]
85e7edea8ac7 Print the filesystem encoding and the generator in the "info" output also
Franz Glasner <fzglas.hg@dom66.de>
parents: 207
diff changeset
1265 elif record[0] == "FSENCODING":
85e7edea8ac7 Print the filesystem encoding and the generator in the "info" output also
Franz Glasner <fzglas.hg@dom66.de>
parents: 207
diff changeset
1266 fsencoding = record[1]
190
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1267 elif record[0] == "FLAGS":
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1268 flags = record[1]
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1269 elif record[0] == "ROOT":
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1270 root = record[1]
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1271 elif record[0] == "COMMENT":
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1272 comments.append(record[1])
219
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
1273 elif record[0] == "ERROR":
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
1274 errors.add(record[1])
208
85e7edea8ac7 Print the filesystem encoding and the generator in the "info" output also
Franz Glasner <fzglas.hg@dom66.de>
parents: 207
diff changeset
1275 elif record[0] in ("TIMESTAMP", "ISOTIMESTAMP"):
190
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1276 pass
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1277 elif record[0] == "CRC32":
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1278 pass
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1279 # in_block = False
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1280 else:
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1281 if not in_block:
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1282 continue
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1283 # digest line or size line
193
fb36e71f6ba8 Change: path indicators for symlinks: ./@ -> ./@/ and /./@ -> /./@/
Franz Glasner <fzglas.hg@dom66.de>
parents: 191
diff changeset
1284 if not record[1] or record[1] == b"./@/":
190
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1285 if record[0] == "SIZE":
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1286 algorithm = "SIZE"
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1287 digest = None
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1288 size = record[2]
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1289 else:
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1290 algorithm = record[0]
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1291 digest = record[2]
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1292 size = record[3]
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1293 if not print_only_last_block:
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1294 print_block_data(
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1295 block_no,
208
85e7edea8ac7 Print the filesystem encoding and the generator in the "info" output also
Franz Glasner <fzglas.hg@dom66.de>
parents: 207
diff changeset
1296 root, generator, fsencoding, flags, comments,
219
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
1297 errors, algorithm, digest, size)
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
1298 root = generator = flags = fsencoding = algorithm \
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
1299 = digest = size = None
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
1300 errors = set()
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
1301 comments = []
190
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1302 in_block = False
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1303 if print_only_last_block:
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1304 if not in_block:
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1305 if digest is not None or size is not None:
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1306 print_block_data(
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1307 block_no,
219
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
1308 root, generator, fsencoding, flags, comments, errors,
208
85e7edea8ac7 Print the filesystem encoding and the generator in the "info" output also
Franz Glasner <fzglas.hg@dom66.de>
parents: 207
diff changeset
1309 algorithm, digest, size)
190
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1310 else:
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1311 logging.warning("missing block end")
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1312
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1313
208
85e7edea8ac7 Print the filesystem encoding and the generator in the "info" output also
Franz Glasner <fzglas.hg@dom66.de>
parents: 207
diff changeset
1314 def print_block_data(block_no, tag, generator, fsencoding, flags, comments,
219
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
1315 errors, algorithm, digest, size):
190
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1316 digeststr = util.n(binascii.hexlify(digest)) if digest else "<no digest>"
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1317 sizestr = str(size) if size is not None else "<no size>"
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1318 print("BLOCK No %d:" % (block_no,))
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1319 print(" Tag:", tag)
208
85e7edea8ac7 Print the filesystem encoding and the generator in the "info" output also
Franz Glasner <fzglas.hg@dom66.de>
parents: 207
diff changeset
1320 print(" FS-Encoding:", fsencoding)
85e7edea8ac7 Print the filesystem encoding and the generator in the "info" output also
Franz Glasner <fzglas.hg@dom66.de>
parents: 207
diff changeset
1321 if generator:
85e7edea8ac7 Print the filesystem encoding and the generator in the "info" output also
Franz Glasner <fzglas.hg@dom66.de>
parents: 207
diff changeset
1322 print(" Generator:", generator)
190
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1323 print(" Flags:", flags if flags else "<none>")
220
8db78850d800 "treesum info": print comments only if not empty
Franz Glasner <fzglas.hg@dom66.de>
parents: 219
diff changeset
1324 if comments:
8db78850d800 "treesum info": print comments only if not empty
Franz Glasner <fzglas.hg@dom66.de>
parents: 219
diff changeset
1325 print(" Comments:", comments)
190
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1326 print(" Algorithm:", algorithm)
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1327 if algorithm != "SIZE":
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1328 print(" Digest:", digeststr)
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1329 print(" Size:", sizestr)
219
19eaba51c632 Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents: 218
diff changeset
1330 print(" Errors:", errors if errors else "<none>")
190
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1331
7e0c25a31757 First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents: 189
diff changeset
1332
124
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1333 if __name__ == "__main__":
3bd3f32b5e60 A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1334 sys.exit(main())