|
1 | 1 | import os |
2 | 2 | import shutil |
3 | | -import glob |
4 | | -import re |
5 | 3 | from stat import S_IRUSR, S_IWUSR, S_IXUSR, S_IRGRP, S_IWGRP, S_IXGRP, S_IXOTH, S_ISGID |
6 | 4 |
|
7 | 5 | from nbgrader.exchange.abc import ExchangeReleaseFeedback as ABCExchangeReleaseFeedback |
8 | 6 | from .exchange import Exchange |
9 | | -from nbgrader.utils import notebook_hash, make_unique_key |
| 7 | +from nbgrader.utils import notebook_hash |
10 | 8 |
|
11 | 9 |
|
12 | 10 | class ExchangeReleaseFeedback(Exchange, ABCExchangeReleaseFeedback): |
@@ -37,40 +35,37 @@ def copy_files(self): |
37 | 35 | else: |
38 | 36 | exclude_students = set() |
39 | 37 |
|
40 | | - html_files = glob.glob(os.path.join(self.src_path, "*.html")) |
41 | | - for html_file in html_files: |
42 | | - regexp = re.escape(os.path.sep).join([ |
43 | | - self.coursedir.format_path( |
44 | | - self.coursedir.feedback_directory, |
45 | | - "(?P<student_id>.*)", |
46 | | - self.coursedir.assignment_id, escape=True), |
47 | | - "(?P<notebook_id>.*).html" |
48 | | - ]) |
49 | | - |
50 | | - m = re.match(regexp, html_file) |
51 | | - if m is None: |
52 | | - msg = "Could not match '%s' with regexp '%s'" % (html_file, regexp) |
53 | | - self.log.error(msg) |
54 | | - continue |
55 | | - |
56 | | - gd = m.groupdict() |
57 | | - student_id = gd['student_id'] |
58 | | - notebook_id = gd['notebook_id'] |
| 38 | + for feedback in self.coursedir.find_notebooks( |
| 39 | + nbgrader_step=self.coursedir.feedback_directory, |
| 40 | + student_id=self.coursedir.student_id or "*", |
| 41 | + assignment_id=self.coursedir.assignment_id, |
| 42 | + notebook_id="*", |
| 43 | + ext="html" |
| 44 | + ): |
| 45 | + html_file = feedback['path'] |
| 46 | + student_id = feedback['student_id'] |
59 | 47 | if student_id in exclude_students: |
60 | 48 | self.log.debug("Skipping student '{}'".format(student_id)) |
61 | 49 | continue |
62 | 50 |
|
63 | | - feedback_dir = os.path.split(html_file)[0] |
| 51 | + notebook_id = feedback['notebook_id'] |
| 52 | + feedback_dir = html_file.parent |
64 | 53 |
|
65 | | - timestamp = open(os.path.join(feedback_dir, 'timestamp.txt')).read() |
66 | | - with open(os.path.join(feedback_dir, "submission_secret.txt")) as fh: |
67 | | - submission_secret = fh.read() |
| 54 | + timestamp = feedback_dir.joinpath('timestamp.txt').read_text() |
| 55 | + submission_secret = feedback_dir.joinpath("submission_secret.txt").read_text() |
68 | 56 |
|
69 | 57 | checksum = notebook_hash(secret=submission_secret, notebook_id=notebook_id) |
70 | 58 | dest = os.path.join(self.dest_path, "{}-tmp.html".format(checksum)) |
71 | 59 |
|
72 | | - self.log.info("Releasing feedback for student '{}' on assignment '{}/{}/{}' ({})".format( |
73 | | - student_id, self.coursedir.course_id, self.coursedir.assignment_id, notebook_id, timestamp)) |
| 60 | + self.log.info( |
| 61 | + "Releasing feedback for student '%s' on assignment '%s/%s/%s' (%s)", |
| 62 | + student_id, |
| 63 | + self.coursedir.course_id, |
| 64 | + feedback["assignment_id"], |
| 65 | + notebook_id, |
| 66 | + timestamp |
| 67 | + ) |
| 68 | + |
74 | 69 | shutil.copy(html_file, dest) |
75 | 70 | # Copy to temporary location and mv to update atomically. |
76 | 71 | updated_feedback = os.path.join(self.dest_path, "{}.html". format(checksum)) |
|
0 commit comments