@@ -61,16 +61,13 @@ def validate_data(data_directory):
61
61
# If hash for filename is not the same as the one in the file, raise
62
62
# ValueError
63
63
# This is a placeholder, replace it to write your solution.
64
- data_pth = Path () / data_directory
64
+ data_pth = Path (data_directory )
65
65
# print(data_pth)
66
66
hash_pth = list (data_pth .glob ("**/*.txt" ))
67
67
hash_pth = str (hash_pth [0 ])
68
68
# hash_pth= "data_pth/**/hash_list.txt"
69
69
# print(hash_pth[0])
70
70
71
- # hash_pth = Path(data_directory)
72
- # hash_pth = data_pth/group-0/'data_hashes.txt'
73
- # data_dir = hash_pth.parent
74
71
with open (hash_pth ) as f :
75
72
lines = f .readlines ()
76
73
# print(lines)
@@ -89,28 +86,26 @@ def validate_data(data_directory):
89
86
90
87
#print(d_pth)
91
88
92
- cal_hash = file_hash (data_pth / spl [1 ])
89
+ cal_hash = file_hash (data_pth . parent / spl [1 ])
93
90
# Check actual hash against expected hash
94
91
act_hash = spl [0 ]
95
92
# Return False if any of the hashes do not match.
96
93
if cal_hash != act_hash :
97
- return False
98
-
99
- # raise NotImplementedError(
100
- # "This is just a template -- you are expected to code this."
101
- # )
102
- return True
103
-
94
+ raise ValueError (f'{ spl [1 ]} changed, hashes do not match' )
95
+ print (f'{ data_directory } is not corrupted, all the hashes match' )
96
+ return
104
97
105
98
def main ():
106
99
# This function (main) called when this file run as a script.
107
- #
108
- # Get the data directory from the command line arguments
109
- if len (sys .argv ) < 2 :
110
- raise RuntimeError ("Please give data directory on " "command line" )
111
- data_directory = sys .argv [1 ]
100
+ group_directory = (Path (__file__ ).parent .parent / 'data' )
101
+ groups = list (group_directory .glob ('group-??' ))
102
+ if len (groups ) == 0 :
103
+ raise RuntimeError ('No group directory in data directory: '
104
+ 'have you downloaded and unpacked the data?' )
105
+ if len (groups ) > 1 :
106
+ raise RuntimeError ('Too many group directories in data directory' )
112
107
# Call function to validate data in data directory
113
- validate_data (data_directory )
108
+ validate_data (groups [ 0 ] )
114
109
115
110
116
111
if __name__ == "__main__" :
0 commit comments