def check_filename_diff(self): released_notebooks = find_all_notebooks(self.release_path) submitted_notebooks = find_all_notebooks(self.src_path) # Look for missing notebooks in submitted notebooks missing = False release_diff = list() for filename in released_notebooks: if filename in submitted_notebooks: release_diff.append("{}: {}".format(filename, 'FOUND')) else: missing = True release_diff.append("{}: {}".format(filename, 'MISSING')) # Look for extra notebooks in submitted notebooks extra = False submitted_diff = list() for filename in submitted_notebooks: if filename in released_notebooks: submitted_diff.append("{}: {}".format(filename, 'OK')) else: extra = True submitted_diff.append("{}: {}".format(filename, 'EXTRA')) if missing or extra: diff_msg = ( "Expected:\n\t{}\nSubmitted:\n\t{}".format( '\n\t'.join(release_diff), '\n\t'.join(submitted_diff), ) ) if missing and self.strict: self.fail( "Assignment {} not submitted. " "There are missing notebooks for the submission:\n{}" "".format(self.coursedir.assignment_id, diff_msg) ) else: self.log.warning( "Possible missing notebooks and/or extra notebooks " "submitted for assignment {}:\n{}" "".format(self.coursedir.assignment_id, diff_msg) )
def check_filename_diff(self): # List of filenames, no paths released_notebooks = [] assignments = ExchangeList.query_exchange(self) latest_timestamp = "1990-01-01 00:00:00" for assignment in assignments: # We want the last released version of this assignments if self.coursedir.assignment_id == assignment[ "assignment_id"] and assignment.get( "status") == "released": if assignment.get("timestamp") > latest_timestamp: latest_timestamp = assignment.get("timestamp") released_notebooks = [ n["notebook_id"] + ".ipynb" for n in assignment["notebooks"] if "notebook_id" in n ] else: continue submitted_notebooks = find_all_notebooks(self.src_path) # Now look for missing notebooks in submitted notebooks missing = False release_diff = list() for filename in released_notebooks: if filename in submitted_notebooks: release_diff.append("{}: {}".format(filename, "FOUND")) else: missing = True release_diff.append("{}: {}".format(filename, "MISSING")) # Look for extra notebooks in submitted notebooks extra = False submitted_diff = list() for filename in submitted_notebooks: if filename in released_notebooks: submitted_diff.append("{}: {}".format(filename, "OK")) else: extra = True submitted_diff.append("{}: {}".format(filename, "EXTRA")) if missing or extra: diff_msg = "Expected:\n\t{}\nSubmitted:\n\t{}".format( "\n\t".join(release_diff), "\n\t".join(submitted_diff)) if missing and self.strict: self.fail("Assignment {} not submitted. " "There are missing notebooks for the submission:\n{}" "".format(self.coursedir.assignment_id, diff_msg)) else: self.log.warning( "Possible missing notebooks and/or extra notebooks " "submitted for assignment {}:\n{}" "".format(self.coursedir.assignment_id, diff_msg))
def _generate_launch_url(self) -> 'str': """ Generate assignment links for assigned assignments. This will search your instructors repository for the source assignment and then generate the link to the student copy of the assignment. :return: The full launch URL including the nbgitpuller next parameter. :rtype: str """ # Given an assignment name, look in that assignment's folder and pull out # the notebook path. #! Blindly take the first result! notebook = nbutils.find_all_notebooks( os.path.join(self.course.working_directory, 'source', self.name))[0] # Construct launch url for nbgitpuller # First join our hub url, hub prefix, and launch url launch_url = f"{self.course.hub_url}{self.course.hub_prefix}/hub/lti/launch" # Then construct our nbgitpuller custom next parameter gitpuller_url = f"{self.course.hub_prefix}/hub/user-redirect/git-pull" # Finally, urlencode our repository and add that repo_encoded_url = urlparse.quote_plus(self.course.stu_launch_url) # Finally glue this all together!! Now we just need to add the subpath for each assignment launch_url_without_subpath = fr"{launch_url}?custom_next={gitpuller_url}%3Frepo%3D{repo_encoded_url}%26subPath%3D" # urlencode the assignment's subpath subpath = urlparse.quote_plus( f"{self.course.assignment_release_path}/{notebook}") # and join it to the previously constructed launch URL (hub + nbgitpuller language) full_launch_url = launch_url_without_subpath + subpath return full_launch_url