Mercurial > hgrepos > Python > apps > py-cutils
annotate cutils/treesum.py @ 299:bcbc68d8aa12
treesum: remove not obsolete comment about not following symlinks to files
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Tue, 04 Mar 2025 11:26:22 +0100 |
| parents | 4a259fb9968e |
| children | 1fc117f5f9a1 |
| 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 |
|
266
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
21 import errno |
|
176
7f5d05a625fd
Implement preconditions for some debug logging
Franz Glasner <fzglas.hg@dom66.de>
parents:
174
diff
changeset
|
22 import logging |
|
124
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
23 import os |
|
188
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
24 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
|
25 import stat |
|
124
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
26 import sys |
|
128
7c646921a479
Add TIMESTAMP and ISOTIMESTAMP to the output
Franz Glasner <fzglas.hg@dom66.de>
parents:
127
diff
changeset
|
27 import time |
|
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 |
|
260
07a0bc723139
treesum: Implement the CRC-32 using the new util.crc32 module
Franz Glasner <fzglas.hg@dom66.de>
parents:
223
diff
changeset
|
34 from .util.crc32 import crc32 |
|
124
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 |
|
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
37 def main(argv=None): |
|
142
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
38 |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
39 def _populate_generate_arguments(gp): |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
40 """Use to populate command aliases. |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
41 |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
42 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
|
43 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
|
44 |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
45 """ |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
46 gp.add_argument( |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
47 "--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
|
48 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
|
49 "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
|
50 "blake2b, blake2b-256, blake2s, " |
|
142
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
51 "blake2 (alias for blake2b), " |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
52 "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
|
53 "md5. " |
|
804a823c63f5
Now the selection of the default algorithm depends on availiability in hashlib
Franz Glasner <fzglas.hg@dom66.de>
parents:
170
diff
changeset
|
54 "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
|
55 "blake2b-256, sha256 or sha1.") |
|
142
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
56 gp.add_argument( |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
57 "--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
|
58 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
|
59 gp.add_argument( |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
60 "--base64", action="store_true", |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
61 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
|
62 "(OpenBSD).") |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
63 gp.add_argument( |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
64 "--comment", action="append", default=[], |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
65 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
|
66 "Can be given more than once.") |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
67 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
|
68 "--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
|
69 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
|
70 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
|
71 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
|
72 help="""Follow symbolic links to directories when walking a |
|
271
6fe88de236cb
treesum: Implement the --half/-H option: follow symlinks given on the command line but no other symlinks.
Franz Glasner <fzglas.hg@dom66.de>
parents:
270
diff
changeset
|
73 directory tree. Augments --physical, --half 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
|
74 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
|
75 "--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
|
76 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
|
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 |
|
271
6fe88de236cb
treesum: Implement the --half/-H option: follow symlinks given on the command line but no other symlinks.
Franz Glasner <fzglas.hg@dom66.de>
parents:
270
diff
changeset
|
79 directory tree. Augments --physical and --half.""") |
|
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( |
|
271
6fe88de236cb
treesum: Implement the --half/-H option: follow symlinks given on the command line but no other symlinks.
Franz Glasner <fzglas.hg@dom66.de>
parents:
270
diff
changeset
|
94 "--half", "-H", action=SymlinkAction, dest="follow_symlinks", |
|
6fe88de236cb
treesum: Implement the --half/-H option: follow symlinks given on the command line but no other symlinks.
Franz Glasner <fzglas.hg@dom66.de>
parents:
270
diff
changeset
|
95 const=FollowSymlinkConfig(True, False, False), |
|
6fe88de236cb
treesum: Implement the --half/-H option: follow symlinks given on the command line but no other symlinks.
Franz Glasner <fzglas.hg@dom66.de>
parents:
270
diff
changeset
|
96 help="""Follow symbolic links given on the command line but do |
|
6fe88de236cb
treesum: Implement the --half/-H option: follow symlinks given on the command line but no other symlinks.
Franz Glasner <fzglas.hg@dom66.de>
parents:
270
diff
changeset
|
97 not follow symlinks while traversing the directory tree. |
|
6fe88de236cb
treesum: Implement the --half/-H option: follow symlinks given on the command line but no other symlinks.
Franz Glasner <fzglas.hg@dom66.de>
parents:
270
diff
changeset
|
98 Overwrites any other symlink related options |
|
6fe88de236cb
treesum: Implement the --half/-H option: follow symlinks given on the command line but no other symlinks.
Franz Glasner <fzglas.hg@dom66.de>
parents:
270
diff
changeset
|
99 (--physical, --logical, -p, --no-follow-directory-symlinks, |
|
6fe88de236cb
treesum: Implement the --half/-H option: follow symlinks given on the command line but no other symlinks.
Franz Glasner <fzglas.hg@dom66.de>
parents:
270
diff
changeset
|
100 --no-follow-file-symlinks, et al.).""") |
|
6fe88de236cb
treesum: Implement the --half/-H option: follow symlinks given on the command line but no other symlinks.
Franz Glasner <fzglas.hg@dom66.de>
parents:
270
diff
changeset
|
101 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
|
102 "--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
|
103 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
|
104 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
|
105 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
|
106 Overwrites any other symlink related options |
|
271
6fe88de236cb
treesum: Implement the --half/-H option: follow symlinks given on the command line but no other symlinks.
Franz Glasner <fzglas.hg@dom66.de>
parents:
270
diff
changeset
|
107 (--physical, --half, -p, --no-follow-directory-symlinks, |
|
6fe88de236cb
treesum: Implement the --half/-H option: follow symlinks given on the command line but no other symlinks.
Franz Glasner <fzglas.hg@dom66.de>
parents:
270
diff
changeset
|
108 --no-follow-file-symlinks, et al.).""") |
|
142
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
109 gp.add_argument( |
|
150
f84cf853da22
Implement "--minimal [TAG]" for treesum.
Franz Glasner <fzglas.hg@dom66.de>
parents:
149
diff
changeset
|
110 "--minimal", nargs="?", const="", default=None, metavar="TAG", |
|
f84cf853da22
Implement "--minimal [TAG]" for treesum.
Franz Glasner <fzglas.hg@dom66.de>
parents:
149
diff
changeset
|
111 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
|
112 "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
|
113 gp.add_argument( |
|
142
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
114 "--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
|
115 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
|
116 "automatically from the filesize.") |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
117 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
|
118 "--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
|
119 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
|
120 "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
|
121 "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
|
122 "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
|
123 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
|
124 "--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
|
125 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
|
126 "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
|
127 "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
|
128 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
|
129 "--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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 "--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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 gp.add_argument( |
|
142
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
141 "--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
|
142 help="Dont use mmap.") |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
143 gp.add_argument( |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
144 "--output", "-o", action="store", metavar="OUTPUT", |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
145 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
|
146 "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
|
147 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
|
148 "--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
|
149 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
|
150 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
|
151 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
|
152 Overwrites any other symlink related options |
|
271
6fe88de236cb
treesum: Implement the --half/-H option: follow symlinks given on the command line but no other symlinks.
Franz Glasner <fzglas.hg@dom66.de>
parents:
270
diff
changeset
|
153 (--logical, --half, -p, --follow-directory-symlinks, --follow-file-symlinks, |
|
6fe88de236cb
treesum: Implement the --half/-H option: follow symlinks given on the command line but no other symlinks.
Franz Glasner <fzglas.hg@dom66.de>
parents:
270
diff
changeset
|
154 et al.).""") |
|
217
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
155 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
|
156 "-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
|
157 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
|
158 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
|
159 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
|
160 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
|
161 Overwrites any other symlink related options |
|
271
6fe88de236cb
treesum: Implement the --half/-H option: follow symlinks given on the command line but no other symlinks.
Franz Glasner <fzglas.hg@dom66.de>
parents:
270
diff
changeset
|
162 (--logical, --half, --physical, --follow-directory-symlinks, |
|
6fe88de236cb
treesum: Implement the --half/-H option: follow symlinks given on the command line but no other symlinks.
Franz Glasner <fzglas.hg@dom66.de>
parents:
270
diff
changeset
|
163 --no-follow-file-symlinks, 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
|
164 This is the default.""") |
|
142
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
165 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
|
166 "--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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 "--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
|
173 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
|
174 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
|
175 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
|
176 "--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
|
177 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
|
178 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
|
179 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
|
180 gp.add_argument( |
|
142
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
181 "directories", nargs="*", metavar="DIRECTORY") |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
182 |
|
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
|
183 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
|
184 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
|
185 "--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
|
186 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
|
187 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
|
188 "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
|
189 |
|
142
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
190 parser = argparse.ArgumentParser( |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
191 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
|
192 fromfile_prefix_chars='@', |
|
17d6e760143f
Optimize help / usage output for the global options.
Franz Glasner <fzglas.hg@dom66.de>
parents:
147
diff
changeset
|
193 add_help=False) |
|
142
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
194 |
|
148
17d6e760143f
Optimize help / usage output for the global options.
Franz Glasner <fzglas.hg@dom66.de>
parents:
147
diff
changeset
|
195 # |
| 153 | 196 # Global options for all sub-commands. |
| 197 # 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
|
198 # |
|
17d6e760143f
Optimize help / usage output for the global options.
Franz Glasner <fzglas.hg@dom66.de>
parents:
147
diff
changeset
|
199 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
|
200 gparser.add_argument( |
|
191
1b8bc876146a
Make "--debug" a global argument in treeview
Franz Glasner <fzglas.hg@dom66.de>
parents:
190
diff
changeset
|
201 "--debug", action="store_true", |
|
1b8bc876146a
Make "--debug" a global argument in treeview
Franz Glasner <fzglas.hg@dom66.de>
parents:
190
diff
changeset
|
202 help="Activate debug logging to stderr") |
|
1b8bc876146a
Make "--debug" a global argument in treeview
Franz Glasner <fzglas.hg@dom66.de>
parents:
190
diff
changeset
|
203 gparser.add_argument( |
|
142
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
204 "-v", "--version", action="version", |
|
148
17d6e760143f
Optimize help / usage output for the global options.
Franz Glasner <fzglas.hg@dom66.de>
parents:
147
diff
changeset
|
205 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
|
206 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
|
207 gparser.add_argument( |
|
17d6e760143f
Optimize help / usage output for the global options.
Franz Glasner <fzglas.hg@dom66.de>
parents:
147
diff
changeset
|
208 "-h", "--help", action="help", |
|
17d6e760143f
Optimize help / usage output for the global options.
Franz Glasner <fzglas.hg@dom66.de>
parents:
147
diff
changeset
|
209 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
|
210 |
|
148
17d6e760143f
Optimize help / usage output for the global options.
Franz Glasner <fzglas.hg@dom66.de>
parents:
147
diff
changeset
|
211 # |
|
17d6e760143f
Optimize help / usage output for the global options.
Franz Glasner <fzglas.hg@dom66.de>
parents:
147
diff
changeset
|
212 # Subcommands |
|
17d6e760143f
Optimize help / usage output for the global options.
Franz Glasner <fzglas.hg@dom66.de>
parents:
147
diff
changeset
|
213 # |
|
142
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
214 subparsers = parser.add_subparsers( |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
215 dest="subcommand", |
|
145
073e0faea599
Optimize help output for subcommands
Franz Glasner <fzglas.hg@dom66.de>
parents:
144
diff
changeset
|
216 title="Commands", |
|
142
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
217 description="This tool uses subcommands. " |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
218 "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
|
219 "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
|
220 "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
|
221 "is listed below:", |
|
145
073e0faea599
Optimize help output for subcommands
Franz Glasner <fzglas.hg@dom66.de>
parents:
144
diff
changeset
|
222 metavar="COMMAND") |
|
124
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
223 |
|
142
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
224 genparser = subparsers.add_parser( |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
225 "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
|
226 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
|
227 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
|
228 _populate_generate_arguments(genparser) |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
229 # And an alias for "generate" |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
230 genparser2 = subparsers.add_parser( |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
231 "gen", |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
232 help="Alias for \"generate\"", |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
233 description="Generate checksums for directory trees. " |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
234 "This is an alias to \"generate\".") |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
235 _populate_generate_arguments(genparser2) |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
236 |
|
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
|
237 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
|
238 "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
|
239 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
|
240 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
|
241 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
|
242 ) |
|
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
|
243 _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
|
244 |
|
147
ed35f3c9e2b5
Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents:
146
diff
changeset
|
245 hparser = subparsers.add_parser( |
|
ed35f3c9e2b5
Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents:
146
diff
changeset
|
246 "help", |
|
ed35f3c9e2b5
Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents:
146
diff
changeset
|
247 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
|
248 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
|
249 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
|
250 |
|
ed35f3c9e2b5
Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents:
146
diff
changeset
|
251 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
|
252 "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 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
|
254 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
|
255 |
|
147
ed35f3c9e2b5
Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents:
146
diff
changeset
|
256 # 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
|
257 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
|
258 |
|
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
|
259 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
|
260 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
|
261 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
|
262 return 0 |
|
147
ed35f3c9e2b5
Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents:
146
diff
changeset
|
263 if opts.subcommand == "help": |
|
ed35f3c9e2b5
Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents:
146
diff
changeset
|
264 if not opts.help_command: |
|
ed35f3c9e2b5
Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents:
146
diff
changeset
|
265 parser.print_help() |
|
ed35f3c9e2b5
Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents:
146
diff
changeset
|
266 else: |
|
ed35f3c9e2b5
Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents:
146
diff
changeset
|
267 if opts.help_command == "generate": |
|
ed35f3c9e2b5
Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents:
146
diff
changeset
|
268 genparser.print_help() |
|
ed35f3c9e2b5
Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents:
146
diff
changeset
|
269 elif opts.help_command == "gen": |
|
ed35f3c9e2b5
Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents:
146
diff
changeset
|
270 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
|
271 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
|
272 infoparser.print_help() |
|
147
ed35f3c9e2b5
Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents:
146
diff
changeset
|
273 elif opts.help_command == "version": |
|
ed35f3c9e2b5
Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents:
146
diff
changeset
|
274 vparser.print_help() |
|
ed35f3c9e2b5
Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents:
146
diff
changeset
|
275 elif opts.help_command == "help": |
|
ed35f3c9e2b5
Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents:
146
diff
changeset
|
276 hparser.print_help() |
|
ed35f3c9e2b5
Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents:
146
diff
changeset
|
277 else: |
|
ed35f3c9e2b5
Add also a "help" subcommand to "treesum".
Franz Glasner <fzglas.hg@dom66.de>
parents:
146
diff
changeset
|
278 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
|
279 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
|
280 |
|
146
7d8df8311e3b
Optimize argument parsing for the "version" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
145
diff
changeset
|
281 # Reparse strictly |
|
7d8df8311e3b
Optimize argument parsing for the "version" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
145
diff
changeset
|
282 opts = parser.parse_args(args=argv) |
|
7d8df8311e3b
Optimize argument parsing for the "version" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
145
diff
changeset
|
283 |
|
176
7f5d05a625fd
Implement preconditions for some debug logging
Franz Glasner <fzglas.hg@dom66.de>
parents:
174
diff
changeset
|
284 # 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
|
285 logging.basicConfig( |
|
7f5d05a625fd
Implement preconditions for some debug logging
Franz Glasner <fzglas.hg@dom66.de>
parents:
174
diff
changeset
|
286 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
|
287 stream=sys.stderr, |
|
7f5d05a625fd
Implement preconditions for some debug logging
Franz Glasner <fzglas.hg@dom66.de>
parents:
174
diff
changeset
|
288 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
|
289 ) |
|
7f5d05a625fd
Implement preconditions for some debug logging
Franz Glasner <fzglas.hg@dom66.de>
parents:
174
diff
changeset
|
290 logging.captureWarnings(True) |
|
7f5d05a625fd
Implement preconditions for some debug logging
Franz Glasner <fzglas.hg@dom66.de>
parents:
174
diff
changeset
|
291 |
|
124
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
292 return treesum(opts) |
|
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
293 |
|
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
294 |
|
210
1be3af138183
Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents:
208
diff
changeset
|
295 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
|
296 ["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
|
297 "directory", |
|
1be3af138183
Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents:
208
diff
changeset
|
298 "file"]) |
|
1be3af138183
Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents:
208
diff
changeset
|
299 |
|
1be3af138183
Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents:
208
diff
changeset
|
300 |
|
1be3af138183
Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents:
208
diff
changeset
|
301 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
|
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 """`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
|
304 `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
|
305 |
|
1be3af138183
Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents:
208
diff
changeset
|
306 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
|
307 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
|
308 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
|
309 |
|
1be3af138183
Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents:
208
diff
changeset
|
310 """ |
|
1be3af138183
Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents:
208
diff
changeset
|
311 |
|
1be3af138183
Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents:
208
diff
changeset
|
312 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
|
313 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
|
314 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
|
315 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
|
316 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
|
317 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
|
318 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
|
319 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
|
320 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
|
321 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
|
322 "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
|
323 "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
|
324 "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
|
325 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
|
326 "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
|
327 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
|
328 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
|
329 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
|
330 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
|
331 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
|
332 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
|
333 |
|
1be3af138183
Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents:
208
diff
changeset
|
334 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
|
335 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
|
336 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
|
337 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
|
338 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
|
339 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
|
340 else: |
|
1be3af138183
Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents:
208
diff
changeset
|
341 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
|
342 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
|
343 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
|
344 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
|
345 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
|
346 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
|
347 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
|
348 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
|
349 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
|
350 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
|
351 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
|
352 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
|
353 else: |
|
1be3af138183
Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents:
208
diff
changeset
|
354 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
|
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 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
|
357 |
|
1be3af138183
Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents:
208
diff
changeset
|
358 |
|
142
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
359 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
|
360 algorithm=util.default_algotag(), |
|
142
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
361 append_output=False, |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
362 base64=False, |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
363 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
|
364 follow_symlinks=FollowSymlinkConfig(False, False, False), |
|
158
d8cdd1985d43
Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
365 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
|
366 generator="normal", |
|
142
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
367 logical=None, |
|
150
f84cf853da22
Implement "--minimal [TAG]" for treesum.
Franz Glasner <fzglas.hg@dom66.de>
parents:
149
diff
changeset
|
368 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
|
369 mode=False, |
|
142
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
370 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
|
371 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
|
372 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
|
373 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
|
374 size_only=False, |
|
b9b38584919b
First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents:
200
diff
changeset
|
375 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
|
376 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
|
377 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
|
378 # 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
|
379 # 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
|
380 # 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
|
381 # 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
|
382 # True]) |
|
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
383 # 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
|
384 opts = argparse.Namespace( |
|
3a18d71d7c50
Implement --follow-directory-symlinks when walking a directory tree
Franz Glasner <fzglas.hg@dom66.de>
parents:
130
diff
changeset
|
385 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
|
386 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
|
387 append_output=append_output, |
|
3a18d71d7c50
Implement --follow-directory-symlinks when walking a directory tree
Franz Glasner <fzglas.hg@dom66.de>
parents:
130
diff
changeset
|
388 base64=base64, |
|
135
dbf27681a1f6
Allow to put comments into the output with "--comment"
Franz Glasner <fzglas.hg@dom66.de>
parents:
134
diff
changeset
|
389 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
|
390 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
|
391 generator=generator, |
|
131
3a18d71d7c50
Implement --follow-directory-symlinks when walking a directory tree
Franz Glasner <fzglas.hg@dom66.de>
parents:
130
diff
changeset
|
392 logical=logical, |
|
150
f84cf853da22
Implement "--minimal [TAG]" for treesum.
Franz Glasner <fzglas.hg@dom66.de>
parents:
149
diff
changeset
|
393 minimal=minimal, |
|
131
3a18d71d7c50
Implement --follow-directory-symlinks when walking a directory tree
Franz Glasner <fzglas.hg@dom66.de>
parents:
130
diff
changeset
|
394 mmap=mmap, |
|
158
d8cdd1985d43
Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
395 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
|
396 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
|
397 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
|
398 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
|
399 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
|
400 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
|
401 utf8=utf8) |
|
124
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
402 return opts |
|
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
403 |
|
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
404 |
|
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
|
405 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
|
406 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
|
407 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
|
408 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
|
409 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
|
410 |
|
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
|
411 |
|
124
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
412 def treesum(opts): |
|
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
413 # 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
|
414 if opts.subcommand in ("generate", "gen"): |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
415 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
|
416 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
|
417 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
|
418 else: |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
419 raise RuntimeError( |
|
71747e45b52c
Prepare for using subcommands in "treesum.py".
Franz Glasner <fzglas.hg@dom66.de>
parents:
137
diff
changeset
|
420 "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
|
421 |
|
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
422 |
|
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
423 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
|
424 # 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
|
425 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
|
426 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
|
427 if not opts.directories: |
|
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
428 opts.directories.append(".") |
|
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
429 |
|
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
430 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
|
431 if hasattr(sys.stdout, "buffer"): |
|
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
432 out_cm = cm.nullcontext(sys.stdout.buffer) |
|
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 out_cm = cm.nullcontext(sys.stdout) |
|
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
435 else: |
|
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
436 if opts.append_output: |
|
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
437 out_cm = open(opts.output, "ab") |
|
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
438 else: |
|
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
439 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
|
440 out_cm = CRC32Output(out_cm) |
|
124
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
441 |
|
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
442 with out_cm as outfp: |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
443 writer = TreesumWriter(outfp) |
|
124
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
444 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
|
445 V1DirectoryTreesumGenerator( |
|
202
b9b38584919b
First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents:
200
diff
changeset
|
446 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
|
447 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
|
448 opts.generator, |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
449 opts.metadata_mode, |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
450 opts.metadata_full_mode, |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
451 opts.metadata_mtime, |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
452 opts.size_only, |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
453 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
|
454 opts.utf8, |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
455 minimal=opts.minimal).generate( |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
456 writer, d, comment=opts.comment) |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
457 |
|
124
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
458 |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
459 class V1DirectoryTreesumGenerator(object): |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
460 |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
461 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
|
462 follow_symlinks, |
|
205
63088d3675bb
Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents:
204
diff
changeset
|
463 with_generator, |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
464 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
|
465 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
|
466 minimal=None,): |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
467 super(V1DirectoryTreesumGenerator, self).__init__() |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
468 self._algorithm = algorithm |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
469 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
|
470 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
|
471 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
|
472 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
|
473 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
|
474 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
|
475 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
|
476 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
|
477 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
|
478 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
|
479 self._minimal = minimal |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
480 |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
481 def generate(self, writer, root, comment=None): |
|
177
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 :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
|
485 |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
486 """ |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
487 self._writer = writer |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
488 self._writer.start("1") |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
489 self._writer.write_fsencoding(util.n(walk.getfsencoding().upper())) |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
490 self._writer.flush() |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
491 |
|
205
63088d3675bb
Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents:
204
diff
changeset
|
492 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
|
493 pass # do nothing |
|
63088d3675bb
Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents:
204
diff
changeset
|
494 elif self._with_generator == "normal": |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
495 self._writer.write_generator("PY2" if util.PY2 else "PY3") |
|
205
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 |
|
295
4a259fb9968e
treesum: Add the treesum version and revision to the full generator output
Franz Glasner <fzglas.hg@dom66.de>
parents:
291
diff
changeset
|
498 info = ("treesum %s (rv:%s), %s %s, %s" |
|
4a259fb9968e
treesum: Add the treesum version and revision to the full generator output
Franz Glasner <fzglas.hg@dom66.de>
parents:
291
diff
changeset
|
499 % (__version__, |
|
4a259fb9968e
treesum: Add the treesum version and revision to the full generator output
Franz Glasner <fzglas.hg@dom66.de>
parents:
291
diff
changeset
|
500 __revision__, |
|
4a259fb9968e
treesum: Add the treesum version and revision to the full generator output
Franz Glasner <fzglas.hg@dom66.de>
parents:
291
diff
changeset
|
501 platform.python_implementation(), |
|
4a259fb9968e
treesum: Add the treesum version and revision to the full generator output
Franz Glasner <fzglas.hg@dom66.de>
parents:
291
diff
changeset
|
502 platform.python_version(), |
|
4a259fb9968e
treesum: Add the treesum version and revision to the full generator output
Franz Glasner <fzglas.hg@dom66.de>
parents:
291
diff
changeset
|
503 platform.platform())) |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
504 self._writer.write_generator(info) |
|
205
63088d3675bb
Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents:
204
diff
changeset
|
505 else: |
|
63088d3675bb
Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents:
204
diff
changeset
|
506 raise NotImplementedError( |
|
63088d3675bb
Add a "GENERATOR" line with control flats to treesum.py
Franz Glasner <fzglas.hg@dom66.de>
parents:
204
diff
changeset
|
507 "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
|
508 |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
509 # |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
510 # 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
|
511 # directory traversal. |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
512 # |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
513 flags = [] |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
514 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
|
515 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
|
516 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
|
517 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
|
518 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
|
519 flags.append("with-metadata-mtime") |
|
219
19eaba51c632
Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents:
218
diff
changeset
|
520 flags.append("follow-symlinks-commandline" |
|
19eaba51c632
Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents:
218
diff
changeset
|
521 if self._follow_symlinks.command_line |
|
19eaba51c632
Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents:
218
diff
changeset
|
522 else "no-follow-symlinks-commandline") |
|
19eaba51c632
Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents:
218
diff
changeset
|
523 flags.append("follow-symlinks-directory" |
|
19eaba51c632
Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents:
218
diff
changeset
|
524 if self._follow_symlinks.directory |
|
19eaba51c632
Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents:
218
diff
changeset
|
525 else "no-follow-symlinks-directory") |
|
19eaba51c632
Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents:
218
diff
changeset
|
526 flags.append("follow-symlinks-file" |
|
19eaba51c632
Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents:
218
diff
changeset
|
527 if self._follow_symlinks.file |
|
19eaba51c632
Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents:
218
diff
changeset
|
528 else "no-follow-symlinks-file") |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
529 if self._size_only: |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
530 flags.append("size-only") |
|
219
19eaba51c632
Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents:
218
diff
changeset
|
531 flags.append("utf8-encoding" if self._utf8_mode else "fs-encoding") |
|
211
5bb0b25f8e99
FIX: FLAGS output: wrong "else" for "utf-8-mode" and "print-size"
Franz Glasner <fzglas.hg@dom66.de>
parents:
210
diff
changeset
|
532 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
|
533 flags.append("print-size") |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
534 self._writer.write_flags(flags) |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
535 |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
536 if self._minimal is None: |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
537 # Write execution timestamps in POSIX epoch and ISO format |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
538 ts = int(time.time()) |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
539 self._writer.write_timestamp(ts) |
|
291
cc2deeb5f2e6
treesum: Indicate that the ISO timestamp is UTC
Franz Glasner <fzglas.hg@dom66.de>
parents:
290
diff
changeset
|
540 ts = (datetime.datetime.utcfromtimestamp(ts)).isoformat("T") + "Z" |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
541 self._writer.write_isotimestamp(ts) |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
542 |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
543 if comment: |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
544 for line in comment: |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
545 self._writer.write_comment(line) |
|
177
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: |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
548 self._writer.write_root( |
|
204
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
549 (walk.WalkDirEntry.alt_u8(self._minimal) |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
550 if self._minimal else b"")) |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
551 else: |
|
278
822cf3a1da22
treesum: FIX: Removal of backslashes in output: do this only where really needed.
Franz Glasner <fzglas.hg@dom66.de>
parents:
277
diff
changeset
|
552 self._writer.write_root(walk.WalkDirEntry.alt_u8( |
|
822cf3a1da22
treesum: FIX: Removal of backslashes in output: do this only where really needed.
Franz Glasner <fzglas.hg@dom66.de>
parents:
277
diff
changeset
|
553 util.normalize_filename(root, True))) |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
554 self._writer.flush() |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
555 |
|
210
1be3af138183
Refactor option handling for configuring symlink handling: now all variations are supported
Franz Glasner <fzglas.hg@dom66.de>
parents:
208
diff
changeset
|
556 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
|
557 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
|
558 linkdgst = self._algorithm[0]() |
|
270
42f4ca423ab3
treesum: REFACTOR: Major refactoring of computing digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
269
diff
changeset
|
559 linkdgst.update(linktgt.fspath) |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
560 dir_dgst = self._algorithm[0]() |
|
270
42f4ca423ab3
treesum: REFACTOR: Major refactoring of computing digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
269
diff
changeset
|
561 dir_dgst.update(b"2:L@,") |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
562 dir_dgst.update( |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
563 util.interpolate_bytes( |
|
270
42f4ca423ab3
treesum: REFACTOR: Major refactoring of computing digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
269
diff
changeset
|
564 b"%d:%s,%d:%s,", |
|
42f4ca423ab3
treesum: REFACTOR: Major refactoring of computing digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
269
diff
changeset
|
565 len(self._algorithm[1]), util.b(self._algorithm[1]), |
|
42f4ca423ab3
treesum: REFACTOR: Major refactoring of computing digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
269
diff
changeset
|
566 len(linkdgst.digest()), linkdgst.digest())) |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
567 if self._size_only: |
|
290
3c3f8151f36a
treesum: FIX: Output of empty sizes in Python 3: print a realy empty string instead of "b''"
Franz Glasner <fzglas.hg@dom66.de>
parents:
278
diff
changeset
|
568 self._writer.write_size(b"./@/", "") |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
569 else: |
|
290
3c3f8151f36a
treesum: FIX: Output of empty sizes in Python 3: print a realy empty string instead of "b''"
Franz Glasner <fzglas.hg@dom66.de>
parents:
278
diff
changeset
|
570 sz = "" if self._print_size else None |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
571 self._writer.write_file_digest( |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
572 self._algorithm[1], |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
573 b"./@/", |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
574 dir_dgst.digest(), |
|
275
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
575 self._use_base64, |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
576 size=sz) |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
577 self._writer.flush() |
|
268
8aadffaaad5f
treesum: refactor: remove early return and use an "else" branch instead
Franz Glasner <fzglas.hg@dom66.de>
parents:
267
diff
changeset
|
578 else: |
|
8aadffaaad5f
treesum: refactor: remove early return and use an "else" branch instead
Franz Glasner <fzglas.hg@dom66.de>
parents:
267
diff
changeset
|
579 self._generate(os.path.normpath(root), tuple()) |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
580 self._writer.finish() |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
581 |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
582 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
|
583 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
|
584 path = os.path.join(root, *top) if top else root |
|
266
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
585 try: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
586 with walk.ScanDir(path) as dirscan: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
587 fsobjects = list(dirscan) |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
588 except OSError as e: |
|
275
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
589 # |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
590 # NOTE: Sync the error handler code with this method's |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
591 # code below before returning! |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
592 # |
|
266
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
593 if e.errno == errno.ENOTDIR: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
594 # object exists but is not a directory |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
595 errmsg = b"not a directory" |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
596 elif e.errno in (errno.EACCES, errno.EPERM, |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
597 getattr(errno, "ENOTCAPABLE", errno.EACCES)): |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
598 # no permissions |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
599 errmsg = ( |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
600 b"access denied / no permissions / missing capabilities") |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
601 elif e.errno == errno.ENOENT: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
602 # given object does not exist |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
603 errmsg = b"no such file or directory" |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
604 else: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
605 raise |
|
275
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
606 if self._utf8_mode: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
607 opath = walk.WalkDirEntry.alt_u8(path) |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
608 else: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
609 opath = walk.WalkDirEntry.alt_fs(path) |
|
266
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
610 self._writer.write_error(util.interpolate_bytes( |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
611 b"`%s': %s", opath, errmsg)) |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
612 opath = join_output_path(top, None) |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
613 if opath: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
614 if self._utf8_mode: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
615 opath = walk.WalkDirEntry.alt_u8(opath) |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
616 else: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
617 opath = walk.WalkDirEntry.alt_fs(opath) |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
618 if self._size_only: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
619 self._writer.write_size(opath, None) |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
620 else: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
621 self._writer.write_file_digest(self._algorithm[1], opath, None) |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
622 self._writer.flush() |
|
277
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
623 return (e.errno, None, None, None) |
|
202
b9b38584919b
First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents:
200
diff
changeset
|
624 if self._utf8_mode: |
|
221
ca9d5a0dc9bb
Rename WalkDirEntry.sort_key and WalkDirEntry.alt_sort_key
Franz Glasner <fzglas.hg@dom66.de>
parents:
220
diff
changeset
|
625 fsobjects.sort(key=walk.WalkDirEntry.sort_key_u8) |
|
202
b9b38584919b
First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents:
200
diff
changeset
|
626 else: |
|
221
ca9d5a0dc9bb
Rename WalkDirEntry.sort_key and WalkDirEntry.alt_sort_key
Franz Glasner <fzglas.hg@dom66.de>
parents:
220
diff
changeset
|
627 fsobjects.sort(key=walk.WalkDirEntry.sort_key_fs) |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
628 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
|
629 dir_size = 0 |
|
204
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
630 dir_tainted = False |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
631 for fso in fsobjects: |
|
275
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
632 # Determine the effective name to be used for digesting |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
633 if self._utf8_mode: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
634 if fso.u8name is None: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
635 dir_tainted = True |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
636 effective_fso_name = fso.alt_u8name |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
637 else: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
638 effective_fso_name = fso.u8name |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
639 else: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
640 if fso.fsname is None: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
641 dir_tainted = True |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
642 effective_fso_name = fso.alt_fsname |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
643 else: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
644 effective_fso_name = fso.fsname |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
645 # Determine the path (mostly its prefix) that is to be printed |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
646 opath = join_output_path(top, fso.name) |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
647 if self._utf8_mode: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
648 opath = walk.WalkDirEntry.alt_u8(opath) |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
649 else: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
650 opath = walk.WalkDirEntry.alt_fs(opath) |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
651 if fso.is_special: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
652 # Determine the tag character |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
653 if fso.is_chr: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
654 special_tag = b':' |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
655 elif fso.is_blk: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
656 special_tag = b';' |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
657 elif fso.is_fifo: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
658 special_tag = b'|' |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
659 elif fso.is_socket: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
660 special_tag = b'=' |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
661 elif fso.is_door: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
662 special_tag = b'>' |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
663 elif fso.is_whiteout: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
664 special_tag = b'%' |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
665 elif fso.is_eventport: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
666 special_tag = b'+' |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
667 else: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
668 assert False, "unknown special filesystem object" |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
669 assert fso.stat is not None # because .is_special is True |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
670 if fso.is_symlink and not self._follow_symlinks.file: |
|
202
b9b38584919b
First preparations to implement an UTF-8-mode for treeview
Franz Glasner <fzglas.hg@dom66.de>
parents:
200
diff
changeset
|
671 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
|
672 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
|
673 linkdgst = self._algorithm[0]() |
|
204
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
674 if self._utf8_mode: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
675 if linktgt.u8path is None: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
676 dir_tainted = True |
|
270
42f4ca423ab3
treesum: REFACTOR: Major refactoring of computing digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
269
diff
changeset
|
677 linkdgst.update(linktgt.alt_u8path) |
|
204
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
678 else: |
|
270
42f4ca423ab3
treesum: REFACTOR: Major refactoring of computing digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
269
diff
changeset
|
679 linkdgst.update(linktgt.u8path) |
|
204
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
680 else: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
681 if linktgt.fspath is None: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
682 dir_tainted = True |
|
270
42f4ca423ab3
treesum: REFACTOR: Major refactoring of computing digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
269
diff
changeset
|
683 linkdgst.update(linktgt.alt_fspath) |
|
204
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
684 else: |
|
270
42f4ca423ab3
treesum: REFACTOR: Major refactoring of computing digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
269
diff
changeset
|
685 linkdgst.update(linktgt.fspath) |
|
275
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
686 dir_dgst.update(util.interpolate_bytes( |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
687 b"2:@%s,%d:%s,", |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
688 special_tag, |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
689 len(effective_fso_name), |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
690 effective_fso_name)) |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
691 dir_dgst.update(util.interpolate_bytes( |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
692 b"%d:%s,%d:%s,", |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
693 len(self._algorithm[1]), util.b(self._algorithm[1]), |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
694 len(linkdgst.digest()), linkdgst.digest())) |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
695 # |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
696 # - no mtime and no mode for symlinks |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
697 # - also does not count for dir_size |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
698 # |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
699 if self._size_only: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
700 self._writer.write_size( |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
701 util.interpolate_bytes( |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
702 b"%s/./@%s", opath, special_tag), |
|
290
3c3f8151f36a
treesum: FIX: Output of empty sizes in Python 3: print a realy empty string instead of "b''"
Franz Glasner <fzglas.hg@dom66.de>
parents:
278
diff
changeset
|
703 "") |
|
275
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
704 else: |
|
290
3c3f8151f36a
treesum: FIX: Output of empty sizes in Python 3: print a realy empty string instead of "b''"
Franz Glasner <fzglas.hg@dom66.de>
parents:
278
diff
changeset
|
705 sz = "" if self._print_size else None |
|
275
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
706 self._writer.write_file_digest( |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
707 self._algorithm[1], |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
708 util.interpolate_bytes( |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
709 b"%s/./@%s", opath, special_tag), |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
710 linkdgst.digest(), |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
711 self._use_base64, |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
712 size=sz) |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
713 else: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
714 # |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
715 # Follow the symlink to special file and/or handle a |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
716 # special file |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
717 # |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
718 dir_dgst.update(util.interpolate_bytes( |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
719 b"1:%s,%d:%s,", |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
720 special_tag, |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
721 len(effective_fso_name), |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
722 effective_fso_name)) |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
723 # no important size here but a mode |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
724 if self._with_metadata_mtime: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
725 mtime = datetime.datetime.utcfromtimestamp( |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
726 int(fso.stat.st_mtime)) |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
727 mtime = util.b(mtime.isoformat("T") + "Z") |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
728 dir_dgst.update(util.interpolate_bytes( |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
729 b"5:mtime,%d:%s,", len(mtime), mtime)) |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
730 if self._with_metadata_full_mode: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
731 modestr = util.b( |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
732 normalized_mode_str(fso.stat.st_mode)) |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
733 dir_dgst.update(util.interpolate_bytes( |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
734 b"8:fullmode,%d:%s,", len(modestr), modestr)) |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
735 elif self._with_metadata_mode: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
736 modestr = util.b(normalized_compatible_mode_str( |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
737 fso.stat.st_mode)) |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
738 dir_dgst.update(util.interpolate_bytes( |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
739 b"4:mode,%d:%s,", len(modestr), modestr)) |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
740 if self._size_only: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
741 self._writer.write_size( |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
742 util.interpolate_bytes( |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
743 b"%s/./%s", opath, special_tag), |
|
290
3c3f8151f36a
treesum: FIX: Output of empty sizes in Python 3: print a realy empty string instead of "b''"
Franz Glasner <fzglas.hg@dom66.de>
parents:
278
diff
changeset
|
744 "") |
|
275
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
745 else: |
|
290
3c3f8151f36a
treesum: FIX: Output of empty sizes in Python 3: print a realy empty string instead of "b''"
Franz Glasner <fzglas.hg@dom66.de>
parents:
278
diff
changeset
|
746 sz = "" if self._print_size else None |
|
275
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
747 self._writer.write_file_digest( |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
748 self._algorithm[1], |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
749 util.interpolate_bytes( |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
750 b"%s/./%s", opath, special_tag), |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
751 b"", |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
752 self._use_base64, |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
753 size=sz) |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
754 elif fso.is_dir: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
755 assert fso.stat is not None # because .is_dir is True |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
756 if fso.is_symlink and not self._follow_symlinks.directory: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
757 linktgt = walk.WalkDirEntry.from_readlink( |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
758 os.readlink(fso.path)) |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
759 linkdgst = self._algorithm[0]() |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
760 if self._utf8_mode: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
761 if linktgt.u8path is None: |
|
204
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
762 dir_tainted = True |
|
275
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
763 linkdgst.update(linktgt.alt_u8path) |
|
204
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
764 else: |
|
275
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
765 linkdgst.update(linktgt.u8path) |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
766 else: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
767 if linktgt.fspath is None: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
768 dir_tainted = True |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
769 linkdgst.update(linktgt.alt_fspath) |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
770 else: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
771 linkdgst.update(linktgt.fspath) |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
772 dir_dgst.update(util.interpolate_bytes( |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
773 b"2:@/,%d:%s,", |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
774 len(effective_fso_name), |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
775 effective_fso_name)) |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
776 # |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
777 # - 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
|
778 # - 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
|
779 # |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
780 dir_dgst.update(util.interpolate_bytes( |
|
270
42f4ca423ab3
treesum: REFACTOR: Major refactoring of computing digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
269
diff
changeset
|
781 b"%d:%s,%d:%s,", |
|
42f4ca423ab3
treesum: REFACTOR: Major refactoring of computing digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
269
diff
changeset
|
782 len(self._algorithm[1]), util.b(self._algorithm[1]), |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
783 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
|
784 if self._size_only: |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
785 self._writer.write_size( |
|
218
dee891ed2307
FIX: Output of symlinks was not converted property but was written in bytes repr
Franz Glasner <fzglas.hg@dom66.de>
parents:
217
diff
changeset
|
786 util.interpolate_bytes(b"%s/./@/", opath), |
|
290
3c3f8151f36a
treesum: FIX: Output of empty sizes in Python 3: print a realy empty string instead of "b''"
Franz Glasner <fzglas.hg@dom66.de>
parents:
278
diff
changeset
|
787 "") |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
788 else: |
|
290
3c3f8151f36a
treesum: FIX: Output of empty sizes in Python 3: print a realy empty string instead of "b''"
Franz Glasner <fzglas.hg@dom66.de>
parents:
278
diff
changeset
|
789 sz = "" if self._print_size else None |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
790 self._writer.write_file_digest( |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
791 self._algorithm[1], |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
792 util.interpolate_bytes(b"%s/./@/", opath), |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
793 linkdgst.digest(), |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
794 self._use_base64) |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
795 else: |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
796 # |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
797 # 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
|
798 # |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
799 |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
800 # Get subdir data from recursing into it |
|
277
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
801 sub_dir_errno, sub_dir_algo, sub_dir_dgst, sub_dir_size = \ |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
802 self._generate(root, top + (fso.name, )) |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
803 |
|
277
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
804 if sub_dir_errno == 0: |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
805 dir_size += sub_dir_size |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
806 else: |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
807 dir_tainted = True |
|
275
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
808 dir_dgst.update(util.interpolate_bytes( |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
809 b"1:/,%d:%s,", |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
810 len(effective_fso_name), |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
811 effective_fso_name)) |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
812 if self._with_metadata_full_mode: |
|
188
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
813 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
|
814 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
|
815 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
|
816 elif self._with_metadata_mode: |
|
188
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
817 modestr = util.b(normalized_compatible_mode_str( |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
818 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
|
819 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
|
820 b"4:mode,%d:%s,", len(modestr), modestr)) |
|
277
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
821 if sub_dir_errno == 0: |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
822 dir_dgst.update(util.interpolate_bytes( |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
823 b"%d:%s,%d:%s,", |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
824 len(sub_dir_algo), util.b(sub_dir_algo), |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
825 len(sub_dir_dgst), sub_dir_dgst)) |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
826 else: |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
827 # NOTE: error message is already printed here |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
828 dir_dgst.update(util.interpolate_bytes( |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
829 b"5:errno,%d:%s", |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
830 len(str(sub_dir_errno)), |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
831 util.b(str(sub_dir_errno)))) |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
832 else: |
|
217
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
833 if fso.is_symlink and not self._follow_symlinks.file: |
|
270
42f4ca423ab3
treesum: REFACTOR: Major refactoring of computing digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
269
diff
changeset
|
834 # |
|
42f4ca423ab3
treesum: REFACTOR: Major refactoring of computing digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
269
diff
changeset
|
835 # Symbolic link to some filesystem object which is not |
|
275
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
836 # determined to be a link to a directory or some other |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
837 # special file (socket, FIFO, et al.). |
|
270
42f4ca423ab3
treesum: REFACTOR: Major refactoring of computing digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
269
diff
changeset
|
838 # |
|
217
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
839 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
|
840 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
|
841 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
|
842 if self._utf8_mode: |
|
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
843 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
|
844 dir_tainted = True |
|
270
42f4ca423ab3
treesum: REFACTOR: Major refactoring of computing digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
269
diff
changeset
|
845 linkdgst.update(linktgt.alt_u8path) |
|
217
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
846 else: |
|
270
42f4ca423ab3
treesum: REFACTOR: Major refactoring of computing digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
269
diff
changeset
|
847 linkdgst.update(linktgt.u8path) |
|
204
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
848 else: |
|
217
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
849 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
|
850 dir_tainted = True |
|
270
42f4ca423ab3
treesum: REFACTOR: Major refactoring of computing digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
269
diff
changeset
|
851 linkdgst.update(linktgt.alt_fspath) |
|
217
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
852 else: |
|
270
42f4ca423ab3
treesum: REFACTOR: Major refactoring of computing digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
269
diff
changeset
|
853 linkdgst.update(linktgt.fspath) |
|
275
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
854 dir_dgst.update(util.interpolate_bytes( |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
855 b"1:@,%d:%s,", |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
856 len(effective_fso_name), |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
857 effective_fso_name)) |
|
217
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
858 # |
|
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
859 # - 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
|
860 # - 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
|
861 # |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
862 dir_dgst.update(util.interpolate_bytes( |
|
270
42f4ca423ab3
treesum: REFACTOR: Major refactoring of computing digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
269
diff
changeset
|
863 b"%d:%s,%d:%s,", |
|
42f4ca423ab3
treesum: REFACTOR: Major refactoring of computing digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
269
diff
changeset
|
864 len(self._algorithm[1]), util.b(self._algorithm[1]), |
|
217
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
865 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
|
866 if self._size_only: |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
867 self._writer.write_size( |
|
218
dee891ed2307
FIX: Output of symlinks was not converted property but was written in bytes repr
Franz Glasner <fzglas.hg@dom66.de>
parents:
217
diff
changeset
|
868 util.interpolate_bytes(b"%s/./@", opath), |
|
290
3c3f8151f36a
treesum: FIX: Output of empty sizes in Python 3: print a realy empty string instead of "b''"
Franz Glasner <fzglas.hg@dom66.de>
parents:
278
diff
changeset
|
869 "") |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
870 else: |
|
290
3c3f8151f36a
treesum: FIX: Output of empty sizes in Python 3: print a realy empty string instead of "b''"
Franz Glasner <fzglas.hg@dom66.de>
parents:
278
diff
changeset
|
871 sz = "" if self._print_size else None |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
872 self._writer.write_file_digest( |
|
217
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
873 self._algorithm[1], |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
874 util.interpolate_bytes(b"%s/./@", opath), |
|
217
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
875 linkdgst.digest(), |
|
275
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
876 self._use_base64, |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
877 size=sz) |
|
217
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
878 else: |
| 223 | 879 # |
| 880 # Follow the symlink to file or handle a "real" file | |
| 881 # | |
| 882 | |
|
275
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
883 dir_dgst.update(util.interpolate_bytes( |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
884 b"0:,%d:%s,", |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
885 len(effective_fso_name), |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
886 effective_fso_name)) |
|
266
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
887 if fso.stat is None: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
888 # |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
889 # Error: most likely a broken symlink here |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
890 # |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
891 dir_tainted = True |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
892 dir_dgst.update(util.interpolate_bytes( |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
893 b"5:errno,%d:%s,", |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
894 len(str(fso.stat_errno)), |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
895 util.b(str(fso.stat_errno)))) |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
896 self._writer.write_error(util.interpolate_bytes( |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
897 b"errno %d: %s", |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
898 fso.stat_errno, |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
899 util.b(fso.stat_errstr, "utf-8"))) |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
900 logging.error( |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
901 "Directory entry has symlink problems: %r", |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
902 opath) |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
903 if self._size_only: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
904 self._writer.write_size(opath, None) |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
905 else: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
906 self._writer.write_file_digest( |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
907 self._algorithm[1], opath, None) |
|
217
8e38c07c4b85
Handle symlinks to files fully and Implement no-follow-file-symlinks
Franz Glasner <fzglas.hg@dom66.de>
parents:
213
diff
changeset
|
908 else: |
|
266
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
909 # |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
910 # Ok: File has normal stat info |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
911 # |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
912 # XXX FIXME: Handle special files (fifo, socket, |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
913 # block or char devices, ...). |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
914 # |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
915 dir_size += fso.stat.st_size |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
916 if self._with_metadata_mtime: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
917 mtime = datetime.datetime.utcfromtimestamp( |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
918 int(fso.stat.st_mtime)) |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
919 mtime = util.b(mtime.isoformat("T") + "Z") |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
920 dir_dgst.update(util.interpolate_bytes( |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
921 b"5:mtime,%d:%s,", len(mtime), mtime)) |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
922 if self._with_metadata_full_mode: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
923 modestr = util.b( |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
924 normalized_mode_str(fso.stat.st_mode)) |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
925 dir_dgst.update(util.interpolate_bytes( |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
926 b"8:fullmode,%d:%s,", len(modestr), modestr)) |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
927 elif self._with_metadata_mode: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
928 modestr = util.b(normalized_compatible_mode_str( |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
929 fso.stat.st_mode)) |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
930 dir_dgst.update(util.interpolate_bytes( |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
931 b"4:mode,%d:%s,", len(modestr), modestr)) |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
932 if self._size_only: |
|
277
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
933 # |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
934 # size can be printed here because .stat is |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
935 # available |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
936 # |
|
266
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
937 self._writer.write_size(opath, fso.stat.st_size) |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
938 else: |
|
277
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
939 try: |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
940 dgst = digest.compute_digest_file( |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
941 self._algorithm[0], |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
942 fso.path, |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
943 use_mmap=self._use_mmap) |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
944 except OSError as e: |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
945 dir_tainted = True |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
946 self._writer.write_error( |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
947 util.interpolate_bytes( |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
948 b"`%s': errno %d: %s", |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
949 opath, |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
950 e.errno, |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
951 util.b(e.strerror, "utf-8"))) |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
952 sz = (fso.stat.st_size if self._print_size |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
953 else None) |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
954 self._writer.write_file_digest( |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
955 self._algorithm[1], opath, None, |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
956 size=sz) |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
957 else: |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
958 dir_dgst.update(util.interpolate_bytes( |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
959 b"%d:%s,%d:%s,", |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
960 len(self._algorithm[1]), |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
961 util.b(self._algorithm[1]), |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
962 len(dgst), |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
963 dgst)) |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
964 sz = (fso.stat.st_size if self._print_size |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
965 else None) |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
966 self._writer.write_file_digest( |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
967 self._algorithm[1], opath, dgst, |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
968 use_base64=self._use_base64, |
|
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
969 size=sz) |
|
267
b9aa65a30b4c
treesum: optimize the use of flush() somewhat
Franz Glasner <fzglas.hg@dom66.de>
parents:
266
diff
changeset
|
970 self._writer.flush() |
|
204
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
971 opath = join_output_path(top, None) |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
972 if opath: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
973 if self._utf8_mode: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
974 opath = walk.WalkDirEntry.alt_u8(opath) |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
975 else: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
976 opath = walk.WalkDirEntry.alt_fs(opath) |
|
266
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
977 if dir_tainted: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
978 # |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
979 # IMPORTANT: Print errors BEFORE the associated digest or size |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
980 # line. Otherwise the "info" command has a problem. |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
981 # |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
982 self._writer.write_error(b"directory is tainted") |
|
277
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
983 logging.error("Directory has problems: %r", opath) |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
984 if self._size_only: |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
985 self._writer.write_size(opath, dir_size) |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
986 else: |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
987 sz = dir_size if self._print_size else None |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
988 self._writer.write_file_digest( |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
989 self._algorithm[1], opath, dir_dgst.digest(), |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
990 use_base64=self._use_base64, size=sz) |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
991 self._writer.flush() |
|
277
9676ecd32a07
treesum: FIX: Proper error handling.
Franz Glasner <fzglas.hg@dom66.de>
parents:
275
diff
changeset
|
992 return (0, self._algorithm[1], dir_dgst.digest(), dir_size) |
|
177
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
993 |
|
089c40240061
Add an alternate implementation for generating directory tree digests:
Franz Glasner <fzglas.hg@dom66.de>
parents:
176
diff
changeset
|
994 |
|
204
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
995 def join_output_path(top, name): |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
996 if name is None: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
997 # 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
|
998 if top: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
999 if isinstance(top[0], bytes): |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
1000 return b"/".join(top) + b"/" |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
1001 else: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
1002 return u"/".join(top) + u"/" |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
1003 else: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
1004 return b"" |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
1005 else: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
1006 # 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
|
1007 if top: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
1008 if isinstance(name, bytes): |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
1009 return b"/".join(top) + b"/" + name |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
1010 else: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
1011 return u"/".join(top) + u"/" + name |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
1012 else: |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
1013 return name |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
1014 |
|
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
1015 |
|
179
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
1016 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
|
1017 |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
1018 """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
|
1019 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
|
1020 |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
1021 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
|
1022 |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
1023 """ |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
1024 |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
1025 __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
|
1026 |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
1027 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
|
1028 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
|
1029 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
|
1030 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
|
1031 |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
1032 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
|
1033 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
|
1034 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
|
1035 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
|
1036 |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
1037 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
|
1038 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
|
1039 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
|
1040 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
|
1041 |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
1042 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
|
1043 self._fp.write(what) |
|
260
07a0bc723139
treesum: Implement the CRC-32 using the new util.crc32 module
Franz Glasner <fzglas.hg@dom66.de>
parents:
223
diff
changeset
|
1044 self._crc32.update(what) |
|
179
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
1045 |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
1046 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
|
1047 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
|
1048 |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
1049 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
|
1050 """Reset the current CRC digest""" |
|
260
07a0bc723139
treesum: Implement the CRC-32 using the new util.crc32 module
Franz Glasner <fzglas.hg@dom66.de>
parents:
223
diff
changeset
|
1051 self._crc32 = 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
|
1052 |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
1053 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
|
1054 """ |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
1055 |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
1056 :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
|
1057 |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
1058 """ |
|
260
07a0bc723139
treesum: Implement the CRC-32 using the new util.crc32 module
Franz Glasner <fzglas.hg@dom66.de>
parents:
223
diff
changeset
|
1059 return self._crc32.hexdigest() |
|
179
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
1060 |
|
53614a724bf0
Also write a (standard) CRC-32 checksum for each block of output
Franz Glasner <fzglas.hg@dom66.de>
parents:
178
diff
changeset
|
1061 |
|
158
d8cdd1985d43
Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
1062 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
|
1063 # 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
|
1064 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
|
1065 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
|
1066 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
|
1067 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
|
1068 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
|
1069 |
|
27d1aaf5fe39
Implement "--mode" flag for "treesum.py" to consider file portable mode bits
Franz Glasner <fzglas.hg@dom66.de>
parents:
156
diff
changeset
|
1070 |
|
158
d8cdd1985d43
Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
1071 def normalized_mode_str(mode): |
|
d8cdd1985d43
Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
1072 modestr = "%o" % (mode,) |
|
d8cdd1985d43
Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
1073 if not modestr.startswith("0"): |
|
d8cdd1985d43
Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
1074 modestr = "0" + modestr |
|
d8cdd1985d43
Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
1075 return modestr |
|
d8cdd1985d43
Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
1076 |
|
d8cdd1985d43
Implement "--full-mode" for "treesum.py"
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
1077 |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1078 class TreesumWriter(object): |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1079 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1080 """Writer to write treesum digest files in a format similar to BSD |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1081 digest files. |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1082 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1083 Wraps an output file pointer for a binary file. |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1084 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1085 Provides high-level methods to write data lines. |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1086 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1087 Also holds the current CRC for a block. |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1088 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1089 """ |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1090 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1091 LS = util.b(os.linesep) |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1092 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1093 def __init__(self, outfp): |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1094 self._outfp = outfp |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1095 self._reset_crc() |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1096 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1097 def _reset_crc(self): |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1098 self._crc = crc32() |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1099 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1100 def start(self, version): |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1101 """Begin a new block, reset the current CRC and write the VERSION |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1102 tag. |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1103 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1104 """ |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1105 self._reset_crc() |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1106 self.write(b"VERSION = ") |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1107 self.writeln(util.b(version)) |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1108 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1109 def write_comment(self, comment): |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1110 self.write(b"COMMENT (") |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1111 self.write(util.b(comment, "utf-8")) |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1112 self.writeln(b")") |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1113 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1114 def write_generator(self, generator): |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1115 self.write(b"GENERATOR (") |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1116 self.write(util.b(generator, "utf-8")) |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1117 self.writeln(b")") |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1118 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1119 def write_error(self, error): |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1120 self.write(b"ERROR (") |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1121 self.write(util.b(error, "utf-8")) |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1122 self.writeln(b")") |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1123 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1124 def write_fsencoding(self, encoding): |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1125 self.write(b"FSENCODING = ") |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1126 self.writeln(util.b(encoding)) |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1127 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1128 def write_flags(self, flags): |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1129 self.write(b"FLAGS = ") |
|
262
c3d6599c1b5e
FIX: treesum: bytearray needs not to be handled
Franz Glasner <fzglas.hg@dom66.de>
parents:
261
diff
changeset
|
1130 if isinstance(flags, (str, bytes)): |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1131 self.writeln(util.b(flags)) |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1132 else: |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1133 flags.sort() |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1134 self.writeln(util.b(",".join(flags))) |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1135 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1136 def write_timestamp(self, ts): |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1137 self.write(b"TIMESTAMP = ") |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1138 self.writeln(util.b(str(ts))) |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1139 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1140 def write_isotimestamp(self, ts): |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1141 self.write(b"ISOTIMESTAMP = ") |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1142 self.writeln(util.b(ts)) |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1143 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1144 def write_root(self, root): |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1145 assert isinstance(root, bytes) |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1146 self.write(b"ROOT (") |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1147 self.write(root) |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1148 self.writeln(b")") |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1149 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1150 def write_size(self, filename, sz): |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1151 assert isinstance(filename, bytes) |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1152 self.write(b"SIZE (") |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1153 self.write(filename) |
|
266
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1154 self.write(b")") |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1155 if sz is not None: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1156 self.write(b" = ") |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1157 self.write(util.b(str(sz))) |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1158 self.writeln(b"") |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1159 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1160 def write_file_digest(self, algorithm, filename, digest, |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1161 use_base64=False, size=None): |
|
266
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1162 if digest is not None: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1163 digest = (base64.b64encode(digest) |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1164 if use_base64 |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1165 else binascii.hexlify(digest)) |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1166 self.write(util.b(algorithm)) |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1167 self.write(b" (") |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1168 self.write(filename) |
|
266
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1169 self.write(b")") |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1170 if digest is not None or size is not None: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1171 self.write(b" = ") |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1172 if digest is not None: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1173 self.write(digest) |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1174 if size is not None: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1175 self.write(b",") |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1176 self.write(util.b(str(size))) |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1177 self.writeln(b"") |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1178 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1179 def finish(self): |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1180 """Finish a block and write the current CRC""" |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1181 crc = self._crc.hexdigest() |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1182 self.write(b"CRC32 = ") |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1183 self.writeln(util.b(crc)) |
|
267
b9aa65a30b4c
treesum: optimize the use of flush() somewhat
Franz Glasner <fzglas.hg@dom66.de>
parents:
266
diff
changeset
|
1184 self.flush() |
|
261
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1185 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1186 def writeln(self, line): |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1187 """Write the bytes `line` into the output file and update the CRC |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1188 accordingly. |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1189 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1190 :param bytes line: The line to write to (without line ending) |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1191 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1192 """ |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1193 self.write(line) |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1194 self.write(self.LS) |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1195 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1196 def write(self, data): |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1197 """Write `data` into the output file and update the CRC accordingly. |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1198 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1199 :param bytes data: The data to write to and to update the CRC with |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1200 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1201 """ |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1202 if data: |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1203 self._outfp.write(data) |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1204 self._crc.update(data) |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1205 |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1206 def flush(self): |
|
a3e25957afb7
treesum: instead of using format_bsd_line use a real write object with specialized methods
Franz Glasner <fzglas.hg@dom66.de>
parents:
260
diff
changeset
|
1207 self._outfp.flush() |
|
124
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1208 |
|
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1209 |
|
188
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1210 class TreesumReader(object): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1211 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1212 """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
|
1213 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1214 Supports the iterator and context manager protocol. |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1215 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1216 """ |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1217 |
|
204
07f1d79e6674
Fully implemented UTF-8 mode for treeview.
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
1218 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
|
1219 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
|
1220 PATTERN2 = re.compile(br"\A(ROOT|COMMENT|ERROR|GENERATOR)[ \t]*\((.*)\)[ \t]*\r?\n\Z") # noqa: E501 line too long |
|
266
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1221 PATTERN3 = re.compile(br"\ASIZE[ \t]*\((.*)\)([ \t]*=[ \t]*(\d+))?[ \t]*\r?\n\Z") # noqa: E501 line too long |
|
275
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
1222 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
|
1223 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1224 def __init__(self, _fp, _filename, _own_fp): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1225 self._fp = _fp |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1226 self._own_fp = _own_fp |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1227 self._filename = _filename |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1228 self._line_no = 0 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1229 self._reset_crc() |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1230 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
|
1231 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
|
1232 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1233 @classmethod |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1234 def from_path(cls_, path): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1235 """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
|
1236 return cls_(open(path, "rb"), path, True) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1237 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1238 @classmethod |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1239 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
|
1240 return cls_(binary_fp, filename, False) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1241 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1242 def __enter__(self): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1243 return self |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1244 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1245 def __exit__(self, *args): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1246 self.close() |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1247 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1248 def close(self): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1249 if self._fp is not None: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1250 try: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1251 if self._own_fp: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1252 self._fp.close() |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1253 finally: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1254 self._fp = None |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1255 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1256 def __iter__(self): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1257 return self |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1258 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1259 def __next__(self): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1260 rec = self.read_record() |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1261 if rec is None: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1262 raise StopIteration() |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1263 return rec |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1264 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1265 if util.PY2: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1266 next = __next__ |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1267 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1268 def all_records(self): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1269 """Iterator over all remaining records""" |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1270 while True: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1271 rec = self.read_record() |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1272 if rec is None: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1273 return |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1274 yield rec |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1275 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1276 def read_record(self): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1277 """Read and parse the "next" line. |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1278 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1279 :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
|
1280 :rtype: tuple or None |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1281 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1282 """ |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1283 # Loop to skip empty lines |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1284 while True: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1285 line = self._get_next_line() |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1286 if not line: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1287 # |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1288 # 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
|
1289 # Check only after the first VERSION line. |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1290 # |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1291 if self._expect_crc is not None: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1292 if self._expect_crc: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1293 logging.warning("CRC32 is missing at EOF") |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1294 return None |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1295 if not self.PATTERN0.search(line): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1296 break |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1297 self._update_crc(line) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1298 # |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1299 # 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
|
1300 # signature |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1301 # |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1302 if self._line_no == 1: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1303 if line.startswith(b"untrusted comment: "): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1304 line = self._get_next_line() |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1305 if not line.endswith(b"\n"): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1306 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
|
1307 # 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
|
1308 base64.b64decode(line[:-1]) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1309 mo = self.PATTERN1.search(line) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1310 if mo: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1311 if mo.group(1) == b"VERSION": |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1312 if self._expect_crc: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1313 logging.warning("CRC32 missing before line %d", |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1314 self._line_no) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1315 self._reset_crc() |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1316 self._expect_crc = True |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1317 self._update_crc(line) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1318 return ("VERSION", util.n(mo.group(2))) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1319 if mo.group(1) == b"CRC32": |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1320 # TODO: check |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1321 if self._expect_crc is None: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1322 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
|
1323 self._line_no) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1324 else: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1325 if self._expect_crc: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1326 if (self._hex_crc() |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1327 != mo.group(2).decode("latin1").upper()): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1328 logging.warning( |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1329 "CRC32 mismatch in line %d:" |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1330 " expected: %s, given: %s", |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1331 self._line_no, |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1332 self._hex_crc(), |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1333 mo.group(2).decode("latin1").upper()) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1334 else: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1335 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
|
1336 self._line_no) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1337 # 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
|
1338 self._expect_crc = False |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1339 return ("CRC32", util.n(mo.group(2))) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1340 else: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1341 self._update_crc(line) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1342 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
|
1343 else: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1344 mo = self.PATTERN2.search(line) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1345 if mo: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1346 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
|
1347 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
|
1348 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
|
1349 elif mo.group(1) == b"ROOT": |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1350 return ("ROOT", mo.group(2)) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1351 assert False, line |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1352 else: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1353 mo = self.PATTERN3.search(line) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1354 if mo: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1355 self._update_crc(line) |
|
266
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1356 if mo.group(2): |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1357 return ("SIZE", mo.group(1), |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1358 int(util.n(mo.group(3)), 10)) |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1359 else: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1360 return ("SIZE", mo.group(1), None) |
|
188
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1361 else: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1362 mo = self.PATTERN4.search(line) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1363 if mo: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1364 self._update_crc(line) |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1365 algo_name = util.n(mo.group(1)) |
|
266
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1366 if mo.group(3): |
|
275
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
1367 if mo.group(4): |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
1368 if (len(mo.group(4)) == |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
1369 2 * self._get_digest_size(algo_name)): |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
1370 # hex |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
1371 digest = binascii.unhexlify(mo.group(4)) |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
1372 else: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
1373 # base64 |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
1374 digest = base64.b64decode(mo.group(4)) |
|
266
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1375 else: |
|
275
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
1376 digest = None |
|
266
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1377 if mo.group(5): |
|
275
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
1378 if mo.group(6): |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
1379 size = int(util.n(mo.group(6)), 10) |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
1380 else: |
|
c72f5b2dbc6f
treesum: Simplify the path computations and make the visible output more consistent.
Franz Glasner <fzglas.hg@dom66.de>
parents:
271
diff
changeset
|
1381 size = None |
|
266
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1382 else: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1383 size = None |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1384 return (algo_name, mo.group(2), digest, size) |
|
188
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1385 else: |
|
266
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
262
diff
changeset
|
1386 return (algo_name, mo.group(2), None, None) |
|
188
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1387 else: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1388 assert False, line |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1389 return line |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1390 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1391 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
|
1392 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
|
1393 if line: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1394 self._line_no += 1 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1395 return line |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1396 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1397 def _reset_crc(self): |
|
260
07a0bc723139
treesum: Implement the CRC-32 using the new util.crc32 module
Franz Glasner <fzglas.hg@dom66.de>
parents:
223
diff
changeset
|
1398 self._crc32 = crc32() |
|
188
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1399 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1400 def _update_crc(self, data): |
|
260
07a0bc723139
treesum: Implement the CRC-32 using the new util.crc32 module
Franz Glasner <fzglas.hg@dom66.de>
parents:
223
diff
changeset
|
1401 self._crc32.update(data) |
|
188
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1402 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1403 def _hex_crc(self): |
|
260
07a0bc723139
treesum: Implement the CRC-32 using the new util.crc32 module
Franz Glasner <fzglas.hg@dom66.de>
parents:
223
diff
changeset
|
1404 return self._crc32.hexdigest() |
|
188
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1405 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1406 def _get_digest_size(self, algo_name): |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1407 if self._current_algo_name == algo_name: |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1408 return self._current_algo_digest_size |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1409 h = util.algotag2algotype(algo_name)() |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1410 self._current_algo_name = algo_name |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1411 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
|
1412 return self._current_algo_digest_size |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1413 |
|
2784fdcc99e5
Implement basic parsing of treesum output.
Franz Glasner <fzglas.hg@dom66.de>
parents:
179
diff
changeset
|
1414 |
|
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
|
1415 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
|
1416 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
|
1417 |
|
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
|
1418 |
|
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
|
1419 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
|
1420 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
|
1421 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
|
1422 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
|
1423 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
|
1424 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
|
1425 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
|
1426 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
|
1427 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
|
1428 |
|
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
|
1429 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
|
1430 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
|
1431 = size = None |
|
219
19eaba51c632
Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents:
218
diff
changeset
|
1432 errors = set() |
|
190
7e0c25a31757
First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents:
189
diff
changeset
|
1433 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
|
1434 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
|
1435 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
|
1436 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
|
1437 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
|
1438 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
|
1439 # 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
|
1440 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
|
1441 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
|
1442 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
|
1443 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
|
1444 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
|
1445 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
|
1446 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
|
1447 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
|
1448 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
|
1449 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
|
1450 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
|
1451 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
|
1452 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
|
1453 comments.append(record[1]) |
|
219
19eaba51c632
Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents:
218
diff
changeset
|
1454 elif record[0] == "ERROR": |
|
19eaba51c632
Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents:
218
diff
changeset
|
1455 errors.add(record[1]) |
|
208
85e7edea8ac7
Print the filesystem encoding and the generator in the "info" output also
Franz Glasner <fzglas.hg@dom66.de>
parents:
207
diff
changeset
|
1456 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
|
1457 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
|
1458 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
|
1459 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
|
1460 # 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
|
1461 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
|
1462 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
|
1463 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
|
1464 # digest line or size line |
|
193
fb36e71f6ba8
Change: path indicators for symlinks: ./@ -> ./@/ and /./@ -> /./@/
Franz Glasner <fzglas.hg@dom66.de>
parents:
191
diff
changeset
|
1465 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
|
1466 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
|
1467 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
|
1468 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
|
1469 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
|
1470 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
|
1471 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
|
1472 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
|
1473 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
|
1474 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
|
1475 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
|
1476 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
|
1477 root, generator, fsencoding, flags, comments, |
|
219
19eaba51c632
Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents:
218
diff
changeset
|
1478 errors, algorithm, digest, size) |
|
19eaba51c632
Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents:
218
diff
changeset
|
1479 root = generator = flags = fsencoding = algorithm \ |
|
19eaba51c632
Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents:
218
diff
changeset
|
1480 = digest = size = None |
|
19eaba51c632
Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents:
218
diff
changeset
|
1481 errors = set() |
|
19eaba51c632
Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents:
218
diff
changeset
|
1482 comments = [] |
|
190
7e0c25a31757
First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents:
189
diff
changeset
|
1483 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
|
1484 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
|
1485 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
|
1486 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
|
1487 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
|
1488 block_no, |
|
219
19eaba51c632
Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents:
218
diff
changeset
|
1489 root, generator, fsencoding, flags, comments, errors, |
|
208
85e7edea8ac7
Print the filesystem encoding and the generator in the "info" output also
Franz Glasner <fzglas.hg@dom66.de>
parents:
207
diff
changeset
|
1490 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
|
1491 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
|
1492 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
|
1493 |
|
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
|
1494 |
|
208
85e7edea8ac7
Print the filesystem encoding and the generator in the "info" output also
Franz Glasner <fzglas.hg@dom66.de>
parents:
207
diff
changeset
|
1495 def print_block_data(block_no, tag, generator, fsencoding, flags, comments, |
|
219
19eaba51c632
Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents:
218
diff
changeset
|
1496 errors, algorithm, digest, size): |
|
190
7e0c25a31757
First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents:
189
diff
changeset
|
1497 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
|
1498 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
|
1499 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
|
1500 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
|
1501 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
|
1502 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
|
1503 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
|
1504 print(" Flags:", flags if flags else "<none>") |
|
220
8db78850d800
"treesum info": print comments only if not empty
Franz Glasner <fzglas.hg@dom66.de>
parents:
219
diff
changeset
|
1505 if comments: |
|
8db78850d800
"treesum info": print comments only if not empty
Franz Glasner <fzglas.hg@dom66.de>
parents:
219
diff
changeset
|
1506 print(" Comments:", comments) |
|
190
7e0c25a31757
First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents:
189
diff
changeset
|
1507 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
|
1508 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
|
1509 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
|
1510 print(" Size:", sizestr) |
|
219
19eaba51c632
Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
Franz Glasner <fzglas.hg@dom66.de>
parents:
218
diff
changeset
|
1511 print(" Errors:", errors if errors else "<none>") |
|
190
7e0c25a31757
First implementation of "treeview info" to print some information from the treeview digest files
Franz Glasner <fzglas.hg@dom66.de>
parents:
189
diff
changeset
|
1512 |
|
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
|
1513 |
|
124
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1514 if __name__ == "__main__": |
|
3bd3f32b5e60
A first version of "treesum" is working
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1515 sys.exit(main()) |
