From d81b77c1f81cde4ca142c4dc2503a7eabd4a75cd Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 2 Sep 2012 14:10:48 -0400 Subject: [PATCH] storage: split load_grade out from load_grades. Also rename _load_grade to parse_grade. These functions will be useful in the upcoming `grade` handler. --- pygrader/storage.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/pygrader/storage.py b/pygrader/storage.py index ad5cc29..fb618c7 100644 --- a/pygrader/storage.py +++ b/pygrader/storage.py @@ -281,26 +281,32 @@ def load_person(name, data={}): return _Person(name=name, **kwargs) def load_grades(basedir, assignments, people): + "Load all grades in a course directory." for assignment in assignments: for person in people: - _LOG.debug('loading {} grade for {}'.format(assignment, person)) - path = assignment_path(basedir, assignment, person) - gpath = _os_path.join(path, 'grade') try: - g = _load_grade(_io.open(gpath, 'r', encoding=_ENCODING), - assignment, person) + yield load_grade(basedir, assignment, person) except IOError: continue - #g.late = _os.stat(gpath).st_mtime > assignment.due - g.late = _os_path.exists(_os_path.join(path, 'late')) - npath = _os_path.join(path, 'notified') - if _os_path.exists(npath): - g.notified = newer(npath, gpath) - else: - g.notified = False - yield g -def _load_grade(stream, assignment, person): +def load_grade(basedir, assignment, person): + "Load a single grade from a course directory." + _LOG.debug('loading {} grade for {}'.format(assignment, person)) + path = assignment_path(basedir, assignment, person) + gpath = _os_path.join(path, 'grade') + g = parse_grade(_io.open(gpath, 'r', encoding=_ENCODING), + assignment, person) + #g.late = _os.stat(gpath).st_mtime > assignment.due + g.late = _os_path.exists(_os_path.join(path, 'late')) + npath = _os_path.join(path, 'notified') + if _os_path.exists(npath): + g.notified = newer(npath, gpath) + else: + g.notified = False + return g + +def parse_grade(stream, assignment, person): + "Parse the points and comment from a grade stream." try: points = float(stream.readline()) except ValueError: -- 2.26.2