Skip to content

Commit 2a6c5e0

Browse files
committed
Fixed the scripts/validate_data.py file and modified the .gitignore file
1 parent d124ae6 commit 2a6c5e0

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*.pyc
22
__pycache__/
3+
.DS_Store

scripts/validate_data.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,13 @@ def validate_data(data_directory):
6161
# If hash for filename is not the same as the one in the file, raise
6262
# ValueError
6363
# This is a placeholder, replace it to write your solution.
64-
data_pth = Path() / data_directory
64+
data_pth = Path(data_directory)
6565
# print(data_pth)
6666
hash_pth = list(data_pth.glob("**/*.txt"))
6767
hash_pth = str(hash_pth[0])
6868
# hash_pth= "data_pth/**/hash_list.txt"
6969
# print(hash_pth[0])
7070

71-
# hash_pth = Path(data_directory)
72-
# hash_pth = data_pth/group-0/'data_hashes.txt'
73-
# data_dir = hash_pth.parent
7471
with open(hash_pth) as f:
7572
lines = f.readlines()
7673
# print(lines)
@@ -89,28 +86,26 @@ def validate_data(data_directory):
8986

9087
#print(d_pth)
9188

92-
cal_hash = file_hash(data_pth / spl[1])
89+
cal_hash = file_hash(data_pth.parent / spl[1])
9390
# Check actual hash against expected hash
9491
act_hash = spl[0]
9592
# Return False if any of the hashes do not match.
9693
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
10497

10598
def main():
10699
# 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')
112107
# Call function to validate data in data directory
113-
validate_data(data_directory)
108+
validate_data(groups[0])
114109

115110

116111
if __name__ == "__main__":

0 commit comments

Comments
 (0)