blob: 23d397dda86ad13c27fb6a11046a5cacbeaf5ee6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
#!/usr/bin/python
"""
From: https://gist.github.com/DaveCTurner/8765561
Modified to print with an extra space between fields
"""
import sys
import tarfile
import hashlib
for filename in sys.argv[1:]:
print filename
with tarfile.open(filename, 'r') as tar:
for tarinfo in tar:
if tarinfo.isreg():
flo = tar.extractfile(tarinfo) # NB doesn't really extract the file, just gives you a stream (file-like-object) for reading it
hash = hashlib.sha1()
while True:
data = flo.read(2**20)
if not data:
break
hash.update(data)
flo.close()
print hash.hexdigest(), '', tarinfo.name
|