From 5890e02585b630d12bf32d872b53986743234087 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 24 Apr 2012 15:27:08 -0400 Subject: [PATCH] Add Course.robot attribute (for automatic email generation). I'm getting things set up to send automatic responses when mailpipe processes incoming email, which means someone's going to have to be signing that email for security. Since you probably don't want to leave your secret PGP key on the mailserver, you can now setup a new (and less important) PGP key for each course. The Course.robot is just a Person instance to hold that key and an appropriate nickname. If you want to use your own key when you call pg.py from the command line, you can always setup a shell alias. In Bash: alias pg.py='/usr/bin/pg.py --author="John Doe"' --- bin/pg.py | 5 ++--- pygrader/model/course.py | 4 +++- pygrader/storage.py | 10 +++++++--- pygrader/test/course.py | 6 ++++++ test/course.conf | 6 ++++++ 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/bin/pg.py b/bin/pg.py index 163f43d..5980b01 100755 --- a/bin/pg.py +++ b/bin/pg.py @@ -89,7 +89,7 @@ if __name__ == '__main__': help="Don't actually send emails, create files, etc.") email_parser.add_argument( '-a', '--author', - help='Your name (email author), defaults to first assistant') + help='Your name (email author), defaults to course robot') email_parser.add_argument( '--cc', action='append', help='People to carbon copy') email_subparsers = email_parser.add_subparsers(title='type') @@ -178,8 +178,7 @@ if __name__ == '__main__': if hasattr(args, attr): name = getattr(args, attr) if name is None and attr == 'author': - kwargs[attr] = list( - course.find_people(group='assistants'))[0] + kwargs[attr] = course.robot else: kwargs[attr] = course.person(name=name) for attr in ['targets']: diff --git a/pygrader/model/course.py b/pygrader/model/course.py index 652592f..559be78 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, name=None, assignments=None, people=None, grades=None): + def __init__(self, name=None, assignments=None, people=None, grades=None, + robot=None): self.name = name if assignments is None: assignments = [] @@ -29,6 +30,7 @@ class Course (object): if grades is None: grades = [] self.grades = sorted(grades) + self.robot = robot def assignment(self, name): for assignment in self.assignments: diff --git a/pygrader/storage.py b/pygrader/storage.py index 7bc9a17..2b1e185 100644 --- a/pygrader/storage.py +++ b/pygrader/storage.py @@ -52,12 +52,14 @@ def load_course(basedir): [, ...] >>> course.grades [] + >>> print(course.robot) + """ _LOG.debug('loading course from {}'.format(basedir)) config = _configparser.ConfigParser() config.read([_os_path.join(basedir, 'course.conf')]) name = config.get('course', 'name') - names = {} + names = {'robot': [config.get('course', 'robot').strip()]} for option in ['assignments', 'professors', 'assistants', 'students']: names[option] = [ a.strip() for a in config.get('course', option).split(',')] @@ -67,7 +69,7 @@ def load_course(basedir): assignments.append(load_assignment( name=assignment, data=dict(config.items(assignment)))) people = {} - for group in ['professors', 'assistants', 'students']: + for group in ['robot', 'professors', 'assistants', 'students']: for person in names[group]: if person in people: _LOG.debug('adding person {} to group {}'.format( @@ -80,9 +82,11 @@ def load_course(basedir): name=person, data=dict(config.items(person))) people[person].groups = [group] people = people.values() + robot = [p for p in people if 'robot' in p.groups][0] grades = list(load_grades(basedir, assignments, people)) return _Course( - name=name, assignments=assignments, people=people, grades=grades) + name=name, assignments=assignments, people=people, grades=grades, + robot=robot) 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 2f1379f..1c6e780 100644 --- a/pygrader/test/course.py +++ b/pygrader/test/course.py @@ -14,6 +14,7 @@ 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 +robot: Robot101 professors: Gandalf assistants: Sauron students: Bilbo Baggins, Frodo Baggins, Aragorn @@ -83,6 +84,11 @@ points: 10 weight: 0.4/2 due: 2011-10-17 +[Robot101] +nickname: phys-101 robot +emails: phys101@tower.edu +pgp-key: 4332B6E3 + [Gandalf] nickname: G-Man emails: g@grey.edu diff --git a/test/course.conf b/test/course.conf index 93999ca..375de45 100644 --- a/test/course.conf +++ b/test/course.conf @@ -3,6 +3,7 @@ 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 +robot: Robot101 professors: Gandalf assistants: Sauron students: Bilbo Baggins, Frodo Baggins, Aragorn @@ -72,6 +73,11 @@ points: 10 weight: 0.4/2 due: 2011-10-17 +[Robot101] +nickname: phys101 robot +emails: phys101@tower.edu +pgp-key: 4332B6E3 + [Gandalf] nickname: G-Man emails: g@grey.edu -- 2.26.2