def main(): filter1 = Filter.Filter() (parsed, assignment, xls, addOutput, addFile, goldenSource) = Parse_Args(filter1) (service, drive) = Open_Classroom() if (parsed): assignmentSelected = Verify_Assignment(service, assignment) if (assignmentSelected != None): tempPath = RunJavaUtils.Create_Temp_Dir() goldenLines = [] if (goldenSource != None): (success, author, package, className, goldenLines) = RunJavaUtils.Copy_And_Run_Java_File( tempPath, goldenSource, None) if (success == False): print("Build failure for golden source") return writer = ExcelWriter.ExcelWriter(xls) Copy_Student_Java_Files(tempPath, service, drive, assignmentSelected, writer, addOutput, addFile, goldenLines, filter1) # files = Create_File_List(studentDir) # RunJavaUtils.Copy_And_Run_Files(studentDir, files, tempPath, writer, addOutput, addFile, goldenLines) writer.Close() RunJavaUtils.Clean_And_Remove_Temp_Dir(tempPath)
def Check_Each_Base(goldenDir, tempPath, baseNames, studentDir, csvName): goldenSources = Find_Files(goldenDir, baseNames) studentFiles = Find_Files(studentDir, baseNames) csv=open(csvName, "w") for baseName in baseNames: goldenSource = goldenDir + "\\" + goldenSources[baseName][0] (success, author, package, className, goldenLines) = RunJavaUtils.Copy_And_Run_Java_File(tempPath, goldenSource) if (success == False): print("!!!!!Build failure for golden source" + goldenSources[baseName][0]) csv.close() return RunJavaUtils.Copy_And_Run_Files(studentDir, studentFiles[baseName], tempPath, csv, True, True, goldenLines) goldenLines=[] csv.close()
def main(): (parsed, studentDir, csv, addOutput, addFile, golden_source) = Parse_Args() if (parsed): tempPath = RunJavaUtils.Create_Temp_Dir() goldenLines = [] if (golden_source != None): (success, _, _, _, goldenLines) = RunJavaUtils.Copy_And_Run_Java_File( tempPath, golden_source, None) if (success == False): print("Build failure for golden source") return writer = ExcelWriter.ExcelWriter(csv) files = Create_File_List(studentDir) RunJavaUtils.Copy_And_Run_Files(studentDir, files, tempPath, writer, addOutput, addFile, goldenLines) writer.Create_Excel_File() RunJavaUtils.Clean_And_Remove_Temp_Dir(tempPath)
def main(): filter1 = Filter.Filter() args = Parse_Args(filter1) (service, drive) = Open_Classroom(args) assignmentSelected = Verify_Assignment(service, args.assignment) if assignmentSelected: tempPath = RunJavaUtils.Create_Temp_Dir() goldenLines = [] if args.golden_source is not None: (success, author, package, className, goldenLines) = RunJavaUtils.Copy_And_Run_Java_File( tempPath, args.golden_source, None) if (success == False): print("Build failure for golden source") return writer = ExcelWriter.ExcelWriter(args.xlsx) Copy_Student_Java_Files(tempPath, service, drive, assignmentSelected, writer, args.output, args.file, goldenLines, filter1) # files = Create_File_List(studentDir) # RunJavaUtils.Copy_And_Run_Files(studentDir, files, tempPath, writer, addOutput, addFile, goldenLines) writer.Create_Excel_File() RunJavaUtils.Clean_And_Remove_Temp_Dir(tempPath)
def Copy_Student_Java_Files(tempDir, service, drive, assignmentSelected, excelWriter, addOutput, addFile, goldLines, filter1): RunJavaUtils.Create_Header(excelWriter, addOutput, addFile, goldLines) studentSubmissions = service.courses().courseWork().studentSubmissions() submissions_for_sslected_assignment = studentSubmissions.list( courseId=courseId, courseWorkId=assignmentSelected['id']).execute() (studentNameList, studentIDToNameMap) = Sort_Student_Names( service.courses().students().list(courseId=courseId).execute()) # we will create a map of list of submissions - sorted by name, init the map submissionList = {} for student in studentNameList: submissionList[student] = [] # now fill in the map for submission in submissions_for_sslected_assignment[ 'studentSubmissions']: studentId = submission['userId'] submissionList[studentIDToNameMap[studentId]].append(submission) # finally, walk through each student alphabetically, and get all the submission from that student for student in studentNameList: for submission in submissionList[student]: studentId = submission['userId'] studentProfile = service.userProfiles().get( userId=studentId).execute() studentName = studentProfile['name'][ 'familyName'] + ", " + studentProfile['name']['givenName'] filtered = [] updated = False print(studentName) assignmentSub = submission['assignmentSubmission'] if ('attachments') in assignmentSub: for singleAssignment in assignmentSub['attachments']: if 'driveFile' in singleAssignment: driveFile = singleAssignment['driveFile'] if ('alternateLink') in driveFile: fileName = driveFile['title'] if (".java" in fileName): if (filter1.Filter_On_File_Name_Only() == False or filter1.Use_File( fileName, [], False)): className = fileName.replace(".java", "") txtName = fileName + ".txt" tempName = os.path.join(tempDir, txtName) print("Downloading to " + tempName) outFile = io.FileIO(tempName, mode='wb') fileID = driveFile['id'] try: request = drive.files().get_media( fileId=fileID) downloader = http.MediaIoBaseDownload( outFile, request, chunksize=CHUNK_SIZE) download_finished = False while download_finished is False: _, download_finished = downloader.next_chunk( ) print("Download complete") ( success, ignore1, package, ignore2, output ) = RunJavaUtils.Copy_And_Run_Java_File( tempDir, tempName, className) except Exception as e: success = False package = "" output = [ "could not download file: " + str(e) ] if (filter1.Use_File( fileName, output, success)): if (success): RunJavaUtils.Append_Run_Data( str(success), success, studentName, package, className, output, tempName, excelWriter, addOutput, addFile, goldLines) updated = True else: RunJavaUtils.Append_Run_Data( str(success), success, studentName, package, className, output, tempName, excelWriter, addOutput, addFile, goldLines) updated = True else: print("Filtered out: " + fileName + " base on name") filtered.append(fileName) if (updated == False): ranLine = "missing" if (len(filtered)): ranLine = ranLine + " filtered out these files: " + str( filtered) RunJavaUtils.Append_Run_Data(ranLine, False, studentName, "missing", "", [""], "", excelWriter, addOutput, addFile, goldLines)
def main(): (parsed, baseNames, goldenDir, studentDir, csvName) = Parse_Args() if (parsed): tempPath = RunJavaUtils.Create_Temp_Dir() Check_Each_Base(goldenDir, tempPath, baseNames, studentDir, csvName) RunJavaUtils.Clean_And_Remove_Temp_Dir(tempPath)