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

updates

parent d3b39e1e
No related branches found
No related tags found
No related merge requests found
Showing
with 471 additions and 0 deletions
"""
cd ~/Autolab && bundle exec rails s -p 8000 --binding=0.0.0.0
To remove my shitty image:
docker rmi tango_python_tue
"""
from zipfile import ZipFile
import os
from os.path import basename
import os
import shutil
from jinja2 import Environment, FileSystemLoader
import glob
COURSES_BASE = "/home/tuhe/Autolab/courses/AutoPopulated"
TEMPLATE_BASE = "/home/tuhe/Documents/unitgrade_private/autolab/lab_template"
CURDIR = os.path.dirname(__file__)
def jj(source, dest, data):
if os.path.exists(dest) and os.path.samefile(source, dest):
raise Exception()
dir, f = os.path.split(source)
file_loader = FileSystemLoader(dir)
env = Environment(loader=file_loader)
output = env.get_template(f).render(data)
with open(dest, 'w') as f:
f.write(output)
return output
def docker_build_image():
os.system("cd docker_tango_python && docker build --tag tango_python_tue .")
pass
def jj_handout(source, dest, data):
out = jj(source, dest, data)
shutil.copy(dest, dest+"-handout")
return out
def zipFilesInDir(dirName, zipFileName, filter):
# create a ZipFile object
with ZipFile(zipFileName, 'w') as zipObj:
# Iterate over all the files in directory
for folderName, subfolders, filenames in os.walk(dirName):
for filename in filenames:
if filter(filename):
# create complete filepath of file in directory
filePath = os.path.join(folderName, filename)
# Add file to zip
zipObj.write(filePath, basename(filePath))
def deploy_assignment(base_name):
docker_build_image()
# Ok so what should go on here?
LAB_DEST = os.path.join(COURSES_BASE, base_name)
STUDENT_HANDOUT_DIR = "/home/tuhe/Documents/unitgrade_private/examples/example_simplest/students/cs101"
INSTRUCTOR_GRADE_FILE = "/home/tuhe/Documents/unitgrade_private/examples/example_simplest/instructor/cs101/report1_grade.py"
# STUDENT_TOKEN_FILE = "/home/tuhe/Documents/unitgrade_private/examples/example_simplest/students/cs101"
from cs101.report1 import Report1 # The instructors report class.
StudentReportClass = Report1.__qualname__ + "_handin.token"
import inspect
# inspect.getfile(Report1.pack_imports[0])
m = Report1.pack_imports[0]
root, relative = Report1()._import_base_relative()
z = 234
# Quickly make student .token file to upload:
# os.system(f"cd {os.path.dirname(STUDENT_HANDOUT_DIR)} && python -m cs101.{os.path.basename(INSTRUCTOR_GRADE_FILE)[:-3]}")
os.system(f"cd {STUDENT_HANDOUT_DIR} && python {os.path.basename(INSTRUCTOR_GRADE_FILE)}")
STUDENT_TOKEN_FILE = glob.glob(STUDENT_HANDOUT_DIR + "/*.token")[0]
tname = os.path.basename(STUDENT_TOKEN_FILE)
for _ in range(3):
tname = tname[:tname.rfind("_")]
tname += ".token"
print("> Name of handin file", tname)
# Take student handout and unzip it.
# Take student token file, unzip it and merge files.
# This is the directory which is going to be handed out.
if os.path.exists(LAB_DEST):
shutil.rmtree(LAB_DEST)
os.mkdir(LAB_DEST)
assert os.path.exists(TEMPLATE_BASE)
# Make the handout directory.
# Start in the src directory. You should make the handout files first.
# jj("a", "b", data={})
src_dest = LAB_DEST + "/src"
# src_source = TEMPLATE_BASE + "/src"
os.mkdir(src_dest)
# unitgrade-docker
from unitgrade_private2 import docker_helpers
data = {
'base_name': base_name,
'nice_name': base_name + "please",
# 'autograde_image': 'autograde_image',
'autograde_image': 'tango_python_tue',
'src_files_to_handout': ['driver_python.py','student_sources.zip', tname, os.path.basename(docker_helpers.__file__),
os.path.basename(INSTRUCTOR_GRADE_FILE)], # Remove tname later; it is the upload.
'handin_filename': 'hello3.c', # the student token file.
'student_token_file': tname,
'instructor_grade_file': os.path.basename(INSTRUCTOR_GRADE_FILE),
'grade_file_relative_destination': relative,
}
# shutil.copyfile(TEMPLATE_BASE + "/hello.yml", f"{LAB_DEST}/{base_name}.yml")
jj_handout(TEMPLATE_BASE + "/src/README", LAB_DEST + "/src/README", data)
jj_handout(TEMPLATE_BASE + "/src/driver_python.py", LAB_DEST + "/src/driver_python.py", data)
jj_handout(TEMPLATE_BASE + "/src/hello.c", LAB_DEST + "/src/hello3.c",data)
jj_handout(TEMPLATE_BASE + "/src/Makefile", LAB_DEST + "/src/Makefile",data)
jj_handout(TEMPLATE_BASE + "/src/driver.sh", LAB_DEST + "/src/driver.sh",data)
jj(TEMPLATE_BASE + "/Makefile", LAB_DEST + "/Makefile", data)
shutil.copyfile(TEMPLATE_BASE + "/hello.yml", f"{LAB_DEST}/{base_name}.yml")
shutil.copyfile(TEMPLATE_BASE + "/autograde-Makefile", LAB_DEST + "/autograde-Makefile")
jj(TEMPLATE_BASE + "/hello.yml", f"{LAB_DEST}/{base_name}.yml", data=data)
jj(TEMPLATE_BASE + "/hello.rb", f"{LAB_DEST}/{base_name}.rb", data=data)
# Copy the student grade file to remove.
shutil.copyfile(INSTRUCTOR_GRADE_FILE, f"{LAB_DEST}/src/{os.path.basename(INSTRUCTOR_GRADE_FILE)}")
shutil.copyfile(STUDENT_TOKEN_FILE, f"{LAB_DEST}/src/{os.path.basename(STUDENT_TOKEN_FILE)}")
shutil.copyfile(STUDENT_TOKEN_FILE, f"{LAB_DEST}/src/{tname}")
# zipFilesInDir(STUDENT_HANDOUT_DIR, LAB_DEST + '/student_sources.zip', lambda name: True)
# Make a zip file of all the students (handed out) sources.
shutil.make_archive(LAB_DEST + '/src/student_sources', 'zip', root_dir=os.path.dirname(STUDENT_HANDOUT_DIR), base_dir='cs101')
# Take the (student) .token file and unpack sources into the student_sources.zip directory.
# docker_helpers
shutil.copyfile(docker_helpers.__file__, f"{LAB_DEST}/src/{os.path.basename(docker_helpers.__file__)}")
os.mkdir(LAB_DEST +"/handin")
os.mkdir(LAB_DEST +"/test-autograder") # Otherwise make clean will screw up.
os.system(f"cd {LAB_DEST} && make && cd {CURDIR}")
print("Deploy", base_name)
if __name__ == "__main__":
# print("Hello there handsome")
print("Deploying to", COURSES_BASE)
deploy_assignment("hello3")
# syntax=docker/dockerfile:1
FROM python:3.8-slim-buster
MAINTAINER Autolab Team <autolab-dev@andrew.cmu.edu>
RUN apt-get update && apt-get install -y \
build-essential \
gcc \
git \
make \
sudo \
python \
procps \
&& rm -rf /var/lib/apt/lists/*
# Install autodriver
WORKDIR /home
RUN useradd autolab
RUN useradd autograde
RUN mkdir autolab autograde output
RUN chown autolab:autolab autolab
RUN chown autolab:autolab output
RUN chown autograde:autograde autograde
RUN git clone --depth 1 https://github.com/autolab/Tango.git
WORKDIR Tango/autodriver
RUN make clean && make
RUN cp autodriver /usr/bin/autodriver
RUN chmod +s /usr/bin/autodriver
# Do the python stuff.
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
# Clean up
WORKDIR /home
RUN apt-get remove -y git && apt-get -y autoremove && rm -rf Tango/
# Check installation
RUN ls -l /home
RUN which autodriver
numpy
tqdm
jinja2
tabulate
compress_pickle
pyfiglet
#
# Makefile to manage the example Hello Lab
#
# Get the name of the lab directory
LAB = $(notdir $(PWD))
all: handout handout-tarfile
handout:
# Rebuild the handout directory that students download
(rm -rf $(LAB)-handout; mkdir $(LAB)-handout)
cp -p src/Makefile-handout $(LAB)-handout/Makefile
cp -p src/README-handout $(LAB)-handout/README
cp -p src/hello3.c-handout $(LAB)-handout/hello3.c
cp -p src/driver.sh $(LAB)-handout
{%- for f in src_files_to_handout %}
cp -p src/{{f}} $(LAB)-handout
{% endfor %}
handout-tarfile: handout
# Build *-handout.tar and autograde.tar
tar cvf $(LAB)-handout.tar $(LAB)-handout
cp -p $(LAB)-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 $(LAB)-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 xvf autograde.tar
cp hello3.c hello3-handout
(cd hello3-handout; sh driver.sh)
clean:
rm -rf *~ hello3-handout
File added
require "AssessmentBase.rb"
module Hello3
include AssessmentBase
def assessmentInitialize(course)
super("hello3",course)
@problems = []
end
end
---
general:
name: {{ base_name }}
description: ''
display_name: Hello3
handin_filename: hello3.c
handin_directory: handin
max_grace_days: 0
handout: hello3-handout.tar
writeup: writeup/hello3.html
max_submissions: -1
disable_handins: false
max_size: 2
has_svn: false
category_name: Lab
problems:
- name: Correctness
description: ''
max_score: 100.0
optional: false
autograder:
autograde_timeout: 180
autograde_image: {{ autograde_image }}
release_score: true
#
# Makefile to manage the example Hello Lab
#
# Get the name of the lab directory
LAB = $(notdir $(PWD))
all: handout handout-tarfile
handout:
# Rebuild the handout directory that students download
(rm -rf $(LAB)-handout; mkdir $(LAB)-handout)
cp -p src/Makefile-handout $(LAB)-handout/Makefile
cp -p src/README-handout $(LAB)-handout/README
cp -p src/hello.c-handout $(LAB)-handout/hello.c
cp -p src/driver.sh $(LAB)-handout
handout-tarfile: handout
# Build *-handout.tar and autograde.tar
tar cvf $(LAB)-handout.tar $(LAB)-handout
cp -p $(LAB)-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 $(LAB)-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/*
This is an example of the simplest possible autograded lab, called "hello." It uses
the recommended file format that we've found helpful in the past.
To build the lab:
linux> make clean
linux> make
To test offline:
linux> cd test-autograder
linux> make clean
linux> make
# Basic files created by the lab author
Makefile Builds the lab from src/
README
autograde-Makefile Makefile that runs the autograder
src/ Contains all src files and solutions
test-autograder/ For testing autograder offline
writeup/ Lab writeup that students view from Autolab
# Files created by running make
hello-handout/ The directory that is handed out to students, created
using files from src/.
hello-handout.tar Archive of hello-handout directory
autograde.tar File that is copied to the autograding instance
(along with autograde-Makefile and student handin file)
# Files created and managed by Autolab
handin/ All students handin files
hello.rb Config file
hello.yml Database properties that persist from semester to semester
log.txt Log of autograded submissions
all:
tar xvf autograde.tar
cp hello.c hello-handout
(cd hello-handout; ./driver.sh)
clean:
rm -rf *~ hello-handout
File added
File added
# Student makefile for the Hello Lab
all:
gcc hello.c -o hello
clean:
rm -rf *~ hello
For this lab, you should write a tiny C program, called "hello.c",
that prints "hello, world" to stdout and then indicates success by
exiting with a status of zero.
To test your work:
linux> make clean; make; ./hello
To run the same autograder that Autolab will use when you submit:
linux> ./driver.sh
Files:
README This file
Makefile Compiles hello.c
driver.sh Autolab autograder
hello.c Empty C file that you will edit
#!/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 hello.c"
(make clean; make)
status=$?
if [ ${status} -ne 0 ]; then
echo "Failure: Unable to compile hello.c (return status = ${status})"
echo "{\"scores\": {\"Correctness\": 0}}"
exit
fi
# Run the code
echo "Running ./hello"
./hello
status=$?
if [ ${status} -eq 0 ]; then
echo "Success: ./hello 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
/*
* Hello Lab
*/
require "AssessmentBase.rb"
module Hello
include AssessmentBase
def assessmentInitialize(course)
super("hello",course)
@problems = []
end
end
---
general:
name: hello
description: ''
display_name: Hello
handin_filename: hello.c
handin_directory: handin
max_grace_days: 0
handout: hello-handout.tar
writeup: writeup/hello.html
max_submissions: -1
disable_handins: false
max_size: 2
has_svn: false
category_name: Lab
problems:
- name: Correctness
description: ''
max_score: 100.0
optional: false
autograder:
autograde_timeout: 180
autograde_image: autograding_image
release_score: true
# Makefile for the Hello Lab
all:
gcc hello.c -o hello
clean:
rm -rf *~ hello
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment