-
Notifications
You must be signed in to change notification settings - Fork 3
/
cksum.py
66 lines (49 loc) · 1.38 KB
/
cksum.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import argparse
import subprocess
import os
# Arguments
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--file", help="Order checksum file", type=str, required=True)
args = parser.parse_args()
# Read the checksum file
with open(args.file) as f:
validated = f.readlines()
# Filter the checksum file
filtered = []
for v in validated:
if ".hdf" in v:
filtered.append(v)
validated = filtered
# Invalid and missing lists
invalid = []
missing = []
# For each entry in the validated list
for v in validated:
# Get the checksum, size and filename
parts = v.split()
vChecksum = parts[0]
vSize = parts[1]
vFile = parts[2]
# The file is not present
if not os.path.isfile(vFile):
# Add it to the missing list
missing.append(vFile)
continue
# Get the cksum output of the downloaded file
output = subprocess.check_output("cksum " + vFile, shell=True)
parts = output.split()
checksum = parts[0]
size = parts[1]
# The checksum and size match - file validated
if checksum == vChecksum and size == vSize:
print vFile + " verified"
# The the file must be invalid
else:
invalid.append(vFile)
# Output any results
print "\n" + str(len(invalid)) + " corrupt files found - please redownload and rerun"
for f in invalid:
print f
print "\n" + str(len(missing)) + " missing files detected - please download and rerun"
for f in missing:
print f