Show More
@@ -59,7 +59,7 b' def visit(opts, filenames, outfile):' | |||||
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 |
|
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: | |
@@ -95,6 +95,9 b' def visit(opts, filenames, outfile):' | |||||
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: | |
@@ -150,6 +153,8 b' if __name__ == "__main__":' | |||||
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", |
@@ -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 | --sha256 show sha256 hash of the content | |||
16 | -M, --md5 show md5 hash of the content |
|
17 | -M, --md5 show md5 hash of the content | |
17 | -D, --dump dump file content |
|
18 | -D, --dump dump file content | |
18 | -H, --hexdump hexdump file content |
|
19 | -H, --hexdump hexdump file content | |
@@ -41,6 +42,9 b' Tests of the file helper tool' | |||||
41 | $ f --sha1 foo |
|
42 | $ f --sha1 foo | |
42 | foo: sha1=f1d2d2f924e986ac86fdf7b36c94bcdf32beec15 |
|
43 | foo: sha1=f1d2d2f924e986ac86fdf7b36c94bcdf32beec15 | |
43 |
|
44 | |||
|
45 | $ f --sha256 foo | |||
|
46 | foo: sha256=b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c | |||
|
47 | ||||
44 | #if symlink |
|
48 | #if symlink | |
45 | $ f foo --mode |
|
49 | $ f foo --mode | |
46 | foo: mode=644 |
|
50 | foo: mode=644 |
General Comments 0
You need to be logged in to leave comments.
Login now