def get_storagedir_contents(courseId, assignmentId, account): """Get the content of a the archive coresponding to a MD5Submission-type homework""" client = paramiko.SSHClient() try: vmcfg = StorerCourseConfig(CourseList().course_config(courseId)) assignments = vmcfg.assignments() storage_hostname = assignments.get(assignmentId, 'AssignmentStorageHost') storage_username = assignments.get(assignmentId, 'AssignmentStorageQueryUser') storage_basepath = assignments.storage_basepath( \ assignments.get(assignmentId, 'AssignmentStorageBasepath') , account) client.load_system_host_keys(vmcfg.known_hosts_file()) client.connect(storage_hostname, username=storage_username, key_filename=vmcfg.storer_sshid(), look_for_keys=False) cmd = "find " + storage_basepath + '/' + account + \ " \( ! -regex '.*/\..*' \) -type f" stdin, stdout, stderr = client.exec_command(cmd) result = [] for d in stdout.readlines(): result.append({'fileName' : d}) for f in [stdin, stdout, stderr]: f.close() return json.dumps(result) except: strout = OutputString() traceback.print_exc(file = strout) return json.dumps({'errorTrace' : strout.get()}, indent=4) finally: client.close()
def get_storagedir_contents(courseId, assignmentId, account): """Get the content of a the archive coresponding to a MD5Submission-type homework""" client = paramiko.SSHClient() try: vmcfg = StorerCourseConfig(CourseList().course_config(courseId)) assignments = vmcfg.assignments() storage_hostname = assignments.get(assignmentId, 'AssignmentStorageHost') storage_username = assignments.get(assignmentId, 'AssignmentStorageQueryUser') storage_basepath = assignments.storage_basepath( \ assignments.get(assignmentId, 'AssignmentStorageBasepath') , account) client.load_system_host_keys(vmcfg.known_hosts_file()) client.connect(storage_hostname, username=storage_username, key_filename=vmcfg.storer_sshid(), look_for_keys=False) cmd = "find " + storage_basepath + '/' + account + \ " \( ! -regex '.*/\..*' \) -type f" stdin, stdout, stderr = client.exec_command(cmd) result = [] for d in stdout.readlines(): result.append({'fileName': d}) for f in [stdin, stdout, stderr]: f.close() return json.dumps(result) except: strout = OutputString() traceback.print_exc(file=strout) return json.dumps({'errorTrace': strout.get()}, indent=4) finally: client.close()
def validate_md5_submission(courseId, assignmentId, account, archiveFileName): """Checks whether a MD5Submission is valid: * checks that the uploaded md5 corresponds to the one of the machine * checks that the archive uploaded by the student is a zip file On success returns (True,). On failure reports the source of the failure: - (False, 'md5') - the uploaded md5 does not match the one computed on the archive - (False, 'zip') - the uploaded archive is not zip. """ md5_calculated = "" md5_uploaded = "" archive_file_type = "" client = paramiko.SSHClient() try: vmcfg = StorerCourseConfig(CourseList().course_config(courseId)) assignments = vmcfg.assignments() storage_hostname = assignments.get(assignmentId, 'AssignmentStorageHost') storage_username = assignments.get(assignmentId, 'AssignmentStorageQueryUser') storage_basepath = assignments.storage_basepath( \ assignments.get(assignmentId, 'AssignmentStorageBasepath'), account) client.load_system_host_keys(vmcfg.known_hosts_file()) client.connect(storage_hostname, username=storage_username, key_filename=vmcfg.storer_sshid(), look_for_keys=False) archive_abs = os.path.join(storage_basepath, account, archiveFileName) # XXX: This will take ages to compute! I wonder how many # connections will Apache hold. stdin, stdout, stderr = client.exec_command("md5sum " + QuoteForPOSIX(archive_abs)) md5_calculated = stdout.readline().split()[0] for f in [stdin, stdout, stderr]: f.close() stdin, stdout, stderr = client.exec_command("file " + QuoteForPOSIX(archive_abs)) archive_file_type = stdout.readline()[len(archive_abs):].split()[1].lower() for f in [stdin, stdout, stderr]: f.close() vmpaths = paths.VmcheckerPaths(vmcfg.root_path()) submission_dir = vmpaths.dir_cur_submission_root(assignmentId, account) md5_fpath = paths.submission_md5_file(submission_dir) if os.path.isfile(md5_fpath): with open(md5_fpath, 'r') as f: md5_uploaded = f.read(32) except: strout = OutputString() traceback.print_exc(file = strout) return json.dumps({'errorTrace' : strout.get()}, indent=4) finally: client.close() if not md5_calculated == md5_uploaded: return (False, MD5_ERR_BAD_MD5) # report the type of the problem if not archive_file_type == "zip": return (False, MD5_ERR_BAD_ZIP) # report the type of the problem return (True,) # no problemo
def validate_md5_submission(courseId, assignmentId, account, archiveFileName): """Checks whether a MD5Submission is valid: * checks that the uploaded md5 corresponds to the one of the machine * checks that the archive uploaded by the student is a zip file On success returns (True,). On failure reports the source of the failure: - (False, 'md5') - the uploaded md5 does not match the one computed on the archive - (False, 'zip') - the uploaded archive is not zip. """ md5_calculated = "" md5_uploaded = "" archive_file_type = "" client = paramiko.SSHClient() try: vmcfg = StorerCourseConfig(CourseList().course_config(courseId)) assignments = vmcfg.assignments() storage_hostname = assignments.get(assignmentId, 'AssignmentStorageHost') storage_username = assignments.get(assignmentId, 'AssignmentStorageQueryUser') storage_basepath = assignments.storage_basepath( \ assignments.get(assignmentId, 'AssignmentStorageBasepath'), account) client.load_system_host_keys(vmcfg.known_hosts_file()) client.connect(storage_hostname, username=storage_username, key_filename=vmcfg.storer_sshid(), look_for_keys=False) archive_abs = os.path.join(storage_basepath, account, archiveFileName) # XXX: This will take ages to compute! I wonder how many # connections will Apache hold. stdin, stdout, stderr = client.exec_command("md5sum " + QuoteForPOSIX(archive_abs)) md5_calculated = stdout.readline().split()[0] for f in [stdin, stdout, stderr]: f.close() stdin, stdout, stderr = client.exec_command("file " + QuoteForPOSIX(archive_abs)) archive_file_type = stdout.readline()[len(archive_abs):].split( )[1].lower() for f in [stdin, stdout, stderr]: f.close() vmpaths = paths.VmcheckerPaths(vmcfg.root_path()) submission_dir = vmpaths.dir_cur_submission_root(assignmentId, account) md5_fpath = paths.submission_md5_file(submission_dir) if os.path.isfile(md5_fpath): with open(md5_fpath, 'r') as f: md5_uploaded = f.read(32) except: strout = OutputString() traceback.print_exc(file=strout) return json.dumps({'errorTrace': strout.get()}, indent=4) finally: client.close() if not md5_calculated == md5_uploaded: return (False, MD5_ERR_BAD_MD5) # report the type of the problem if not archive_file_type == "zip": return (False, MD5_ERR_BAD_ZIP) # report the type of the problem return (True, ) # no problemo