Mercurial > hg
comparison tests/f @ 35472:c1f7037c2ded
tests: teach `f` to handle sha256 checksums
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Wed, 20 Dec 2017 20:46:33 -0500 |
parents | ea4d27aac557 |
children | c69e78ef2b54 |
comparison
equal
deleted
inserted
replaced
35471:ea4d27aac557 | 35472:c1f7037c2ded |
---|---|
57 content = None | 57 content = None |
58 facts = [] | 58 facts = [] |
59 if isfile: | 59 if isfile: |
60 if opts.type: | 60 if opts.type: |
61 facts.append('file') | 61 facts.append('file') |
62 if opts.hexdump or opts.dump or opts.md5 or opts.sha1: | 62 if any((opts.hexdump, opts.dump, opts.md5, opts.sha1, opts.sha256)): |
63 content = open(f, 'rb').read() | 63 content = open(f, 'rb').read() |
64 elif islink: | 64 elif islink: |
65 if opts.type: | 65 if opts.type: |
66 facts.append('link') | 66 facts.append('link') |
67 content = os.readlink(f) | 67 content = os.readlink(f) |
93 h = hashlib.md5(content) | 93 h = hashlib.md5(content) |
94 facts.append('md5=%s' % h.hexdigest()[:opts.bytes]) | 94 facts.append('md5=%s' % h.hexdigest()[:opts.bytes]) |
95 if opts.sha1 and content is not None: | 95 if opts.sha1 and content is not None: |
96 h = hashlib.sha1(content) | 96 h = hashlib.sha1(content) |
97 facts.append('sha1=%s' % h.hexdigest()[:opts.bytes]) | 97 facts.append('sha1=%s' % h.hexdigest()[:opts.bytes]) |
98 if opts.sha256 and content is not None: | |
99 h = hashlib.sha256(content) | |
100 facts.append('sha256=%s' % h.hexdigest()[:opts.bytes]) | |
98 if isstdin: | 101 if isstdin: |
99 outfile.write(b', '.join(facts) + b'\n') | 102 outfile.write(b', '.join(facts) + b'\n') |
100 elif facts: | 103 elif facts: |
101 outfile.write(b'%s: %s\n' % (f.encode('utf-8'), b', '.join(facts))) | 104 outfile.write(b'%s: %s\n' % (f.encode('utf-8'), b', '.join(facts))) |
102 elif not quiet: | 105 elif not quiet: |
148 help="check if file is newer (or same)") | 151 help="check if file is newer (or same)") |
149 parser.add_option("-r", "--recurse", action="store_true", | 152 parser.add_option("-r", "--recurse", action="store_true", |
150 help="recurse into directories") | 153 help="recurse into directories") |
151 parser.add_option("-S", "--sha1", action="store_true", | 154 parser.add_option("-S", "--sha1", action="store_true", |
152 help="show sha1 hash of the content") | 155 help="show sha1 hash of the content") |
156 parser.add_option("", "--sha256", action="store_true", | |
157 help="show sha256 hash of the content") | |
153 parser.add_option("-M", "--md5", action="store_true", | 158 parser.add_option("-M", "--md5", action="store_true", |
154 help="show md5 hash of the content") | 159 help="show md5 hash of the content") |
155 parser.add_option("-D", "--dump", action="store_true", | 160 parser.add_option("-D", "--dump", action="store_true", |
156 help="dump file content") | 161 help="dump file content") |
157 parser.add_option("-H", "--hexdump", action="store_true", | 162 parser.add_option("-H", "--hexdump", action="store_true", |