From: W. Trevor King Date: Tue, 24 Apr 2012 18:33:28 +0000 (-0400) Subject: Add Course.name attribute (for clearer email generation). X-Git-Tag: v0.2~13 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=694574e4dd12a350d2e7b7fac3bc5d3c6cc52c31;p=pygrader.git Add Course.name attribute (for clearer email generation). --- diff --git a/pygrader/model/course.py b/pygrader/model/course.py index f66493a..652592f 100644 --- a/pygrader/model/course.py +++ b/pygrader/model/course.py @@ -18,7 +18,8 @@ from .. import LOG as _LOG class Course (object): - def __init__(self, assignments=None, people=None, grades=None): + def __init__(self, name=None, assignments=None, people=None, grades=None): + self.name = name if assignments is None: assignments = [] self.assignments = sorted(assignments) diff --git a/pygrader/storage.py b/pygrader/storage.py index db02f20..7bc9a17 100644 --- a/pygrader/storage.py +++ b/pygrader/storage.py @@ -39,9 +39,24 @@ _DATE_REGEXP = _re.compile('^([^T]*)(T?)([^TZ+-.]*)([.]?[0-9]*)([+-][0-9:]*|Z?)$ def load_course(basedir): + """Load a course directory. + + >>> from pygrader.test.course import StubCourse + >>> stub_course = StubCourse(load=False) + >>> course = load_course(basedir=stub_course.basedir) + >>> course.name + 'phys101' + >>> course.assignments # doctest: +ELLIPSIS + [, ...] + >>> course.people # doctest: +ELLIPSIS + [, ...] + >>> course.grades + [] + """ _LOG.debug('loading course from {}'.format(basedir)) config = _configparser.ConfigParser() config.read([_os_path.join(basedir, 'course.conf')]) + name = config.get('course', 'name') names = {} for option in ['assignments', 'professors', 'assistants', 'students']: names[option] = [ @@ -66,7 +81,8 @@ def load_course(basedir): people[person].groups = [group] people = people.values() grades = list(load_grades(basedir, assignments, people)) - return _Course(assignments=assignments, people=people, grades=grades) + return _Course( + name=name, assignments=assignments, people=people, grades=grades) def parse_date(string): """Parse dates given using the W3C DTF profile of ISO 8601. diff --git a/pygrader/test/course.py b/pygrader/test/course.py index 98da559..2f1379f 100644 --- a/pygrader/test/course.py +++ b/pygrader/test/course.py @@ -10,6 +10,7 @@ from pygrader.storage import load_course as _load_course COURSE_CONF = """ [course] +name: phys101 assignments: Attendance 1, Attendance 2, Attendance 3, Attendance 4, Attendance 5, Attendance 6, Attendance 7, Attendance 8, Attendance 9, Assignment 1, Assignment 2, Exam 1, Exam 2 @@ -113,14 +114,15 @@ class StubCourse (object): course.conf >>> course.cleanup() """ - def __init__(self): + def __init__(self, load=True): self.basedir = _tempfile.mkdtemp(prefix='pygrader-tmp-') try: self.mailbox = _os_path.join(self.basedir, 'mail') course_conf = _os_path.join(self.basedir, 'course.conf') with open(course_conf, 'w') as f: f.write(COURSE_CONF) - self.course = _load_course(basedir=self.basedir) + if load: + self.course = _load_course(basedir=self.basedir) except Exception: self.cleanup() diff --git a/test/course.conf b/test/course.conf index 744e96c..93999ca 100644 --- a/test/course.conf +++ b/test/course.conf @@ -1,4 +1,5 @@ [course] +name: phys101 assignments: Attendance 1, Attendance 2, Attendance 3, Attendance 4, Attendance 5, Attendance 6, Attendance 7, Attendance 8, Attendance 9, Assignment 1, Assignment 2, Exam 1, Exam 2