Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to the validation script #7

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion first_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def hash_for_fname(fname):
# Convert a string filename to a Path object.
fpath = Path(fname)
# Your code here.
return 'not-really-the-hash'
contents_fpath = fpath.read_bytes()
hash_value_fpath = sha1(contents_fpath).hexdigest()
return hash_value_fpath
jagruti8 marked this conversation as resolved.
Show resolved Hide resolved


# Fill in the function above to make the test below pass.
Expand All @@ -48,11 +50,23 @@ def check_hashes(hash_fname):
# Directory containing hash filenames file.
data_dir = hash_pth.parent
# Read in text for hash filename
text_file = hash_pth.read_text()
# Split into lines.
lines = text_file.splitlines()
# For each line:
for line in lines:
# Split each line into expected_hash and filename
a = line.split(' ')
jagruti8 marked this conversation as resolved.
Show resolved Hide resolved
# Calculate actual hash for given filename.
path = data_dir / a[1]
content = path.read_bytes()
hash_value = sha1(content).hexdigest()

# Check actual hash against expected hash
if hash_value != a[0]:
break
return True

# Return False if any of the hashes do not match.
return False
jagruti8 marked this conversation as resolved.
Show resolved Hide resolved

Expand Down