#!/usr/bin/python from collections import deque import sys,os,pwd ##################################################################### # This script joins the student's files into one file. The graders # find it convenient to have one file that contains the autotest # results and all the student's code. That way, they don't have to # switch from file to file while marking. # # Last Revised By: Nick Lee (yc2lee) on December 21, 2011 # # # assn_name: The assignment number or assignment name. assn_name = '06' # # file_list: List of files the students are expected to submit. file_list = [ 'a06q1.rkt', 'a06q2.rkt', 'a06q3.rkt', 'a06q4.rkt' ] # # assn_folder: The name of the assignment's folder in handin. assn_folder = 'a06' # # autotest_folder: The name of the folder created by RST. autotest_folder = 'test.1.AUTOTESTRESULTS' # # output_filename: The name of the output file. output_filename = 'GRADED_ASSIGNMENT.py' # # ########################################################## students_with_no_autotest = [] # Arguments: # assign_nbr: a string containing the assignment number # quest_id: a string containing the student's Quest ID # autotest_results: a string containing the path to the autotest results OUTPUT.txt # files: A list of strings. The strings are the files to include. It's OK if # the list contains files that don't actually exist. # Returned Value: # A deque containing the contents of the GRADED_ASSIGNMENT.* file def MakeGradedAssignment(assign_nbr, quest_id, autotest_results, files): answer = deque() ## Include a little header information answer.append("ASSIGNMENT %s\n" % assign_nbr) answer.append("Student's Quest ID: %s\n\n" % quest_id) ## Print the student's autotest results printing_test_results = False if os.path.isfile(autotest_results): f = file(autotest_results, "r") for line in f.readlines(): if line.startswith("****"): printing_test_results = True answer.append(line) elif printing_test_results: if line.startswith("**** ") and ("Output comparison for" not in line): break answer.append(line) f.close() else: students_with_no_autotest.append([quest_id, autotest_results]) answer.append("\n\n") ## Print the files that the students are supposed to hand in for fname in files: if "GRADED_ASSIGNMENT." in fname: continue answer.append("**** %s *****************************************************************\n" % fname.split('/')[-1]) if fname.endswith('.rkt'): # for .rkt files, also check .ss and .scm, which RST accepts root = fname[:fname.rindex('.rkt')] for extension in ['.rkt', '.ss', '.scm']: fname = root + extension if os.path.isfile(fname): f = file(fname, "r") for line in f.readlines(): answer.append(line) f.close() break; elif os.path.isfile(fname): f = file(fname, "r") for line in f.readlines(): answer.append(line) f.close() answer.append("\n\n") answer.append("**** End of graded assignment. *************************************************\n") return answer def PrintHelp(): print "You can use this script to create %s for every student, or just one student." % output_filename print print "1) To create for every student:" print " Set the five variables at the top of the script." print " Then run this script with no arguments: python MakeGradedAssignment.py" print " The script will create %s file for all the students" % output_filename print print "2) To create for one student:" print " Run this script like this:" print " python MakeGradedAssignment.py assign_nbr quest_id autotest_results file1 file2 ... filen" print "\tassign_nbr: The assignment number. Ex: 06" print "\tquest_id: The student's Quest ID. Ex: jsmith" print "\tautotest_results: Path to OUTPUT.txt file produced by RST" print "\tfile1 file2 ... filen: Path to the student's files. Ex: a06q1.rkt a06q2.rkt a06q3.rkt" print " When run like this, the script will ignore the variables set" print " in the script, and instead use the arguments provided. The" print " output will be printed to the screen. No files will be created" print " or modified." print print "Note: If you enter .rkt files, the script will first try to find the" print " exact file you entered. If it cannot find the file, it will try" print " the .ss and .scm extensions." print # # SCRIPT STARTS HERE!!!!!!!!!!!!!!!!!!!!!!!!!! # course = pwd.getpwuid(os.getuid())[0] argc = len(sys.argv) if argc == 1: # Create graded assignment file for every student assn_handin = '/u/%s/handin/%s/' % (course, assn_folder) assn_marking = '/u/%s/marking/%s/%s/' % (course, assn_folder, autotest_folder) students = filter(lambda s: '.' not in s, os.listdir(assn_handin)) students_len = len(students) print "Creating %s for the %d students in" % (output_filename, students_len) print "%s" % assn_handin print "Test results will be obtained from" print "%s\n" % assn_marking quit = raw_input("Continue? (y/n): ") if quit != 'y' and quit != 'yes': print 'Exiting...' sys.exit(0) print 'OK! Making files...' counter = 0 for stud in students: counter += 1; if '.' in stud: continue; print '--- Creating %s for %s --- %d/%d' % (output_filename, stud, counter, students_len) autotest_location = assn_marking + "%s/OUTPUT.txt" % stud files = [] for expected_file in file_list: files.append(assn_handin + "%s/%s" % (stud, expected_file)) print 'Creating ' + assn_handin + "%s/%s" % (stud, output_filename) print 'Autotest results '+ autotest_location f = open(assn_handin + "%s/%s" % (stud, output_filename), 'w') q = MakeGradedAssignment(assn_name, stud, autotest_location, files); for line in q: f.write(line) f.close() elif argc >= 4: # create graded assignment for one student, and print to screen q = MakeGradedAssignment(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4:]) for line in q: print line, else: PrintHelp() if len(students_with_no_autotest) > 0: print >>sys.stderr print >>sys.stderr, "Could not find autotest results for these students:" print >>sys.stderr for stud in students_with_no_autotest: print >>sys.stderr, ("%-8s %s" % (stud[0], stud[1]))