Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # coding: utf-8
- from hashlib import sha1 as hasher
- import os
- import sys
- from multiprocessing import Pool, Manager
- active = True
- def get_hash(q):
- h = hasher()
- while active or not q.empty():
- with open(q.get(), 'rb') as f:
- for chunk in iter(lambda: f.read(2047), b''):
- h.update(chunk)
- print('{}\t{}'.format(path, h.hexdigest()))
- def find(target):
- if os.path.isdir(target):
- for root, dirs, files in os.walk(target):
- for file in files:
- yield os.path.join(root, file)
- else:
- yield target
- def main():
- if len(sys.argv) < 2:
- sys.exit(1)
- for target in sys.argv[1:]:
- with Pool(processes=4) as pool:
- q = Manager().Queue()
- pool.map(get_hash, (q,))
- for path in find(target):
- q.put(path)
- active = False
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement