Skip to content
Snippets Groups Projects
Commit c85068a4 authored by tuhe's avatar tuhe
Browse files

updates

parent 54569673
No related branches found
No related tags found
No related merge requests found
Showing
with 9 additions and 1325 deletions
import os
import glob
import shutil
import time
import zipfile
import io
import subprocess
import urllib.request
def download_docker_images(destination=None):
if destination is None:
destination = os.getcwd()
if not os.path.exists(destination):
os.makedirs(destination)
print('Beginning file download with urllib2...')
url = 'https://gitlab.compute.dtu.dk/tuhe/unitgrade_private/-/archive/master/unitgrade_private-master.zip?path=docker_images'
result, headers = urllib.request.urlretrieve(url)
ex = result +"_extract"
zf = zipfile.ZipFile(result)
zf.extractall(path=ex)
dockers = [f for f in zf.namelist() if f[-1] == "/" and len( [s for s in f if s == "/"] ) == 3]
for f in dockers: # zf.namelist():
tmp_dir = ex + "/" + f
if os.path.isdir(tmp_dir):
dest = destination +"/"+os.path.basename(tmp_dir[:-1])
if os.path.isdir(dest):
print("> Destination for docker image", dest, "exists. Skipping download.")
else:
print("> Extracting docker image", os.path.basename(f[:-1]), "to", dest)
shutil.copytree(tmp_dir, dest)
def compile_docker_image(Dockerfile, tag=None):
assert os.path.isfile(Dockerfile)
base = os.path.dirname(Dockerfile)
if tag == None:
tag = os.path.basename(base)
os.system(f"cd {base} && docker build --tag {tag} .")
return tag
def student_token_file_runner(host_tmp_dir, student_token_file, instructor_grade_script, grade_file_relative_destination):
"""
This code is used to run student unitgrade tests (i.e., a .token file).
Use by autolab code.
It accepts a student .token file which is extracted, the 'correct' instructor grade script is copied
into it, and it is then run.
:param Dockerfile_location:
:param host_tmp_dir:
:param student_token_file:
:param ReportClass:
:param instructor_grade_script:
:return:
"""
assert os.path.exists(student_token_file)
assert os.path.exists(instructor_grade_script)
from unitgrade_private import load_token
start = time.time()
results, _ = load_token(student_token_file)
sources = results['sources'][0]
with io.BytesIO(sources['zipfile']) as zb:
with zipfile.ZipFile(zb) as zip:
zip.extractall(host_tmp_dir)
# Done extracting the zip file! Now time to move the (good) report test class into the location.
gscript = instructor_grade_script
print(f"{sources['report_relative_location']=}")
print(f"{sources['name']=}")
print("Now in docker_helpers.py")
print(f'{gscript=}')
print(f'{instructor_grade_script=}')
gscript_destination = host_tmp_dir + "/" + grade_file_relative_destination
print(f'{gscript_destination=}')
shutil.copy(gscript, gscript_destination)
# Now everything appears very close to being set up and ready to roll!.
d = os.path.normpath(grade_file_relative_destination).split(os.sep)
d = d[:-1] + [os.path.basename(instructor_grade_script)[:-3]]
pycom = ".".join(d)
"""
docker run -v c:/Users/tuhe/Documents/2021/python-docker/tmp:/app python-docker python3 -m cs202courseware.ug2report1_grade
"""
pycom = "python3 -m " + pycom
print(f"{pycom=}")
token_location = host_tmp_dir + "/" + os.path.dirname( grade_file_relative_destination ) + "/*.token"
elapsed = time.time() - start
# print("Elapsed time is", elapsed)
return pycom, host_tmp_dir, token_location
def docker_run_token_file(Dockerfile_location, host_tmp_dir, student_token_file, tag=None, instructor_grade_script=None,
fix_user=None,
# grade_script_relative_destination_dir=None, # The relative location relative to the top-dir containing the package. Example: irlc/project1
xvfb=True):
"""
xvfb: Control whether to use X-windows. Works on linux. This seems like a good idea when using e.g. gym.
This thingy works:
To build the image, run:
docker build --tag python-docker .
To run the app run:
docker run -v c:/Users/tuhe/Documents/2021/python-docker/tmp:/app python-docker > output.log
"""
Dockerfile_location = Dockerfile_location.replace("\\", "/")
host_tmp_dir = host_tmp_dir.replace("\\", "/")
student_token_file = student_token_file.replace("\\", "/")
# A bunch of tests. This is going to be great!
Dockerfile_location = os.path.abspath(Dockerfile_location)
assert os.path.exists(Dockerfile_location)
start = time.time()
if fix_user is None:
fix_user = os.name != 'nt' # On Linux, this should probably be true to avoid problem with edit-rights of docker-created files.
# with open(student_token_file, 'rb') as f:
# results = pickle.load(f)
from unitgrade_private import load_token
results, _ = load_token(student_token_file)
sources = results['sources'][0]
if os.path.exists(host_tmp_dir):
shutil.rmtree(host_tmp_dir)
with io.BytesIO(sources['zipfile']) as zb:
with zipfile.ZipFile(zb) as zip:
zip.extractall(host_tmp_dir)
# Done extracting the zip file! Now time to move the (good) report test class into the location.
gscript = instructor_grade_script
# if grade_script_relative_destination_dir is None:
# student_grade_script = host_tmp_dir + "/" + sources['report_relative_location']
# else:
# student_grade_script = host_tmp_dir + "/" + grade_script_relative_destination_dir
# Get relative location from first line of the grade script.
with open(instructor_grade_script, 'r') as f:
student_grade_script_dir = os.path.dirname( host_tmp_dir + "/" + f.read().splitlines()[0][1:].strip() )
print("student_grade_script", student_grade_script_dir)
student_grade_script_dir = student_grade_script_dir.replace("\\", "/")
instructor_grade_script = student_grade_script_dir + "/"+os.path.basename(gscript)
shutil.copy(gscript, instructor_grade_script)
"""
docker run -v c:/Users/tuhe/Documents/2021/python-docker/tmp:/home python-docker python3 -m cs202courseware.ug2report1_grade
"""
if tag is None:
dockname = os.path.basename( os.path.dirname(Dockerfile_location) )
else:
dockname = tag
tmp_grade_file = sources['name'] + "/" + sources['report_relative_location']
tmp_grade_file = tmp_grade_file.replace("\\", "/")
# pycom = ".".join( sources['report_module_specification'][:-1] + [os.path.basename(gscript)[:-3],] )
pycom = ".".join(os.path.relpath(instructor_grade_script, host_tmp_dir)[:-3].split("/"))
pycom = "python3 -m " + pycom
if fix_user:
user_cmd = ' --user "$(id -u):$(id -g)" '
else:
user_cmd = ''
if xvfb:
user_cmd = " -e DISPLAY=:0 -v /tmp/.X11-unix:/tmp/.X11-unix " + user_cmd
tmp_path = os.path.abspath(host_tmp_dir).replace("\\", "/")
dcom = f"docker run {user_cmd} -v {tmp_path}:/home {dockname} {pycom}"
cdcom = f"cd {os.path.dirname(Dockerfile_location)}"
fcom = f"{cdcom} && {dcom}"
print("> Running docker command")
print(fcom)
init = time.time() - start
# thtools.execute_command(fcom.split())
out = subprocess.check_output(fcom, shell=True).decode("utf-8")
host_tmp_dir +"/" + os.path.dirname(tmp_grade_file) + "/"
tokens = glob.glob( os.path.dirname(instructor_grade_script) + "/*.token" )
for t in tokens:
print("Source image produced token", t)
elapsed = time.time() - start
print("Elapsed time is", elapsed, f"({init=} seconds)")
if len(tokens) != 1:
print("Wrong number of tokens produced:", len(tokens))
print(out)
return tokens[0]
import os
import glob
import shutil
import sys
import subprocess
from unitgrade_private.autolab.autolab import format_autolab_json
from unitgrade_private.docker_helpers import student_token_file_runner
from unitgrade_private import load_token
import time
verbose = False
tag = "[driver_python.py]"
if not verbose:
print("="*10)
print(tag, "Starting unitgrade evaluation...")
sys.stderr = sys.stdout
wdir = os.getcwd()
def pfiles():
print("> Files in dir:")
for f in glob.glob(wdir + "/*"):
print(f)
print("---")
handin_filename = "Report2_handin.token"
student_token_file = 'Report2_handin.token'
instructor_grade_script = 'report2_grade.py'
grade_file_relative_destination = "cs102/report2_grade.py"
host_tmp_dir = wdir + "/tmp"
homework_file = ""
# homework_file = ""
student_should_upload_token = # Add these from template.
if not verbose:
pfiles()
print(f"{host_tmp_dir=}")
print(f"{student_token_file=}")
print(f"{instructor_grade_script=}")
command, host_tmp_dir, token = student_token_file_runner(host_tmp_dir, student_token_file, instructor_grade_script, grade_file_relative_destination)
# Alternatively. Unzip the .token file of the student (true version). Overwrite the .py file with the one uploaded, then
# run the stuff.
if not student_should_upload_token:
""" Add the student homework to the right location. """
print("Moving from", os.path.basename(handin_filename), "to", handin_filename)
print("file exists?", os.path.isfile(os.path.basename(handin_filename)))
shutil.move(os.path.basename(handin_filename), host_tmp_dir + "/" + handin_filename)
command = f"cd tmp && {command} --noprogress --autolab"
def rcom(cm):
rs = subprocess.run(cm, capture_output=True, text=True, shell=True)
print(rs.stdout)
if len(rs.stderr) > 0:
print(tag, "There were errors in executing the file:")
print(rs.stderr)
start = time.time()
rcom(command)
ls = glob.glob(token)
f = ls[0]
results, _ = load_token(ls[0])
if verbose:
print(f"{token=}")
print(results['total'])
format_autolab_json(results)
# if os.path.exists(host_tmp_dir):
# shutil.rmtree(host_tmp_dir)
# with io.BytesIO(sources['zipfile']) as zb:
# with zipfile.ZipFile(zb) as zip:
# zip.extractall(host_tmp_dir
# print("="*10)
# print('{"scores": {"Correctness": 100, "Problem 1": 4}}')
## Format the scores here.
# sc = [('Total', results['total'][0])] + [(q['title'], q['obtained']) for k, q in results['details'].items()]
# ss = ", ".join([f'"{t}": {s}' for t, s in sc])
# scores = '{"scores": {' + ss + '}}'
# print('{"_presentation": "semantic"}')
# print(scores)
File deleted
require "AssessmentBase.rb"
module Cs102
include AssessmentBase
def assessmentInitialize(course)
super("cs102",course)
@problems = []
end
end
\ No newline at end of file
---
general:
name: cs102
description: ''
display_name: CS 102 Report 2
handin_filename: Report2_handin.token
handin_directory: handin
max_grace_days: 0
handout: cs102-handout.tar
writeup: writeup/cs102.html
max_submissions: -1
disable_handins: false
max_size: 2
has_svn: false
category_name: Lab
problems:
- name: Unitgrade score
description: ''
max_score: 16
optional: false
autograder:
autograde_timeout: 180
autograde_image: tango_python_tue
release_score: true
# problems:
# - name: Correctness
# description: ''
# max_score: 100.0
# optional: false
\ No newline at end of file
# Makefile for the Hello Lab
all:
echo "Makefile called... it is empty so far. "
#gcc hello3.c -o hello3
clean:
rm -rf *~ hello3
# Makefile for the Hello Lab
all:
echo "Makefile called... it is empty so far. "
#gcc hello3.c -o hello3
clean:
rm -rf *~ hello3
This directory contains all of the code files for the Hello Lab,
including the files that are handed out to students.
Files:
# Autograder and solution files
Makefile Makefile and ...
README ... README for this directory
driver.sh* Autograder
hello.c Solution hello.c file
# Files that are handed out to students
Makefile-handout Makefile and ...
README-handout ... README handed out to students
hello.c-handout Blank hello.c file handed out to students
This directory contains all of the code files for the Hello Lab,
including the files that are handed out to students.
Files:
# Autograder and solution files
Makefile Makefile and ...
README ... README for this directory
driver.sh* Autograder
hello.c Solution hello.c file
# Files that are handed out to students
Makefile-handout Makefile and ...
README-handout ... README handed out to students
hello.c-handout Blank hello.c file handed out to students
This diff is collapsed.
import os
import glob
import shutil
import time
import zipfile
import io
import subprocess
import urllib.request
def download_docker_images(destination=None):
if destination is None:
destination = os.getcwd()
if not os.path.exists(destination):
os.makedirs(destination)
print('Beginning file download with urllib2...')
url = 'https://gitlab.compute.dtu.dk/tuhe/unitgrade_private/-/archive/master/unitgrade_private-master.zip?path=docker_images'
result, headers = urllib.request.urlretrieve(url)
ex = result +"_extract"
zf = zipfile.ZipFile(result)
zf.extractall(path=ex)
dockers = [f for f in zf.namelist() if f[-1] == "/" and len( [s for s in f if s == "/"] ) == 3]
for f in dockers: # zf.namelist():
tmp_dir = ex + "/" + f
if os.path.isdir(tmp_dir):
dest = destination +"/"+os.path.basename(tmp_dir[:-1])
if os.path.isdir(dest):
print("> Destination for docker image", dest, "exists. Skipping download.")
else:
print("> Extracting docker image", os.path.basename(f[:-1]), "to", dest)
shutil.copytree(tmp_dir, dest)
def compile_docker_image(Dockerfile, tag=None):
assert os.path.isfile(Dockerfile)
base = os.path.dirname(Dockerfile)
if tag == None:
tag = os.path.basename(base)
os.system(f"cd {base} && docker build --tag {tag} .")
return tag
def student_token_file_runner(host_tmp_dir, student_token_file, instructor_grade_script, grade_file_relative_destination):
"""
This code is used to run student unitgrade tests (i.e., a .token file).
Use by autolab code.
It accepts a student .token file which is extracted, the 'correct' instructor grade script is copied
into it, and it is then run.
:param Dockerfile_location:
:param host_tmp_dir:
:param student_token_file:
:param ReportClass:
:param instructor_grade_script:
:return:
"""
assert os.path.exists(student_token_file)
assert os.path.exists(instructor_grade_script)
from unitgrade_private import load_token
start = time.time()
results, _ = load_token(student_token_file)
sources = results['sources'][0]
with io.BytesIO(sources['zipfile']) as zb:
with zipfile.ZipFile(zb) as zip:
zip.extractall(host_tmp_dir)
# Done extracting the zip file! Now time to move the (good) report test class into the location.
gscript = instructor_grade_script
print(f"{sources['report_relative_location']=}")
print(f"{sources['name']=}")
print("Now in docker_helpers.py")
print(f'{gscript=}')
print(f'{instructor_grade_script=}')
gscript_destination = host_tmp_dir + "/" + grade_file_relative_destination
print(f'{gscript_destination=}')
shutil.copy(gscript, gscript_destination)
# Now everything appears very close to being set up and ready to roll!.
d = os.path.normpath(grade_file_relative_destination).split(os.sep)
d = d[:-1] + [os.path.basename(instructor_grade_script)[:-3]]
pycom = ".".join(d)
"""
docker run -v c:/Users/tuhe/Documents/2021/python-docker/tmp:/app python-docker python3 -m cs202courseware.ug2report1_grade
"""
pycom = "python3 -m " + pycom
print(f"{pycom=}")
token_location = host_tmp_dir + "/" + os.path.dirname( grade_file_relative_destination ) + "/*.token"
elapsed = time.time() - start
# print("Elapsed time is", elapsed)
return pycom, host_tmp_dir, token_location
def docker_run_token_file(Dockerfile_location, host_tmp_dir, student_token_file, tag=None, instructor_grade_script=None,
fix_user=None,
# grade_script_relative_destination_dir=None, # The relative location relative to the top-dir containing the package. Example: irlc/project1
xvfb=True):
"""
xvfb: Control whether to use X-windows. Works on linux. This seems like a good idea when using e.g. gym.
This thingy works:
To build the image, run:
docker build --tag python-docker .
To run the app run:
docker run -v c:/Users/tuhe/Documents/2021/python-docker/tmp:/app python-docker > output.log
"""
Dockerfile_location = Dockerfile_location.replace("\\", "/")
host_tmp_dir = host_tmp_dir.replace("\\", "/")
student_token_file = student_token_file.replace("\\", "/")
# A bunch of tests. This is going to be great!
Dockerfile_location = os.path.abspath(Dockerfile_location)
assert os.path.exists(Dockerfile_location)
start = time.time()
if fix_user is None:
fix_user = os.name != 'nt' # On Linux, this should probably be true to avoid problem with edit-rights of docker-created files.
# with open(student_token_file, 'rb') as f:
# results = pickle.load(f)
from unitgrade_private import load_token
results, _ = load_token(student_token_file)
sources = results['sources'][0]
if os.path.exists(host_tmp_dir):
shutil.rmtree(host_tmp_dir)
with io.BytesIO(sources['zipfile']) as zb:
with zipfile.ZipFile(zb) as zip:
zip.extractall(host_tmp_dir)
# Done extracting the zip file! Now time to move the (good) report test class into the location.
gscript = instructor_grade_script
# if grade_script_relative_destination_dir is None:
# student_grade_script = host_tmp_dir + "/" + sources['report_relative_location']
# else:
# student_grade_script = host_tmp_dir + "/" + grade_script_relative_destination_dir
# Get relative location from first line of the grade script.
with open(instructor_grade_script, 'r') as f:
student_grade_script_dir = os.path.dirname( host_tmp_dir + "/" + f.read().splitlines()[0][1:].strip() )
print("student_grade_script", student_grade_script_dir)
student_grade_script_dir = student_grade_script_dir.replace("\\", "/")
instructor_grade_script = student_grade_script_dir + "/"+os.path.basename(gscript)
shutil.copy(gscript, instructor_grade_script)
"""
docker run -v c:/Users/tuhe/Documents/2021/python-docker/tmp:/home python-docker python3 -m cs202courseware.ug2report1_grade
"""
if tag is None:
dockname = os.path.basename( os.path.dirname(Dockerfile_location) )
else:
dockname = tag
tmp_grade_file = sources['name'] + "/" + sources['report_relative_location']
tmp_grade_file = tmp_grade_file.replace("\\", "/")
# pycom = ".".join( sources['report_module_specification'][:-1] + [os.path.basename(gscript)[:-3],] )
pycom = ".".join(os.path.relpath(instructor_grade_script, host_tmp_dir)[:-3].split("/"))
pycom = "python3 -m " + pycom
if fix_user:
user_cmd = ' --user "$(id -u):$(id -g)" '
else:
user_cmd = ''
if xvfb:
user_cmd = " -e DISPLAY=:0 -v /tmp/.X11-unix:/tmp/.X11-unix " + user_cmd
tmp_path = os.path.abspath(host_tmp_dir).replace("\\", "/")
dcom = f"docker run {user_cmd} -v {tmp_path}:/home {dockname} {pycom}"
cdcom = f"cd {os.path.dirname(Dockerfile_location)}"
fcom = f"{cdcom} && {dcom}"
print("> Running docker command")
print(fcom)
init = time.time() - start
# thtools.execute_command(fcom.split())
out = subprocess.check_output(fcom, shell=True).decode("utf-8")
host_tmp_dir +"/" + os.path.dirname(tmp_grade_file) + "/"
tokens = glob.glob( os.path.dirname(instructor_grade_script) + "/*.token" )
for t in tokens:
print("Source image produced token", t)
elapsed = time.time() - start
print("Elapsed time is", elapsed, f"({init=} seconds)")
if len(tokens) != 1:
print("Wrong number of tokens produced:", len(tokens))
print(out)
return tokens[0]
#!/bin/bash
# driver.sh - The simplest autograder we could think of. It checks
# that students can write a C program that compiles, and then
# executes with an exit status of zero.
# Usage: ./driver.sh
# Compile the code
# echo "Compiling hello3.c"
# python3 -c "print('Hello world from python 2')"
# python3 --version
python3 driver_python.py
#(make clean; make)
#status=$?
#if [ ${status} -ne 0 ]; then
# echo "Failure: Unable to compile hello3.c (return status = ${status})"
# echo "{\"scores\": {\"Correctness\": 0}}"
# exit
#fi
#
# Run the code
#echo "Running ./hello3"
#./hello3
#status=$?
#if [ ${status} -eq 0 ]; then
# echo "Success: ./hello3 runs with an exit status of 0"
# echo "{\"scores\": {\"Correctness\": 100}}"
#else
# echo "Failure: ./hello fails or returns nonzero exit status of ${status}"
# echo "{\"scores\": {\"Correctness\": 0}}"
#fi
exit
#!/bin/bash
# driver.sh - The simplest autograder we could think of. It checks
# that students can write a C program that compiles, and then
# executes with an exit status of zero.
# Usage: ./driver.sh
# Compile the code
# echo "Compiling hello3.c"
# python3 -c "print('Hello world from python 2')"
# python3 --version
python3 driver_python.py
#(make clean; make)
#status=$?
#if [ ${status} -ne 0 ]; then
# echo "Failure: Unable to compile hello3.c (return status = ${status})"
# echo "{\"scores\": {\"Correctness\": 0}}"
# exit
#fi
#
# Run the code
#echo "Running ./hello3"
#./hello3
#status=$?
#if [ ${status} -eq 0 ]; then
# echo "Success: ./hello3 runs with an exit status of 0"
# echo "{\"scores\": {\"Correctness\": 100}}"
#else
# echo "Failure: ./hello fails or returns nonzero exit status of ${status}"
# echo "{\"scores\": {\"Correctness\": 0}}"
#fi
exit
import os
import glob
import shutil
import sys
import subprocess
from unitgrade_private.autolab.autolab import format_autolab_json
from unitgrade_private.docker_helpers import student_token_file_runner
from unitgrade_private import load_token
import time
verbose = False
tag = "[driver_python.py]"
if not verbose:
print("="*10)
print(tag, "Starting unitgrade evaluation...")
sys.stderr = sys.stdout
wdir = os.getcwd()
def pfiles():
print("> Files in dir:")
for f in glob.glob(wdir + "/*"):
print(f)
print("---")
handin_filename = "Report2_handin.token"
student_token_file = 'Report2_handin.token'
instructor_grade_script = 'report2_grade.py'
grade_file_relative_destination = "cs102/report2_grade.py"
host_tmp_dir = wdir + "/tmp"
homework_file = ""
# homework_file = ""
student_should_upload_token = # Add these from template.
if not verbose:
pfiles()
print(f"{host_tmp_dir=}")
print(f"{student_token_file=}")
print(f"{instructor_grade_script=}")
command, host_tmp_dir, token = student_token_file_runner(host_tmp_dir, student_token_file, instructor_grade_script, grade_file_relative_destination)
# Alternatively. Unzip the .token file of the student (true version). Overwrite the .py file with the one uploaded, then
# run the stuff.
if not student_should_upload_token:
""" Add the student homework to the right location. """
print("Moving from", os.path.basename(handin_filename), "to", handin_filename)
print("file exists?", os.path.isfile(os.path.basename(handin_filename)))
shutil.move(os.path.basename(handin_filename), host_tmp_dir + "/" + handin_filename)
command = f"cd tmp && {command} --noprogress --autolab"
def rcom(cm):
rs = subprocess.run(cm, capture_output=True, text=True, shell=True)
print(rs.stdout)
if len(rs.stderr) > 0:
print(tag, "There were errors in executing the file:")
print(rs.stderr)
start = time.time()
rcom(command)
ls = glob.glob(token)
f = ls[0]
results, _ = load_token(ls[0])
if verbose:
print(f"{token=}")
print(results['total'])
format_autolab_json(results)
# if os.path.exists(host_tmp_dir):
# shutil.rmtree(host_tmp_dir)
# with io.BytesIO(sources['zipfile']) as zb:
# with zipfile.ZipFile(zb) as zip:
# zip.extractall(host_tmp_dir
# print("="*10)
# print('{"scores": {"Correctness": 100, "Problem 1": 4}}')
## Format the scores here.
# sc = [('Total', results['total'][0])] + [(q['title'], q['obtained']) for k, q in results['details'].items()]
# ss = ", ".join([f'"{t}": {s}' for t, s in sc])
# scores = '{"scores": {' + ss + '}}'
# print('{"_presentation": "semantic"}')
# print(scores)
import os
import glob
import shutil
import sys
import subprocess
from unitgrade_private.autolab.autolab import format_autolab_json
from unitgrade_private.docker_helpers import student_token_file_runner
from unitgrade_private import load_token
import time
verbose = False
tag = "[driver_python.py]"
if not verbose:
print("="*10)
print(tag, "Starting unitgrade evaluation...")
sys.stderr = sys.stdout
wdir = os.getcwd()
def pfiles():
print("> Files in dir:")
for f in glob.glob(wdir + "/*"):
print(f)
print("---")
handin_filename = "Report2_handin.token"
student_token_file = 'Report2_handin.token'
instructor_grade_script = 'report2_grade.py'
grade_file_relative_destination = "cs102/report2_grade.py"
host_tmp_dir = wdir + "/tmp"
homework_file = ""
# homework_file = ""
student_should_upload_token = # Add these from template.
if not verbose:
pfiles()
print(f"{host_tmp_dir=}")
print(f"{student_token_file=}")
print(f"{instructor_grade_script=}")
command, host_tmp_dir, token = student_token_file_runner(host_tmp_dir, student_token_file, instructor_grade_script, grade_file_relative_destination)
# Alternatively. Unzip the .token file of the student (true version). Overwrite the .py file with the one uploaded, then
# run the stuff.
if not student_should_upload_token:
""" Add the student homework to the right location. """
print("Moving from", os.path.basename(handin_filename), "to", handin_filename)
print("file exists?", os.path.isfile(os.path.basename(handin_filename)))
shutil.move(os.path.basename(handin_filename), host_tmp_dir + "/" + handin_filename)
command = f"cd tmp && {command} --noprogress --autolab"
def rcom(cm):
rs = subprocess.run(cm, capture_output=True, text=True, shell=True)
print(rs.stdout)
if len(rs.stderr) > 0:
print(tag, "There were errors in executing the file:")
print(rs.stderr)
start = time.time()
rcom(command)
ls = glob.glob(token)
f = ls[0]
results, _ = load_token(ls[0])
if verbose:
print(f"{token=}")
print(results['total'])
format_autolab_json(results)
# if os.path.exists(host_tmp_dir):
# shutil.rmtree(host_tmp_dir)
# with io.BytesIO(sources['zipfile']) as zb:
# with zipfile.ZipFile(zb) as zip:
# zip.extractall(host_tmp_dir
# print("="*10)
# print('{"scores": {"Correctness": 100, "Problem 1": 4}}')
## Format the scores here.
# sc = [('Total', results['total'][0])] + [(q['title'], q['obtained']) for k, q in results['details'].items()]
# ss = ", ".join([f'"{t}": {s}' for t, s in sc])
# scores = '{"scores": {' + ss + '}}'
# print('{"_presentation": "semantic"}')
# print(scores)
This diff is collapsed.
File deleted
from unitgrade_private.autolab.autolab import new_deploy_assignment from unitgrade_private.autolab.autolab import new_deploy_assignment
from unitgrade_private.docker_helpers import download_docker_images from unitgrade_private.docker_helpers import download_docker_images
from unitgrade_private.docker_helpers import compile_docker_image from unitgrade_private.docker_helpers import compile_docker_image
from unitgrade_private.autolab.autolab import format_autolab_json
if __name__ == "__main__": if __name__ == "__main__":
## Step 1. Deploy the report file. ## Step 1. Deploy the report file.
...@@ -21,9 +22,15 @@ if __name__ == "__main__": ...@@ -21,9 +22,15 @@ if __name__ == "__main__":
# Step 1: Download and compile docker grading image. You only need to do this once. #!s=a # Step 1: Download and compile docker grading image. You only need to do this once. #!s=a
download_docker_images("./docker") # Download docker images from gitlab (only do this once). download_docker_images("./docker") # Download docker images from gitlab (only do this once).
dockerfile = f"./docker/docker_tango_python/Dockerfile" dockerfile = f"./docker/docker_tango_python/Dockerfile"
autograde_image = 'tango_python_tue2' # Tag given to the image in case you have multiple images. autograde_image = 'tango_python_tue' # Tag given to the image in case you have multiple images.
compile_docker_image(Dockerfile=dockerfile, tag=autograde_image, no_cache=False) # Compile docker image. #!s compile_docker_image(Dockerfile=dockerfile, tag=autograde_image, no_cache=False) # Compile docker image. #!s
from unitgrade_private import load_token
data, _ = load_token("../02105/instructor/week2/StoneReport_handin_10_of_10.token")
# data, _ = load_token("../example_framework/students/cs102/Report2_handin_3_of_16.token")
format_autolab_json(data, indent=2)
# Step 2: Create the cs102.tar file from the grade scripts. #!s=b # Step 2: Create the cs102.tar file from the grade scripts. #!s=b
instructor_base = f"../02105/instructor/week2" instructor_base = f"../02105/instructor/week2"
student_base = "../02105/students/week2" student_base = "../02105/students/week2"
...@@ -43,7 +50,7 @@ if __name__ == "__main__": ...@@ -43,7 +50,7 @@ if __name__ == "__main__":
student_base = "../02631/students/week5" student_base = "../02631/students/week5"
# INSTRUCTOR_GRADE_FILE = # INSTRUCTOR_GRADE_FILE =
description = """ Hand in the file stones.py. You can find the full example, including solution, at https://gitlab.compute.dtu.dk/tuhe/unitgrade_private/-/tree/master/examples/02631/instructor/week5 """ description = """ Hand in the file looping.py. You can find the full example, including solution, at https://gitlab.compute.dtu.dk/tuhe/unitgrade_private/-/tree/master/examples/02631/instructor/week5 """
# description = "This is the stones-problem" # description = "This is the stones-problem"
output_tar = new_deploy_assignment("c02631week5", # Autolab name of assignment (and name of .tar file) output_tar = new_deploy_assignment("c02631week5", # Autolab name of assignment (and name of .tar file)
INSTRUCTOR_BASE=instructor_base, INSTRUCTOR_BASE=instructor_base,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment