Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import hashlib
- import os.path
- def md5_for_file(f, block_size=2**20):
- md5 = hashlib.md5()
- while True:
- data = f.read(block_size)
- if not data:
- break
- md5.update(data)
- print md5.hexdigest()
- return md5
- def checksumModacoFile(path):
- sourceChecksum = os.path.basename(path)
- sourceChecksum = sourceChecksum.lower()
- sourceChecksum = sourceChecksum.split('md5',1)[1].strip('-')
- sourceChecksum = sourceChecksum.split('.')[0]
- checksum = None
- with open(os.path.abspath(path), 'rb') as f:
- checksum = md5_for_file(f)
- return checksum.hexdigest() == sourceChecksum
- if __name__ == "__main__":
- import sys
- files = sys.argv
- files.pop(0) # remove this file from list
- for file_ in files:
- if checksumModacoFile(file_):
- print '[PASS]', file_
- else:
- print '[FAIL]', file_
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement