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

updates

parent bafbf14b
No related branches found
No related tags found
No related merge requests found
Showing
with 1187 additions and 1 deletion
......@@ -13,4 +13,3 @@ hello.c Solution hello.c file
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
File added
# from cs202courseware.ug2report1 import Report1
# import thtools
import pickle
import os
import glob
# from unitgrade_private2.deployment import remove_hidden_methods
# from unitgrade_private2.hidden_gather_upload import gather_upload_to_campusnet
# from unitgrade_private2.hidden_create_files import setup_grade_file_report
import shutil
import time
import zipfile
import io
def student_token_file_runner(host_tmp_dir, student_token_file, instructor_grade_script, grade_file_relative_destination):
"""
:param Dockerfile_location:
:param host_tmp_dir:
:param student_token_file:
:param ReportClass:
:param instructor_grade_script:
:return:
"""
# assert os.path.exists(Dockerfile_location)
start = time.time()
with open(student_token_file, 'rb') as f:
results = pickle.load(f)
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.
import inspect
# if ReportClass is not None:
# gscript = inspect.getfile(ReportClass)[:-3] + "_grade.py"
# else:
gscript = instructor_grade_script
print(f"{sources['report_relative_location']=}")
print(f"{sources['name']=}")
# student_grade_script = host_tmp_dir + "/" + sources['name'] + "/" + sources['report_relative_location']
# instructor_grade_script = os.path.dirname(student_grade_script) + "/" + os.path.basename(gscript)
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!.
# import thtools
# os.path.split()
d = os.path.normpath(grade_file_relative_destination).split(os.sep)
d = d[:-1] + [os.path.basename(instructor_grade_script)[:-3]]
# print(f'{d=}')
pycom = ".".join(d)
"""
docker run -v c:/Users/tuhe/Documents/2021/python-docker/tmp:/app python-docker python3 -m cs202courseware.ug2report1_grade
"""
# dockname = os.path.basename(os.path.dirname(Dockerfile_location))
# tmp_grade_file = sources['name'] + "/" + sources['report_relative_location']
# print(f'{tmp_grade_file=}')
# pycom = ".".join((sources['name'],) + os.path.split(sources['report_relative_location'])[1:-1] + (os.path.basename(gscript),))
pycom = "python3 -m " + pycom # pycom[:-3]
print(f"{pycom=}")
# tmp_path = os.path.abspath(host_tmp_dir).replace("\\", "/")
# dcom = f"docker run -v {tmp_path}:/app {dockname} {pycom}"
# cdcom = f"cd {os.path.dirname(Dockerfile_location)}"
# fcom = f"{cdcom} && {dcom}"
# print("> Running docker command")
# print(fcom)
# thtools.execute_command(fcom.split())
# get token file:
token_location = host_tmp_dir + "/" + os.path.dirname( grade_file_relative_destination ) + "/*.token"
# host_tmp_dir + "/" + os.path.dirname(tmp_grade_file) + "/"
# tokens = glob.glob(host_tmp_dir + "/" + os.path.dirname(tmp_grade_file) + "/*.token")
# token_location = host_tmp_dir + "/" + os.path.dirname(tmp_grade_file)
# for t in tokens:
# print("Source image produced token", t)
elapsed = time.time() - start
# print("Elapsed time is", elapsed)
return pycom, token_location
pass
def docker_run_token_file(Dockerfile_location, host_tmp_dir, student_token_file, ReportClass=None, instructor_grade_script=None):
"""
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
"""
# A bunch of tests. This is going to be great!
assert os.path.exists(Dockerfile_location)
start = time.time()
with open(student_token_file, 'rb') as f:
results = pickle.load(f)
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.
import inspect
if ReportClass is not None:
gscript = inspect.getfile(ReportClass)[:-3] + "_grade.py"
else:
gscript = instructor_grade_script
student_grade_script = host_tmp_dir + "/" + sources['name'] + "/" + sources['report_relative_location']
instructor_grade_script = os.path.dirname(student_grade_script) + "/"+os.path.basename(gscript)
shutil.copy(gscript, instructor_grade_script)
# Now everything appears very close to being set up and ready to roll!.
import thtools
"""
docker run -v c:/Users/tuhe/Documents/2021/python-docker/tmp:/app python-docker python3 -m cs202courseware.ug2report1_grade
"""
dockname = os.path.basename( os.path.dirname(Dockerfile_location) )
tmp_grade_file = sources['name'] + "/" + sources['report_relative_location']
pycom = ".".join( (sources['name'], ) + os.path.split(sources['report_relative_location'])[1:-1] + (os.path.basename(gscript),) )
pycom = "python3 -m " + pycom[:-3]
tmp_path = os.path.abspath(host_tmp_dir).replace("\\", "/")
dcom = f"docker run -v {tmp_path}:/app {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())
# get token file:
host_tmp_dir +"/" + os.path.dirname(tmp_grade_file) + "/"
tokens = glob.glob(host_tmp_dir +"/" + os.path.dirname(tmp_grade_file) + "/*.token" )
for t in tokens:
print("Source image produced token", t)
elapsed = time.time() - start
print("Elapsed time is", elapsed, f"({init=} seconds)")
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 sys
import pickle
# import io
import subprocess
import docker_helpers
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("---")
student_token_file = 'Report1_handin.token'
instructor_grade_script = 'report1_grade.py'
grade_file_relative_destination = "cs101\report1_grade.py"
with open(student_token_file, 'rb') as f:
results = pickle.load(f)
sources = results['sources'][0]
host_tmp_dir = wdir + "/tmp"
if not verbose:
pfiles()
print(f"{host_tmp_dir=}")
print(f"{student_token_file=}")
print(f"{instructor_grade_script=}")
command, token = docker_helpers.student_token_file_runner(host_tmp_dir, student_token_file, instructor_grade_script, grade_file_relative_destination)
command = f"cd tmp && {command} --noprogress --autolab"
def rcom(cm):
# print(f"running... ", cm)
# start = time.time()
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)
# print(rs)
# print("result of running command was", rs.stdout, "err", rs.stderr, "time", time.time() - start)
start = time.time()
rcom(command)
# pfiles()
# for f in glob.glob(host_tmp_dir + "/cs101/*"):
# print("cs101/", f)
# print("---")
ls = glob.glob(token)
# print(ls)
f = ls[0]
with open(f, 'rb') as f:
results = pickle.load(f)
# print("results")
# print(results.keys())
if verbose:
print(f"{token=}")
print(results['total'])
# 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}}')
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)
\ No newline at end of file
import os
import glob
import sys
import pickle
# import io
import subprocess
import docker_helpers
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("---")
student_token_file = 'Report1_handin.token'
instructor_grade_script = 'report1_grade.py'
grade_file_relative_destination = "cs101\report1_grade.py"
with open(student_token_file, 'rb') as f:
results = pickle.load(f)
sources = results['sources'][0]
host_tmp_dir = wdir + "/tmp"
if not verbose:
pfiles()
print(f"{host_tmp_dir=}")
print(f"{student_token_file=}")
print(f"{instructor_grade_script=}")
command, token = docker_helpers.student_token_file_runner(host_tmp_dir, student_token_file, instructor_grade_script, grade_file_relative_destination)
command = f"cd tmp && {command} --noprogress --autolab"
def rcom(cm):
# print(f"running... ", cm)
# start = time.time()
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)
# print(rs)
# print("result of running command was", rs.stdout, "err", rs.stderr, "time", time.time() - start)
start = time.time()
rcom(command)
# pfiles()
# for f in glob.glob(host_tmp_dir + "/cs101/*"):
# print("cs101/", f)
# print("---")
ls = glob.glob(token)
# print(ls)
f = ls[0]
with open(f, 'rb') as f:
results = pickle.load(f)
# print("results")
# print(results.keys())
if verbose:
print(f"{token=}")
print(results['total'])
# 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}}')
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)
\ No newline at end of file
This diff is collapsed.
File added
#
# Makefile to manage the example Hello Lab
#
# Get the name of the lab directory
# LAB = $(notdir $(PWD)) # Fail on windows for some reason...
all: handout handout-tarfile
handout:
# Rebuild the handout directory that students download
(rm -rf cs102-handout; mkdir cs102-handout)
cp -p src/Makefile-handout cs102-handout/Makefile
cp -p src/README-handout cs102-handout/README
cp -p src/driver_python.py cs102-handout
cp -p src/student_sources.zip cs102-handout
cp -p src/Report2_handin.token cs102-handout
cp -p src/docker_helpers.py cs102-handout
cp -p src/report2_grade.py cs102-handout
handout-tarfile: handout
# Build *-handout.tar and autograde.tar
tar cvf cs102-handout.tar cs102-handout
cp -p cs102-handout.tar autograde.tar
clean:
# Clean the entire lab directory tree. Note that you can run
# "make clean; make" at any time while the lab is live with no
# adverse effects.
rm -f *~ *.tar
(cd src; make clean)
(cd test-autograder; make clean)
rm -rf cs102-handout
rm -f autograde.tar
#
# CAREFULL!!! This will delete all student records in the logfile and
# in the handin directory. Don't run this once the lab has started.
# Use it to clean the directory when you are starting a new version
# of the lab from scratch, or when you are debugging the lab prior
# to releasing it to the students.
#
cleanallfiles:
# Reset the lab from scratch.
make clean
rm -f log.txt
rm -rf handin/*
all:
tar xf autograde.tar
cp Report2_handin.token cs102-handout
(cd cs102-handout; python3 driver_python.py)
clean:
rm -rf *~ hello3-handout
\ No newline at end of file
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 101 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: Total
description: ''
max_score: 18
optional: false
- name: The first question for week 1.
description: ''
max_score: 10
optional: true
- name: Second problem
description: ''
max_score: 8
optional: true
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
File added
# from cs202courseware.ug2report1 import Report1
# import thtools
import pickle
import os
import glob
# from unitgrade_private2.deployment import remove_hidden_methods
# from unitgrade_private2.hidden_gather_upload import gather_upload_to_campusnet
# from unitgrade_private2.hidden_create_files import setup_grade_file_report
import shutil
import time
import zipfile
import io
def student_token_file_runner(host_tmp_dir, student_token_file, instructor_grade_script, grade_file_relative_destination):
"""
:param Dockerfile_location:
:param host_tmp_dir:
:param student_token_file:
:param ReportClass:
:param instructor_grade_script:
:return:
"""
# assert os.path.exists(Dockerfile_location)
start = time.time()
with open(student_token_file, 'rb') as f:
results = pickle.load(f)
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.
import inspect
# if ReportClass is not None:
# gscript = inspect.getfile(ReportClass)[:-3] + "_grade.py"
# else:
gscript = instructor_grade_script
print(f"{sources['report_relative_location']=}")
print(f"{sources['name']=}")
# student_grade_script = host_tmp_dir + "/" + sources['name'] + "/" + sources['report_relative_location']
# instructor_grade_script = os.path.dirname(student_grade_script) + "/" + os.path.basename(gscript)
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!.
# import thtools
# os.path.split()
d = os.path.normpath(grade_file_relative_destination).split(os.sep)
d = d[:-1] + [os.path.basename(instructor_grade_script)[:-3]]
# print(f'{d=}')
pycom = ".".join(d)
"""
docker run -v c:/Users/tuhe/Documents/2021/python-docker/tmp:/app python-docker python3 -m cs202courseware.ug2report1_grade
"""
# dockname = os.path.basename(os.path.dirname(Dockerfile_location))
# tmp_grade_file = sources['name'] + "/" + sources['report_relative_location']
# print(f'{tmp_grade_file=}')
# pycom = ".".join((sources['name'],) + os.path.split(sources['report_relative_location'])[1:-1] + (os.path.basename(gscript),))
pycom = "python3 -m " + pycom # pycom[:-3]
print(f"{pycom=}")
# tmp_path = os.path.abspath(host_tmp_dir).replace("\\", "/")
# dcom = f"docker run -v {tmp_path}:/app {dockname} {pycom}"
# cdcom = f"cd {os.path.dirname(Dockerfile_location)}"
# fcom = f"{cdcom} && {dcom}"
# print("> Running docker command")
# print(fcom)
# thtools.execute_command(fcom.split())
# get token file:
token_location = host_tmp_dir + "/" + os.path.dirname( grade_file_relative_destination ) + "/*.token"
# host_tmp_dir + "/" + os.path.dirname(tmp_grade_file) + "/"
# tokens = glob.glob(host_tmp_dir + "/" + os.path.dirname(tmp_grade_file) + "/*.token")
# token_location = host_tmp_dir + "/" + os.path.dirname(tmp_grade_file)
# for t in tokens:
# print("Source image produced token", t)
elapsed = time.time() - start
# print("Elapsed time is", elapsed)
return pycom, token_location
pass
def docker_run_token_file(Dockerfile_location, host_tmp_dir, student_token_file, ReportClass=None, instructor_grade_script=None):
"""
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
"""
# A bunch of tests. This is going to be great!
assert os.path.exists(Dockerfile_location)
start = time.time()
with open(student_token_file, 'rb') as f:
results = pickle.load(f)
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.
import inspect
if ReportClass is not None:
gscript = inspect.getfile(ReportClass)[:-3] + "_grade.py"
else:
gscript = instructor_grade_script
student_grade_script = host_tmp_dir + "/" + sources['name'] + "/" + sources['report_relative_location']
instructor_grade_script = os.path.dirname(student_grade_script) + "/"+os.path.basename(gscript)
shutil.copy(gscript, instructor_grade_script)
# Now everything appears very close to being set up and ready to roll!.
import thtools
"""
docker run -v c:/Users/tuhe/Documents/2021/python-docker/tmp:/app python-docker python3 -m cs202courseware.ug2report1_grade
"""
dockname = os.path.basename( os.path.dirname(Dockerfile_location) )
tmp_grade_file = sources['name'] + "/" + sources['report_relative_location']
pycom = ".".join( (sources['name'], ) + os.path.split(sources['report_relative_location'])[1:-1] + (os.path.basename(gscript),) )
pycom = "python3 -m " + pycom[:-3]
tmp_path = os.path.abspath(host_tmp_dir).replace("\\", "/")
dcom = f"docker run -v {tmp_path}:/app {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())
# get token file:
host_tmp_dir +"/" + os.path.dirname(tmp_grade_file) + "/"
tokens = glob.glob(host_tmp_dir +"/" + os.path.dirname(tmp_grade_file) + "/*.token" )
for t in tokens:
print("Source image produced token", t)
elapsed = time.time() - start
print("Elapsed time is", elapsed, f"({init=} seconds)")
return tokens[0]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment