Skip to content

Commit bdce3fa

Browse files
committed
Add error codes to output for easier grader debugging
1 parent 7365cf3 commit bdce3fa

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

prework.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,8 @@ def check_file(filename, correct_hash=None, different_hash=None, correct_perms=N
8989

9090
def is_writable(filename):
9191
"""Check if the given file has any write permissions"""
92-
with open(filename, 'rb') as target_file:
93-
new_perms = oct(os.stat(filename).st_mode)[-3:]
94-
return any([i in "2367" for i in new_perms])
92+
new_perms = oct(os.stat(filename).st_mode)[-3:]
93+
return any([i in "2367" for i in new_perms])
9594

9695
def check_challenge_1():
9796
print("### Challenge 1 ###\n")
@@ -115,7 +114,7 @@ def check_challenge_1():
115114
print(f"\tYour permissions:\tpermanent.txt ({oct(os.stat('permanent.txt').st_mode)[-3:]})\n")
116115
return False
117116
else:
118-
print("⛔ Sorry, that's not the right answer. Please make sure your challenge_1 command modifies the file's content, but not its' permissions.\n")
117+
print("⛔ Sorry, that's not the right answer. Please make sure your challenge_1 command modifies the file's content, but not its' permissions. Error code: {result}\n")
119118
return False
120119

121120

@@ -143,7 +142,7 @@ def check_challenge_2():
143142
print(f"🚧 Your command ran, but it seems like you accidentally modified the contents of permanent.txt. Please check your command and try again.\n")
144143
return False
145144
else:
146-
print("⛔ Sorry, that's not the right answer. Please make sure your challenge_2 command modifies the file's permissions, but not its' content.\n")
145+
print("⛔ Sorry, that's not the right answer. Please make sure your challenge_2 command modifies the file's permissions, but not its' content. Error code: {result}\n")
147146
return False
148147

149148
def check_challenge_3():
@@ -159,7 +158,7 @@ def check_challenge_3():
159158
if result1 == 0:
160159
print(f"Done.")
161160
else:
162-
print("⛔ Sorry, that's not the right answer. Please make sure your challenge_3 command does not modify the original random.txt file.")
161+
print("⛔ Sorry, that's not the right answer. Please make sure your challenge_3 command does not modify the original random.txt file. Error code: {result1}")
163162
return False
164163

165164
# Check if copy.txt has been created
@@ -175,7 +174,7 @@ def check_challenge_3():
175174
print(f"Your command was:\n\t> {chal.read()}\n")
176175
return True
177176
else:
178-
print(f"🚧 You're making progress! Your command creates copy.txt, but its contents do not match random.txt. Please check your command and try again.\n")
177+
print(f"🚧 You're making progress! Your command creates copy.txt, but its contents do not match random.txt. Please check your command and try again. Error code: {result2}\n")
179178
return False
180179

181180
dramatic_print([f"Validating scripts.", ".", ". "])

0 commit comments

Comments
 (0)