From 4e218b3c10fe61f5bc9a83183bd584927e37b1ec Mon Sep 17 00:00:00 2001 From: jwansek Date: Sat, 22 Jan 2022 20:34:02 +0000 Subject: worked on handling and showing exceptions in client clode --- mark.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'mark.py') diff --git a/mark.py b/mark.py index 9c0ec6b..2630be1 100644 --- a/mark.py +++ b/mark.py @@ -1,3 +1,4 @@ +from dataclasses import dataclass import jinja_helpers import configparser import argparse @@ -5,10 +6,36 @@ import tempfile import zipfile import reflect import jinja2 +import shutil import yaml import json import os +@dataclass +class FileDependencies: + assessment_struct:dict + + def __enter__(self): + try: + for file_dep in self.assessment_struct["dependencies"]["files"]: + if os.path.isfile(file_dep): + shutil.copy(file_dep, os.path.split(file_dep)[-1]) + else: + shutil.copytree(file_dep, os.path.split(file_dep)[-1]) + # print("%s --> %s" % (file_dep, os.path.join(os.getcwd(), os.path.split(file_dep)[-1]))) + except KeyError: + pass + + def __exit__(self, type, value, traceback): + try: + for file_dep in self.assessment_struct["dependencies"]["files"]: + if os.path.isfile(os.path.split(file_dep)[-1]): + os.remove(os.path.split(file_dep)[-1]) + else: + shutil.rmtree(os.path.split(file_dep)[-1]) + except KeyError: + pass + def main(**kwargs): student_no = os.path.splitext(os.path.split(args["submission"])[-1])[0] @@ -27,7 +54,8 @@ def main(**kwargs): with open(kwargs["assessment"], "r") as f: assessment_struct = yaml.safe_load(f) - output = reflect.gen_reflection_report(submission_files, assessment_struct, student_no, kwargs) + with FileDependencies(assessment_struct): + output = reflect.gen_reflection_report(submission_files, assessment_struct, student_no, kwargs) output_file = kwargs["out"] if kwargs["format"] == "yaml": -- cgit v1.2.3