##// END OF EJS Templates
testlib: add `--raw-sha1` option to `f`...
Raphaël Gomès -
r50451:9172bd49 stable
parent child Browse files
Show More
@@ -63,7 +63,16 b' def visit(opts, filenames, outfile):'
63 if isfile:
63 if isfile:
64 if opts.type:
64 if opts.type:
65 facts.append(b'file')
65 facts.append(b'file')
66 if any((opts.hexdump, opts.dump, opts.md5, opts.sha1, opts.sha256)):
66 needs_reading = (
67 opts.hexdump,
68 opts.dump,
69 opts.md5,
70 opts.sha1,
71 opts.raw_sha1,
72 opts.sha256,
73 )
74
75 if any(needs_reading):
67 with open(f, 'rb') as fobj:
76 with open(f, 'rb') as fobj:
68 content = fobj.read()
77 content = fobj.read()
69 elif islink:
78 elif islink:
@@ -101,6 +110,9 b' def visit(opts, filenames, outfile):'
101 if opts.md5 and content is not None:
110 if opts.md5 and content is not None:
102 h = hashlib.md5(content)
111 h = hashlib.md5(content)
103 facts.append(b'md5=%s' % binascii.hexlify(h.digest())[: opts.bytes])
112 facts.append(b'md5=%s' % binascii.hexlify(h.digest())[: opts.bytes])
113 if opts.raw_sha1 and content is not None:
114 h = hashlib.sha1(content)
115 facts.append(b'raw-sha1=%s' % h.digest()[: opts.bytes])
104 if opts.sha1 and content is not None:
116 if opts.sha1 and content is not None:
105 h = hashlib.sha1(content)
117 h = hashlib.sha1(content)
106 facts.append(
118 facts.append(
@@ -186,6 +198,12 b' if __name__ == "__main__":'
186 )
198 )
187 parser.add_option(
199 parser.add_option(
188 "",
200 "",
201 "--raw-sha1",
202 action="store_true",
203 help="show raw bytes of the sha1 hash of the content",
204 )
205 parser.add_option(
206 "",
189 "--sha256",
207 "--sha256",
190 action="store_true",
208 action="store_true",
191 help="show sha256 hash of the content",
209 help="show sha256 hash of the content",
@@ -13,6 +13,7 b' Tests of the file helper tool'
13 check if file is newer (or same)
13 check if file is newer (or same)
14 -r, --recurse recurse into directories
14 -r, --recurse recurse into directories
15 -S, --sha1 show sha1 hash of the content
15 -S, --sha1 show sha1 hash of the content
16 --raw-sha1 show raw bytes of the sha1 hash of the content
16 --sha256 show sha256 hash of the content
17 --sha256 show sha256 hash of the content
17 -M, --md5 show md5 hash of the content
18 -M, --md5 show md5 hash of the content
18 -D, --dump dump file content
19 -D, --dump dump file content
General Comments 0
You need to be logged in to leave comments. Login now