From: W. Trevor King Date: Sun, 2 Sep 2012 18:10:48 +0000 (-0400) Subject: storage: split load_grade out from load_grades. X-Git-Tag: v0.3~6 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d81b77c1f81cde4ca142c4dc2503a7eabd4a75cd;p=pygrader.git 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. --- 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: