-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment_autograder.py
More file actions
51 lines (33 loc) · 1.72 KB
/
assignment_autograder.py
File metadata and controls
51 lines (33 loc) · 1.72 KB
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
WeChat: cstutorcs
QQ: 749389476
Email: tutorcs@163.com
#!/usr/bin/python3
import sys
from quickselect import autograder as quickselect_autograder
from editDistance import autograder as editDistance_autograder
from balanced import autograder as balanced_autograder
total = 0
if len( sys.argv ) > 1:
import tarfile, os, shutil
with tarfile.open(sys.argv[1]) as tarball:
def is_within_directory(directory, target):
abs_directory = os.path.abspath(directory)
abs_target = os.path.abspath(target)
prefix = os.path.commonprefix([abs_directory, abs_target])
return prefix == abs_directory
def safe_extract(tar, path=".", members=None, *, numeric_owner=False):
for member in tar.getmembers():
member_path = os.path.join(path, member.name)
if not is_within_directory(path, member_path):
raise Exception("Attempted Path Traversal in Tar File")
tar.extractall(path, members, numeric_owner=numeric_owner)
safe_extract(tarball, "tar_test")
total += quickselect_autograder.grade_quickselect ( path="tar_test/quickselect/", verbose=True )
total += editDistance_autograder.grade_editDistance ( path="tar_test/editDistance/", verbose=True )
total += balanced_autograder.grade_balanced ( path="tar_test/balanced/", verbose=True )
shutil.rmtree("tar_test")
else:
total += quickselect_autograder.grade_quickselect ( path="quickselect/", verbose=True )
total += editDistance_autograder.grade_editDistance ( path="editDistance/", verbose=True )
total += balanced_autograder.grade_balanced ( path="balanced/", verbose=True )
print ("Score on assignment: {} out of 75.".format(total))