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
File added
File added
File added
File added
# from cs202courseware.ug2report1 import Report1 # from cs202courseware.ug2report1 import Report1
import thtools # import thtools
import pickle import pickle
import os import os
import glob import glob
...@@ -12,6 +11,87 @@ import time ...@@ -12,6 +11,87 @@ import time
import zipfile import zipfile
import io 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): def docker_run_token_file(Dockerfile_location, host_tmp_dir, student_token_file, ReportClass=None, instructor_grade_script=None):
""" """
This thingy works: This thingy works:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment