Mercurial > hgrepos > Python > apps > py-cutils
annotate cutils/treesum.py @ 217:8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sat, 25 Jan 2025 09:52:22 +0100 |
| parents | 5a2d9ec204ce |
| children | dee891ed2307 |
| 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 | 189 # Global options for all sub-commands. |
| 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") |
|
210
1be3af138183
Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents:
208
diff
changeset
|
518 if self._follow_symlinks.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
|
519 flags.append("follow-symlinks-commandline") |
|
1be3af138183
Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents:
208
diff
changeset
|
520 if self._follow_symlinks.directory: |
|
1be3af138183
Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents:
208
diff
changeset
|
521 flags.append("follow-symlinks-directory") |
|
1be3af138183
Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents:
208
diff
changeset
|
522 if self._follow_symlinks.file: |
|
1be3af138183
Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents:
208
diff
changeset
|
523 flags.append("follow-symlinks-file") |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
524 if self._size_only: |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
525 flags.append("size-only") |
|
202
b9b38584919b
First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents:
200
diff
changeset
|
526 if self._utf8_mode: |
|
b9b38584919b
First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents:
200
diff
changeset
|
527 flags.append("utf8-mode") |
|
211
5bb0b25f8e99
FIX: FLAGS output: wrong "else" for "utf-8-mode" and "print-size"
Franz Glasner <fzglas.hg@dom66.de>
parents:
210
diff
changeset
|
528 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
|
529 flags.append("print-size") |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
530 if flags: |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
531 flags.sort() |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
532 self._outfp.write( |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
533 format_bsd_line("FLAGS", ",".join(flags), None, False)) |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
534 |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
535 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
|
536 # 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
|
537 ts = int(time.time()) |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
538 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
|
539 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
|
540 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
|
541 |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
542 if comment: |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
543 for line in comment: |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
544 self._outfp.write( |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
545 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
|
546 |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
547 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
|
548 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
|
549 "ROOT", |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
550 None, |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
551 (walk.WalkDirEntry.alt_u8(self._minimal) |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
552 if self._minimal else b""), |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
553 False)) |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
554 else: |
|
204
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
555 self._outfp.write(format_bsd_line( |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
556 "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
|
557 self._outfp.flush() |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
558 |
|
210
1be3af138183
Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents:
208
diff
changeset
|
559 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
|
560 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
|
561 linkdgst = self._algorithm[0]() |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
562 linkdgst.update( |
|
202
b9b38584919b
First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents:
200
diff
changeset
|
563 util.interpolate_bytes( |
|
b9b38584919b
First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents:
200
diff
changeset
|
564 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
|
565 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
|
566 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
|
567 dir_dgst.update( |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
568 util.interpolate_bytes( |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
569 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
|
570 if self._size_only: |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
571 self._outfp.write( |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
572 format_bsd_line( |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
573 "SIZE", |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
574 None, |
|
193
fb36e71f6ba8
Change: path indicators for symlinks: ./@ -> ./@/ and /./@ -> /./@/
Franz Glasner <fzglas.hg@dom66.de>
parents:
191
diff
changeset
|
575 "./@/", |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
576 False, |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
577 0)) |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
578 else: |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
579 self._outfp.write( |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
580 format_bsd_line( |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
581 self._algorithm[1], |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
582 dir_dgst.digest(), |
|
193
fb36e71f6ba8
Change: path indicators for symlinks: ./@ -> ./@/ and /./@ -> /./@/
Franz Glasner <fzglas.hg@dom66.de>
parents:
191
diff
changeset
|
583 "./@/", |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
584 self._use_base64)) |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
585 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
|
586 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
|
587 "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
|
588 return |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
589 |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
590 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
|
591 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
|
592 "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
|
593 |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
594 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
|
595 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
|
596 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
|
597 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
|
598 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
|
599 if self._utf8_mode: |
|
b9b38584919b
First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents:
200
diff
changeset
|
600 fsobjects.sort(key=walk.WalkDirEntry.alt_sort_key) |
|
b9b38584919b
First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents:
200
diff
changeset
|
601 else: |
|
b9b38584919b
First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents:
200
diff
changeset
|
602 fsobjects.sort(key=walk.WalkDirEntry.sort_key) |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
603 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
|
604 dir_size = 0 |
|
204
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
605 dir_tainted = False |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
606 for fso in fsobjects: |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
607 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
|
608 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
|
609 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
|
610 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
|
611 # 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
|
612 linkdgst = self._algorithm[0]() |
|
204
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
613 if self._utf8_mode: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
614 if linktgt.u8path is None: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
615 dir_tainted = True |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
616 linkdgst.update(util.interpolate_bytes( |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
617 b"%d:%s,", |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
618 len(linktgt.alt_u8path), |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
619 linktgt.alt_u8path)) |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
620 else: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
621 linkdgst.update(util.interpolate_bytes( |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
622 b"%d:%s,", |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
623 len(linktgt.u8path), |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
624 linktgt.u8path)) |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
625 if fso.u8name is None: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
626 dir_tainted = True |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
627 dir_dgst.update(util.interpolate_bytes( |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
628 b"1:S,%d:%s,", |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
629 len(fso.alt_u8name), |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
630 fso.alt_u8name)) |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
631 else: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
632 dir_dgst.update(util.interpolate_bytes( |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
633 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
|
634 else: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
635 if linktgt.fspath is None: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
636 dir_tainted = True |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
637 linkdgst.update(util.interpolate_bytes( |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
638 b"%d:%s,", |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
639 len(linktgt.alt_fspath), |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
640 linktgt.alt_fspath)) |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
641 else: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
642 linkdgst.update(util.interpolate_bytes( |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
643 b"%d:%s,", |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
644 len(linktgt.fspath), |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
645 linktgt.fspath)) |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
646 if fso.fsname is None: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
647 dir_tainted = True |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
648 dir_dgst.update(util.interpolate_bytes( |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
649 b"1:S,%d:%s,", |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
650 len(fso.alt_fsname), |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
651 fso.alt_fsname)) |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
652 else: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
653 dir_dgst.update(util.interpolate_bytes( |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
654 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
|
655 # |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
656 # - 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
|
657 # - 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
|
658 # |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
659 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
|
660 b"%d:%s,", |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
661 len(linkdgst.digest()), linkdgst.digest())) |
|
204
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
662 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
|
663 if self._utf8_mode: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
664 opath = walk.WalkDirEntry.alt_u8(opath) |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
665 else: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
666 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
|
667 if self._size_only: |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
668 self._outfp.write(format_bsd_line( |
|
193
fb36e71f6ba8
Change: path indicators for symlinks: ./@ -> ./@/ and /./@ -> /./@/
Franz Glasner <fzglas.hg@dom66.de>
parents:
191
diff
changeset
|
669 "SIZE", None, "%s/./@/" % (opath,), False, 0)) |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
670 else: |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
671 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
|
672 self._algorithm[1], |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
673 linkdgst.digest(), |
|
193
fb36e71f6ba8
Change: path indicators for symlinks: ./@ -> ./@/ and /./@ -> /./@/
Franz Glasner <fzglas.hg@dom66.de>
parents:
191
diff
changeset
|
674 "%s/./@/" % (opath,), |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
675 self._use_base64)) |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
676 self._outfp.flush() |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
677 else: |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
678 # |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
679 # 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
|
680 # |
|
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 # 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
|
683 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
|
684 root, top + (fso.name, )) |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
685 |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
686 dir_size += sub_dir_size |
|
204
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
687 if self._utf8_mode: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
688 if fso.u8name is None: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
689 dir_tainted = True |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
690 dir_dgst.update(util.interpolate_bytes( |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
691 b"1:d,%d:%s,", |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
692 len(fso.alt_u8name), |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
693 fso.alt_u8name)) |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
694 else: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
695 dir_dgst.update(util.interpolate_bytes( |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
696 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
|
697 else: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
698 if fso.fsname is None: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
699 dir_tainted = True |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
700 dir_dgst.update(util.interpolate_bytes( |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
701 b"1:d,%d:%s,", |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
702 len(fso.alt_fsname), |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
703 fso.alt_fsname)) |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
704 else: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
705 dir_dgst.update(util.interpolate_bytes( |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
706 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
|
707 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
|
708 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
|
709 if self._with_metadata_full_mode: |
|
188
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
710 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
|
711 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
|
712 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
|
713 elif self._with_metadata_mode: |
|
188
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
714 modestr = util.b(normalized_compatible_mode_str( |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
715 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
|
716 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
|
717 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
|
718 else: |
|
217
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
719 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
|
720 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
|
721 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
|
722 # 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
|
723 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
|
724 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
|
725 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
|
726 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
|
727 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
|
728 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
|
729 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
|
730 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
|
731 else: |
|
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
732 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
|
733 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
|
734 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
|
735 linktgt.u8path)) |
|
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
736 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
|
737 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
|
738 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
|
739 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
|
740 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
|
741 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
|
742 else: |
|
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
743 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
|
744 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
|
745 else: |
|
217
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
746 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
|
747 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
|
748 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
|
749 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
|
750 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
|
751 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
|
752 else: |
|
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
753 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
|
754 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
|
755 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
|
756 linktgt.fspath)) |
|
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
757 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
|
758 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
|
759 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
|
760 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
|
761 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
|
762 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
|
763 else: |
|
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
764 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
|
765 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
|
766 # |
|
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
767 # - 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
|
768 # - 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
|
769 # |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
770 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
|
771 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
|
772 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
|
773 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
|
774 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
|
775 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
|
776 else: |
|
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
777 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
|
778 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
|
779 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
|
780 "SIZE", None, "%s/./@" % (opath,), False, 0)) |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
781 else: |
|
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( |
|
217
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
783 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
|
784 linkdgst.digest(), |
|
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
785 "%s/./@" % (opath,), |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
786 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
|
787 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
|
788 else: |
|
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
789 # follow symlinks to files |
|
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
790 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
|
791 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
|
792 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
|
793 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
|
794 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
|
795 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
|
796 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
|
797 else: |
|
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
798 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
|
799 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
|
800 else: |
|
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
801 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
|
802 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
|
803 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
|
804 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
|
805 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
|
806 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
|
807 else: |
|
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
808 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
|
809 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
|
810 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
|
811 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
|
812 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
|
813 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
|
814 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
|
815 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
|
816 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
|
817 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
|
818 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
|
819 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
|
820 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
|
821 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
|
822 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
|
823 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
|
824 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
|
825 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
|
826 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
|
827 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
|
828 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
|
829 fso.path, |
|
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
830 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
|
831 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
|
832 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
|
833 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
|
834 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
|
835 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
|
836 else: |
|
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
837 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
|
838 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
|
839 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
|
840 "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
|
841 else: |
|
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._print_size: |
|
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
843 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
|
844 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
|
845 dgst, opath, |
|
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
846 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
|
847 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
|
848 else: |
|
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
849 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
|
850 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
|
851 self._use_base64)) |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
852 self._outfp.flush() |
|
204
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
853 opath = join_output_path(top, None) |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
854 if opath: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
855 if self._utf8_mode: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
856 opath = walk.WalkDirEntry.alt_u8(opath) |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
857 else: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
858 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
|
859 if self._size_only: |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
860 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
|
861 "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
|
862 else: |
|
204
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
863 if dir_tainted: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
864 self._outfp.write(format_bsd_line( |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
865 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
|
866 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
|
867 if self._print_size: |
|
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 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
|
870 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
|
871 else: |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
872 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
|
873 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
|
874 self._use_base64)) |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
875 self._outfp.flush() |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
876 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
|
877 |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
878 |
|
204
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
879 def join_output_path(top, name): |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
880 if name is None: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
881 # 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
|
882 if top: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
883 if isinstance(top[0], bytes): |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
884 return b"/".join(top) + b"/" |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
885 else: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
886 return u"/".join(top) + u"/" |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
887 else: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
888 return b"" |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
889 else: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
890 # 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
|
891 if top: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
892 if isinstance(name, bytes): |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
893 return b"/".join(top) + b"/" + name |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
894 else: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
895 return u"/".join(top) + u"/" + name |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
896 else: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
897 return name |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
898 |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
899 |
|
179
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
900 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
|
901 |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
902 """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
|
903 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
|
904 |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
905 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
|
906 |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
907 """ |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
908 |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
909 __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
|
910 |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
911 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
|
912 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
|
913 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
|
914 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
|
915 |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
916 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
|
917 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
|
918 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
|
919 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
|
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 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
|
922 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
|
923 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
|
924 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
|
925 |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
926 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
|
927 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
|
928 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
|
929 |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
930 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
|
931 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
|
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 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
|
934 """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
|
935 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
|
936 |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
937 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
|
938 """ |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
939 |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
940 :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
|
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 """ |
|
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
|
943 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
|
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 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
|
946 """ |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
947 |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
948 :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
|
949 |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
950 """ |
|
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
|
951 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
|
952 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
|
953 # 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
|
954 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
|
955 else: |
|
0e8c12ff0f41
FIX: For Python2.7 correct the CRC only if is < 0
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
956 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
|
957 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
|
958 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
|
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 |
|
158
d8cdd1985d43
Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
961 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
|
962 # 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
|
963 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
|
964 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
|
965 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
|
966 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
|
967 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
|
968 |
|
27d1aaf5fe39
Implement "--mode" flag for "treesum.py" to consider file portable mode bits
Franz Glasner <fzglas.hg@dom66.de>
parents:
156
diff
changeset
|
969 |
|
158
d8cdd1985d43
Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
970 def normalized_mode_str(mode): |
|
d8cdd1985d43
Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
971 modestr = "%o" % (mode,) |
|
d8cdd1985d43
Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
972 if not modestr.startswith("0"): |
|
d8cdd1985d43
Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
973 modestr = "0" + modestr |
|
d8cdd1985d43
Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
974 return modestr |
|
d8cdd1985d43
Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
975 |
|
d8cdd1985d43
Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
976 |
|
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
|
977 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
|
978 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
|
979 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
|
980 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
|
981 if what == b"TIMESTAMP": |
|
129
bdd8ea43074b
Output FLAGS as line "FLAGS = ..." instead of "FLAGS (...)"
Franz Glasner <fzglas.hg@dom66.de>
parents:
128
diff
changeset
|
982 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
|
983 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
|
984 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
|
985 b"CRC32"): |
|
129
bdd8ea43074b
Output FLAGS as line "FLAGS = ..." instead of "FLAGS (...)"
Franz Glasner <fzglas.hg@dom66.de>
parents:
128
diff
changeset
|
986 assert filename is None |
|
188
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
987 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
|
988 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
|
989 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
|
990 return util.interpolate_bytes( |
|
204
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
991 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
|
992 if not isinstance(filename, bytes): |
|
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
993 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
|
994 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
|
995 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
|
996 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
|
997 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
|
998 if use_base64: |
|
128
7c646921a479
Add TIMESTAMP and ISOTIMESTAMP to the output
Franz Glasner <fzglas.hg@dom66.de>
parents:
127
diff
changeset
|
999 value = base64.b64encode(value) |
|
124
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1000 else: |
|
128
7c646921a479
Add TIMESTAMP and ISOTIMESTAMP to the output
Franz Glasner <fzglas.hg@dom66.de>
parents:
127
diff
changeset
|
1001 value = binascii.hexlify(value) |
|
193
fb36e71f6ba8
Change: path indicators for symlinks: ./@ -> ./@/ and /./@ -> /./@/
Franz Glasner <fzglas.hg@dom66.de>
parents:
191
diff
changeset
|
1002 if filename != b"./@/": |
|
127
6a50d02fe0ca
Change the filename output: make it more consistent
Franz Glasner <fzglas.hg@dom66.de>
parents:
125
diff
changeset
|
1003 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
|
1004 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
|
1005 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
|
1006 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
|
1007 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
|
1008 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
|
1009 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
|
1010 |
|
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1011 |
|
188
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1012 class TreesumReader(object): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1013 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1014 """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
|
1015 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1016 Supports the iterator and context manager protocol. |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1017 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1018 """ |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1019 |
|
204
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
1020 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
|
1021 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
|
1022 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
|
1023 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
|
1024 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
|
1025 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1026 def __init__(self, _fp, _filename, _own_fp): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1027 self._fp = _fp |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1028 self._own_fp = _own_fp |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1029 self._filename = _filename |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1030 self._line_no = 0 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1031 self._reset_crc() |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1032 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
|
1033 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
|
1034 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1035 @classmethod |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1036 def from_path(cls_, path): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1037 """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
|
1038 return cls_(open(path, "rb"), path, True) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1039 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1040 @classmethod |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1041 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
|
1042 return cls_(binary_fp, filename, False) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1043 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1044 def __enter__(self): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1045 return self |
|
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 def __exit__(self, *args): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1048 self.close() |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1049 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1050 def close(self): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1051 if self._fp is not None: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1052 try: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1053 if self._own_fp: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1054 self._fp.close() |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1055 finally: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1056 self._fp = None |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1057 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1058 def __iter__(self): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1059 return self |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1060 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1061 def __next__(self): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1062 rec = self.read_record() |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1063 if rec is None: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1064 raise StopIteration() |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1065 return rec |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1066 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1067 if util.PY2: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1068 next = __next__ |
|
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 all_records(self): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1071 """Iterator over all remaining records""" |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1072 while True: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1073 rec = self.read_record() |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1074 if rec is None: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1075 return |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1076 yield rec |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1077 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1078 def read_record(self): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1079 """Read and parse the "next" line. |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1080 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1081 :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
|
1082 :rtype: tuple or None |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1083 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1084 """ |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1085 # Loop to skip empty lines |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1086 while True: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1087 line = self._get_next_line() |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1088 if not line: |
|
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 # 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
|
1091 # Check only after the first VERSION 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 if self._expect_crc is not None: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1094 if self._expect_crc: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1095 logging.warning("CRC32 is missing at EOF") |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1096 return None |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1097 if not self.PATTERN0.search(line): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1098 break |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1099 self._update_crc(line) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1100 # |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1101 # 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
|
1102 # signature |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1103 # |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1104 if self._line_no == 1: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1105 if line.startswith(b"untrusted comment: "): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1106 line = self._get_next_line() |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1107 if not line.endswith(b"\n"): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1108 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
|
1109 # 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
|
1110 base64.b64decode(line[:-1]) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1111 mo = self.PATTERN1.search(line) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1112 if mo: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1113 if mo.group(1) == b"VERSION": |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1114 if self._expect_crc: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1115 logging.warning("CRC32 missing before line %d", |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1116 self._line_no) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1117 self._reset_crc() |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1118 self._expect_crc = True |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1119 self._update_crc(line) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1120 return ("VERSION", util.n(mo.group(2))) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1121 if mo.group(1) == b"CRC32": |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1122 # TODO: check |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1123 if self._expect_crc is None: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1124 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
|
1125 self._line_no) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1126 else: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1127 if self._expect_crc: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1128 if (self._hex_crc() |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1129 != mo.group(2).decode("latin1").upper()): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1130 logging.warning( |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1131 "CRC32 mismatch in line %d:" |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1132 " expected: %s, given: %s", |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1133 self._line_no, |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1134 self._hex_crc(), |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1135 mo.group(2).decode("latin1").upper()) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1136 else: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1137 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
|
1138 self._line_no) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1139 # 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
|
1140 self._expect_crc = False |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1141 return ("CRC32", util.n(mo.group(2))) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1142 else: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1143 self._update_crc(line) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1144 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
|
1145 else: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1146 mo = self.PATTERN2.search(line) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1147 if mo: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1148 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
|
1149 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
|
1150 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
|
1151 elif mo.group(1) == b"ROOT": |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1152 return ("ROOT", mo.group(2)) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1153 assert False, line |
|
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 mo = self.PATTERN3.search(line) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1156 if mo: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1157 self._update_crc(line) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1158 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
|
1159 else: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1160 mo = self.PATTERN4.search(line) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1161 if mo: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1162 self._update_crc(line) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1163 algo_name = util.n(mo.group(1)) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1164 if (len(mo.group(3)) == |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1165 2 * self._get_digest_size(algo_name)): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1166 # hex |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1167 digest = binascii.unhexlify(mo.group(3)) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1168 else: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1169 # base64 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1170 digest = base64.b64decode(mo.group(3)) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1171 if mo.group(4): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1172 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
|
1173 else: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1174 size = None |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1175 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
|
1176 else: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1177 assert False, line |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1178 return line |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1179 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1180 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
|
1181 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
|
1182 if line: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1183 self._line_no += 1 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1184 return line |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1185 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1186 def _reset_crc(self): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1187 self._crc32 = zlib.crc32(b"") |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1188 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1189 def _update_crc(self, data): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1190 self._crc32 = zlib.crc32(data, self._crc32) |
|
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 _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
|
1193 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
|
1194 |
|
73d22943da5a
FIX: CRC-32 validation on Python2.7: normalize to positive numbers
Franz Glasner <fzglas.hg@dom66.de>
parents:
205
diff
changeset
|
1195 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
|
1196 """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
|
1197 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
|
1198 |
|
73d22943da5a
FIX: CRC-32 validation on Python2.7: normalize to positive numbers
Franz Glasner <fzglas.hg@dom66.de>
parents:
205
diff
changeset
|
1199 :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
|
1200 versions |
|
73d22943da5a
FIX: CRC-32 validation on Python2.7: normalize to positive numbers
Franz Glasner <fzglas.hg@dom66.de>
parents:
205
diff
changeset
|
1201 :rtype: int |
|
73d22943da5a
FIX: CRC-32 validation on Python2.7: normalize to positive numbers
Franz Glasner <fzglas.hg@dom66.de>
parents:
205
diff
changeset
|
1202 |
|
73d22943da5a
FIX: CRC-32 validation on Python2.7: normalize to positive numbers
Franz Glasner <fzglas.hg@dom66.de>
parents:
205
diff
changeset
|
1203 """ |
|
73d22943da5a
FIX: CRC-32 validation on Python2.7: normalize to positive numbers
Franz Glasner <fzglas.hg@dom66.de>
parents:
205
diff
changeset
|
1204 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
|
1205 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
|
1206 # 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
|
1207 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
|
1208 else: |
|
0e8c12ff0f41
FIX: For Python2.7 correct the CRC only if is < 0
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
1209 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
|
1210 else: |
|
73d22943da5a
FIX: CRC-32 validation on Python2.7: normalize to positive numbers
Franz Glasner <fzglas.hg@dom66.de>
parents:
205
diff
changeset
|
1211 return self._crc32 |
|
188
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1212 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1213 def _get_digest_size(self, algo_name): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1214 if self._current_algo_name == algo_name: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1215 return self._current_algo_digest_size |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1216 h = util.algotag2algotype(algo_name)() |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1217 self._current_algo_name = algo_name |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1218 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
|
1219 return self._current_algo_digest_size |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1220 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1221 |
|
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
|
1222 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
|
1223 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
|
1224 |
|
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
|
1225 |
|
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
|
1226 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
|
1227 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
|
1228 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
|
1229 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
|
1230 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
|
1231 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
|
1232 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
|
1233 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
|
1234 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
|
1235 |
|
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 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
|
1237 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
|
1238 = size = 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
|
1239 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
|
1240 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
|
1241 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
|
1242 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
|
1243 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
|
1244 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
|
1245 # 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
|
1246 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
|
1247 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
|
1248 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
|
1249 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
|
1250 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
|
1251 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
|
1252 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
|
1253 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
|
1254 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
|
1255 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
|
1256 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
|
1257 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
|
1258 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
|
1259 comments.append(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
|
1260 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
|
1261 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
|
1262 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
|
1263 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
|
1264 # 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
|
1265 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
|
1266 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
|
1267 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
|
1268 # digest line or size line |
|
193
fb36e71f6ba8
Change: path indicators for symlinks: ./@ -> ./@/ and /./@ -> /./@/
Franz Glasner <fzglas.hg@dom66.de>
parents:
191
diff
changeset
|
1269 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
|
1270 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
|
1271 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
|
1272 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
|
1273 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
|
1274 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
|
1275 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
|
1276 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
|
1277 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
|
1278 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
|
1279 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
|
1280 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
|
1281 root, generator, fsencoding, flags, comments, |
|
85e7edea8ac7
Print the filesystem encoding and the generator in the "info" output also
Franz Glasner <fzglas.hg@dom66.de>
parents:
207
diff
changeset
|
1282 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
|
1283 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
|
1284 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
|
1285 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
|
1286 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
|
1287 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
|
1288 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
|
1289 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
|
1290 root, generator, fsencoding, flags, comments, |
|
85e7edea8ac7
Print the filesystem encoding and the generator in the "info" output also
Franz Glasner <fzglas.hg@dom66.de>
parents:
207
diff
changeset
|
1291 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
|
1292 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
|
1293 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
|
1294 |
|
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 |
|
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 def print_block_data(block_no, tag, generator, fsencoding, flags, comments, |
|
85e7edea8ac7
Print the filesystem encoding and the generator in the "info" output also
Franz Glasner <fzglas.hg@dom66.de>
parents:
207
diff
changeset
|
1297 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
|
1298 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
|
1299 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
|
1300 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
|
1301 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
|
1302 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
|
1303 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
|
1304 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
|
1305 print(" Flags:", flags if flags else "<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(" Comments:", comments if comments 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
|
1307 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
|
1308 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
|
1309 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
|
1310 print(" Size:", sizestr) |
|
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 |
|
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 |
|
124
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1313 if __name__ == "__main__": |
|
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1314 sys.exit(main()) |
