From 02e298e63c06a1ec9c0e3ab86f31e7845b39ed21 Mon Sep 17 00:00:00 2001 From: Ian Stuart Date: Wed, 2 Oct 2024 16:07:20 +0100 Subject: [PATCH] Improve the information output, to match upstream nbgrader --- nbexchange/plugin/collect.py | 2 +- nbexchange/plugin/exchange.py | 3 ++- nbexchange/plugin/fetch_assignment.py | 5 +++-- nbexchange/plugin/fetch_feedback.py | 8 +++----- nbexchange/plugin/list.py | 16 +++++++++++++++- nbexchange/plugin/release_assignment.py | 4 +++- nbexchange/plugin/submit.py | 12 ++++++++---- nbexchange/tests/test_plugin_submit.py | 1 + 8 files changed, 36 insertions(+), 15 deletions(-) diff --git a/nbexchange/plugin/collect.py b/nbexchange/plugin/collect.py index d4e8ed5f..79a4e5e7 100644 --- a/nbexchange/plugin/collect.py +++ b/nbexchange/plugin/collect.py @@ -96,7 +96,7 @@ def do_collect(self): f"No submissions of '{self.coursedir.assignment_id}' for course '{self.coursedir.course_id}' to collect" ) else: - self.log.debug( + self.log.info( f"Processing {len(submissions)} submissions of '{self.coursedir.assignment_id}' for course '{self.coursedir.course_id}'" # noqa: E501 ) diff --git a/nbexchange/plugin/exchange.py b/nbexchange/plugin/exchange.py index f998f118..d1dda387 100644 --- a/nbexchange/plugin/exchange.py +++ b/nbexchange/plugin/exchange.py @@ -88,7 +88,8 @@ def do_copy(self, src, dest): def start(self): self.log.debug(f"Called start on {self.__class__.__name__}") - + self.set_timestamp() + self.log.info(f"timetamp: {self.timestamp}") if self.coursedir and not self.coursedir.course_id: self.coursedir.course_id = self.course_id diff --git a/nbexchange/plugin/fetch_assignment.py b/nbexchange/plugin/fetch_assignment.py index 41e90722..4aed5b25 100644 --- a/nbexchange/plugin/fetch_assignment.py +++ b/nbexchange/plugin/fetch_assignment.py @@ -131,6 +131,7 @@ def do_copy(self, src, dest): def copy_files(self): self.log.debug(f"Source: {self.src_path}") - self.log.debug(f"Destination: {self.dest_path}") + self.log.info("Source: The exhange service") + self.log.info(f"Destination: {self.dest_path}") self.do_copy(self.src_path, self.dest_path) - self.log.debug(f"Fetched as: {self.coursedir.course_id} {self.coursedir.assignment_id}") + self.log.info(f"Fetched as: {self.coursedir.course_id} {self.coursedir.assignment_id}") diff --git a/nbexchange/plugin/fetch_feedback.py b/nbexchange/plugin/fetch_feedback.py index 4d3d972b..ba1a3269 100644 --- a/nbexchange/plugin/fetch_feedback.py +++ b/nbexchange/plugin/fetch_feedback.py @@ -34,7 +34,7 @@ def download(self): # Feedback, here, is the time the feedback was generated, not the time of the submission if "feedback" in content: for f in content["feedback"]: - self.log.debug(f"##### fetch-feedback.download has {f['filename']}, {f['timestamp']}") + self.log.debug(f"fetch-feedback.download has {f['filename']}, {f['timestamp']}") try: # This matches nb_timestamp in list.parse_assignments, "status" == "submitted" # The format should match the nbgrader default "%Y-%m-%d %H:%M:%S.%f %Z" @@ -45,9 +45,7 @@ def download(self): # ) timestamp = f["timestamp"] os.makedirs(os.path.join(self.dest_path, timestamp), exist_ok=True) - self.log.debug( - f"##### fetch-feedback.download writing to {os.path.join(self.dest_path, timestamp)}" - ) + self.log.info(f"Downloading feedback to {os.path.join(self.dest_path, timestamp)}") with open(os.path.join(self.dest_path, timestamp, f["filename"]), "wb") as handle: handle.write(base64.b64decode(f["content"])) except Exception as e: # TODO: exception handling @@ -56,6 +54,6 @@ def download(self): self.fail(content.get("note", "could not get feedback")) def copy_files(self): - self.log.debug(f"Destination: {self.dest_path}") + self.log.info(f"Destination: {self.dest_path}") self.download() self.log.debug(f"Fetched as: {self.coursedir.notebook_id}") diff --git a/nbexchange/plugin/list.py b/nbexchange/plugin/list.py index 2f5f90df..36ef1399 100644 --- a/nbexchange/plugin/list.py +++ b/nbexchange/plugin/list.py @@ -4,6 +4,7 @@ from urllib.parse import quote_plus import nbgrader.exchange.abc as abc +from nbgrader.exchange.default.list import ExchangeList as DefaultExchangeList from traitlets import Unicode from .exchange import Exchange @@ -13,6 +14,7 @@ # "inbound" is files submitted by students (on external service) # "cached" is files submitted by students & collected by instructors (so on local disk) class ExchangeList(abc.ExchangeList, Exchange): + def do_copy(self, src, dest): pass @@ -291,17 +293,29 @@ def list_files(self): self.log.debug("ExchaneList.list_file starting") assignments = self.parse_assignments() + if self.inbound or self.cached: + self.log.info("Submitted assignments:") + for assignment in assignments: + for info in assignment["submissions"]: + self.log.info(DefaultExchangeList.format_inbound_assignment(self, info)) + else: + self.log.info("Released assignments:") + for info in assignments: + self.log.info(DefaultExchangeList.format_outbound_assignment(self, info)) return assignments def remove_files(self): if self.coursedir.course_id: """Delete assignment""" + self.log.info( + f"Unreleasing assignment_id {self.coursedir.assignment_id} on course code {self.coursedir.course_id}" + ) url = f"assignment?course_id={quote_plus(self.coursedir.course_id)}&assignment_id={quote_plus(self.coursedir.assignment_id)}" # noqa: E501 r = self.api_request(url, method="DELETE") - self.log.debug(f"Got back {r.status_code} after assignment unrelease") + self.log.info(f"Got back {r.status_code} after assignment unrelease") def start(self): ##### diff --git a/nbexchange/plugin/release_assignment.py b/nbexchange/plugin/release_assignment.py index a4a6e8f3..4023aa49 100644 --- a/nbexchange/plugin/release_assignment.py +++ b/nbexchange/plugin/release_assignment.py @@ -70,6 +70,8 @@ def get_notebooks(self): def upload(self, file): files = {"assignment": ("assignment.tar.gz", file)} + self.log.info(f"Source: {self.src_path}") + self.log.info("Destination: The exhange service") url = f"assignment?course_id={quote_plus(self.coursedir.course_id)}&assignment_id={quote_plus(self.coursedir.assignment_id)}" # noqa: E501 @@ -84,7 +86,7 @@ def upload(self, file): if not data["success"]: self.fail(data["note"]) - self.log.info("Successfully uploaded released assignment.") + self.log.info(f"Released as: {self.coursedir.course_id} {self.coursedir.assignment_id}") def copy_files(self): # Grab files from hard drive diff --git a/nbexchange/plugin/submit.py b/nbexchange/plugin/submit.py index 874cb4bc..f49fe472 100644 --- a/nbexchange/plugin/submit.py +++ b/nbexchange/plugin/submit.py @@ -3,14 +3,14 @@ import sys from urllib.parse import quote_plus -import nbgrader.exchange.abc as abc +from nbgrader.exchange.abc import ExchangeSubmit as ABCExchangeSubmit from nbgrader.utils import find_all_notebooks from .exchange import Exchange from .list import ExchangeList -class ExchangeSubmit(abc.ExchangeSubmit, Exchange): +class ExchangeSubmit(Exchange, ABCExchangeSubmit): def do_copy(self, src, dest): pass @@ -34,9 +34,8 @@ def tar_source(self): import tarfile import time from contextlib import closing - from datetime import datetime - timestamp = datetime.now().strftime(self.timestamp_format).strip() + timestamp = self.timestamp tar_file = io.BytesIO() with tarfile.open(fileobj=tar_file, mode="w:gz") as tar_handle: tar_handle.add(self.src_path, arcname=".") @@ -50,6 +49,9 @@ def tar_source(self): def upload(self, file): self.log.debug(f"ExchangeSubmit uploading to: {self.service_url()}") + self.log.info(f"Source: {self.src_path}") + self.log.info("Destination: The exhange service") + files = {"assignment": ("assignment.tar.gz", file)} r = self.api_request( f"submission?course_id={quote_plus(self.coursedir.course_id)}&assignment_id={quote_plus(self.coursedir.assignment_id)}", # noqa: E501 @@ -61,6 +63,8 @@ def upload(self, file): if not data["success"]: self.fail(data["note"]) + self.log.info(f"Submitted as: {self.coursedir.course_id} {self.coursedir.assignment_id} {self.timestamp}") + # Like the default Submit, we log differences, and do not rener then in the display # (not sure that's any ues to anyone - but that's what the original does) def check_filename_diff(self): diff --git a/nbexchange/tests/test_plugin_submit.py b/nbexchange/tests/test_plugin_submit.py index 15865bf9..4afb5fd7 100644 --- a/nbexchange/tests/test_plugin_submit.py +++ b/nbexchange/tests/test_plugin_submit.py @@ -47,6 +47,7 @@ def test_submit_methods(plugin_config, tmpdir, caplog): ) plugin = ExchangeSubmit(coursedir=CourseDirectory(config=plugin_config), config=plugin_config) + plugin.set_timestamp() plugin.init_src() assert re.search(r"nbexchange/assign_1_1$", plugin.src_path) plugin.init_dest()