-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_problem.py
More file actions
71 lines (64 loc) · 1.79 KB
/
check_problem.py
File metadata and controls
71 lines (64 loc) · 1.79 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
import sys
import settings
import subprocess
PIPE = subprocess.PIPE
try:
problem_slug = sys.argv[1]
except:
print("Please provide problem slug")
exit()
try:
slug_parts = problem_slug.split('/')
which_problem = slug_parts.pop()
if which_problem in ['less', 'more']:
problem_name = slug_parts.pop()
problem_folder= os.path.join(problem_name, which_problem)
else:
problem_folder = problem_name = which_problem
problem_name = settings.PROBLEM_NAMES.get(problem_name, problem_name)
except:
print("Unexpected error")
exit()
# Pull code
os.chdir(settings.STUDENT_DIR)
for student in settings.students:
os.chdir(student)
process = subprocess.Popen(['git', 'pull'], stdout=PIPE, stderr=PIPE)
stdoutput, stderroutput = process.communicate()
print(stdoutput)
print(stderroutput)
process = subprocess.Popen(
['git', 'checkout', problem_slug],
stdout=PIPE,
stderr=PIPE
)
stdoutput, stderroutput = process.communicate()
print(stdoutput)
print(stderroutput)
os.chdir('..')
# compare50 this/years/submissions/* \
# -a last/years/submissions/* \
# -d distro/code/*
os.chdir('..')
submissions = os.path.join(settings.STUDENT_DIR, '*', f'{problem_name}.c')
other_submissions = os.path.join(
settings.SOLUTIONS_DIR,
problem_folder,
'*',
f'{problem_name}.c'
)
command = ['python3.9', '-m', 'compare50', submissions, '-a', other_submissions]
dist_code_file = os.path.join(settings.DIST_DIR, f'{problem_name}.c')
if os.path.exists(dist_code_file):
command.append('-d')
command.append(dist_code_file)
if settings.DEBUG:
print(' '.join(command))
exit()
print(' '.join(command))
process = subprocess.Popen(command, stdout=PIPE, stderr=PIPE)
stdoutput, stderroutput = process.communicate()
print(stdoutput)
print(stderroutput)
os.rename('results', f'{problem_name}_results')