From: W. Trevor King Date: Sun, 2 Sep 2012 18:12:15 +0000 (-0400) Subject: storage: add save_grade (useful for upcoming `grade` handler). X-Git-Tag: v0.3~5 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=c9c47a4b75a7c0a2c2b5dfb78779c3c7e945b4d2;p=pygrader.git storage: add save_grade (useful for upcoming `grade` handler). --- diff --git a/pygrader/storage.py b/pygrader/storage.py index fb618c7..34af7dc 100644 --- a/pygrader/storage.py +++ b/pygrader/storage.py @@ -341,6 +341,21 @@ def set_late(basedir, assignment, person): Lpath = _os_path.join(path, 'late') _touch(Lpath) +def save_grade(basedir, grade): + "Save a grade into a course directory" + path = assignment_path( + basedir=basedir, assignment=grade.assignment, person=grade.student) + if not _os_path.isdir(path): + _os.makedirs(path) + gpath = _os_path.join(path, 'grade') + with _io.open(gpath, 'w', encoding=_ENCODING) as f: + f.write('{}\n'.format(grade.points)) + if grade.comment: + f.write('\n{}\n'.format(grade.comment.strip())) + set_notified(basedir=basedir, grade=grade) + set_late( + basedir=basedir, assignment=grade.assignment, person=grade.student) + def _touch(path): """Touch a file (`path` is created if it doesn't already exist)