View difference between Paste ID: wihcqs1M and PmwA7ybG
SHOW: | | - or go back to the newest paste.
1
#!/usr/bin/env python
2
 
3-
import sys
3+
4
import os.path
5
 
6
def md5_for_file(f, block_size=2**20):
7-
files = sys.argv
7+
    md5 = hashlib.md5()
8-
files.pop(0)
8+
    while True:
9
        data = f.read(block_size)
10-
for file_ in files:
10+
        if not data:
11-
    sourceChecksum = os.path.basename(file_)
11+
            break
12
        md5.update(data)
13
    print md5.hexdigest()
14
    return md5
15
16-
    checksum = hashlib.md5()
16+
def checksumModacoFile(path):
17
    sourceChecksum = os.path.basename(path)
18-
    with open(file_, 'r') as f:
18+
19-
        chunk = f.read(512)
19+
20-
        while chunk:
20+
21-
            checksum.update(chunk)
21+
22-
            chunk = f.read(512)
22+
    checksum = None
23
    with open(os.path.abspath(path), 'rb') as f:
24-
    if checksum.hexdigest() == sourceChecksum:
24+
        checksum = md5_for_file(f)
25-
        print '[PASS]', file_
25+
26-
    else:
26+
    return checksum.hexdigest() == sourceChecksum
27-
        print '[FAIL]', file_
27+
28
if __name__ == "__main__":
29
    import sys
30
31
    files = sys.argv
32
    files.pop(0) # remove this file from list
33
    
34
    for file_ in files:
35
        if checksumModacoFile(file_):
36
            print '[PASS]', file_
37
        else:
38
            print '[FAIL]', file_