|
1 |
| -#! /bin/python3 |
2 |
| -# coding: utf-8 |
| 1 | +#!/bin/python3 |
| 2 | +import importlib.util |
| 3 | +import sys |
3 | 4 |
|
4 |
| -from inginious import input |
5 |
| -from inginious import feedback |
6 |
| -from inginious import input |
7 |
| -import subprocess |
8 |
| -from inginious import rst |
9 |
| -import re |
10 | 5 |
|
| 6 | +# Dynamically load modules we need |
| 7 | +# Credits to https://stackoverflow.com/a/67692/6149867 |
| 8 | +# And for the explanation : http://www.blog.pythonlibrary.org/2016/05/27/python-201-an-intro-to-importlib/ |
| 9 | +def dynamically_load_module(module, path): |
| 10 | + spec = importlib.util.spec_from_file_location(module, path) |
| 11 | + mod = importlib.util.module_from_spec(spec) |
| 12 | + spec.loader.exec_module(mod) |
| 13 | + return mod |
11 | 14 |
|
12 |
| -# Will be filled by process.py |
13 |
| -exercise = 'Anagram' |
14 |
| -student_file = f'{exercise}.java' |
15 |
| -test_file = f'{exercise}TestInginious.java' |
16 | 15 |
|
17 |
| -# Archive for jplag |
| 16 | +##################################### |
| 17 | +# Our import for common run file # |
| 18 | +##################################### |
| 19 | +sys.path.append("/course/common") |
18 | 20 |
|
19 |
| -input.parse_template(student_file) |
20 |
| - |
21 |
| -student_name = input.get_input("@username") |
22 |
| -subprocess.call(['archive', '-a', student_file,'-o',student_name+''], universal_newlines=True) |
23 |
| - |
24 |
| - |
25 |
| -compile_error = subprocess.call(f'javac -cp ".:libs/junit-4.12.jar:libs/hamcrest-core-1.3.jar:libs/JavaGrading.jar" RunTests.java {test_file} {student_file} 2>&1', shell=True, stdout=open('compiler.out', 'w')) |
26 |
| - |
27 |
| -if compile_error != 0: |
28 |
| - codeblock = rst.get_codeblock("java", open('compiler.out').read()) |
29 |
| - feedback.set_global_feedback("Votre code ne compile pas: \n\n" + codeblock, True) |
30 |
| - feedback.set_global_result("failed") |
31 |
| - exit(0) |
32 |
| - |
33 |
| - |
34 |
| -try: |
35 |
| - out = subprocess.check_output('java -cp "libs/junit-4.12.jar:libs/hamcrest-core-1.3.jar:libs/JavaGrading.jar:." RunTests', shell=True).decode('utf8') |
36 |
| - out = out[out.index('--- GRADE ---'):] |
37 |
| - |
38 |
| - grade = re.findall(r"^TOTAL ([0-9\.]+)/([0-9\.]+)$", out, re.MULTILINE)[-1] |
39 |
| - grade = 100.0*float(grade[0])/float(grade[1]) |
40 |
| - |
41 |
| - feedback.set_grade(grade) |
42 |
| - output = '\n'.join(out.split('\n')[1:-4]) |
43 |
| - feedback.set_global_feedback("Résultat des tests: \n\n" + output, True) |
44 |
| - |
45 |
| - if grade < 99.99 : |
46 |
| - feedback.set_global_result("failed") |
47 |
| - else: |
48 |
| - feedback.set_global_result("success") |
49 |
| -except Exception as e: |
50 |
| - feedback.set_global_feedback("Une erreur s'est produite!." + str(e), True) |
51 |
| - feedback.set_global_result("failed") |
| 21 | +runfile = dynamically_load_module("runfile", "/course/common/runfile.py") |
| 22 | +runfile.main() |
0 commit comments