storage: split load_grade out from load_grades.
authorW. Trevor King <wking@tremily.us>
Sun, 2 Sep 2012 18:10:48 +0000 (14:10 -0400)
committerW. Trevor King <wking@tremily.us>
Sun, 2 Sep 2012 18:27:48 +0000 (14:27 -0400)
Also rename _load_grade to parse_grade.

These functions will be useful in the upcoming `grade` handler.

pygrader/storage.py

index ad5cc2909c942b8c3745a7de78f31bc31f2af82b..fb618c78930bae7bc457dbf92ab1120c4a1b3e82 100644 (file)
@@ -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: