From 91eec8397506789e993d3961e4f394385367c69a Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Fri, 8 Apr 2016 22:44:26 -0500 Subject: [PATCH] Framework for staging submissions. --- lib/kgrader/assignment.rb | 22 ++++++++++++++++++++-- lib/kgrader/cli.rb | 23 ++++------------------- lib/kgrader/filesystem.rb | 23 +++++++++++++++++++++-- lib/kgrader/submission.rb | 16 ++++++++++++++++ 4 files changed, 61 insertions(+), 23 deletions(-) diff --git a/lib/kgrader/assignment.rb b/lib/kgrader/assignment.rb index ee6544f..e7efec8 100644 --- a/lib/kgrader/assignment.rb +++ b/lib/kgrader/assignment.rb @@ -1,13 +1,15 @@ module KGrader class Assignment - attr_reader :name + attr_reader :name, :manifest def initialize(filesystem, course, name) @fs = filesystem @course = course @name = name - @config = @fs.load @fs.assignment(@course.name, @name) + @root = @fs.assignment @course.name, @name + @config = @fs.load @fs.assignment_config(@course.name, @name) + @manifest = build_manifest rescue FilesystemError raise AssignmentError, "unknown assignment: #{name}" end @@ -15,5 +17,21 @@ module KGrader def id @config['id'] || @name end + + def build_manifest + unless @config.include? 'manifest' + raise AssignmentError, "missing manifest: #{@name}" + end + + manifest = @config['manifest'] + provided = manifest['provided'].map do |glob| + Dir[File.join @root, 'provided', glob] + end.flatten + { + :provided => provided, + :graded => manifest['graded'], + :report => manifest['report'] + } + end end end diff --git a/lib/kgrader/cli.rb b/lib/kgrader/cli.rb index 54351a4..647a85e 100644 --- a/lib/kgrader/cli.rb +++ b/lib/kgrader/cli.rb @@ -37,8 +37,8 @@ module KGrader end def clean - clear_jail - clean_desk + @fs.reset_jail + @fs.clean_desk end def clobber @@ -46,8 +46,8 @@ module KGrader print "are you sure? [y/N] " abort "aborted" unless ['y', 'yes'].include? STDIN.gets.strip.downcase - clear_jail - clear_desk + @fs.reset_jail + @fs.reset_desk end private @@ -65,20 +65,5 @@ module KGrader puts "#{pad} - #{assignment.name}" end end - - def clear_jail - FileUtils.rm_rf @fs.jail - end - - def clear_desk - FileUtils.rm_rf Dir[File.join @fs.desk, '*', ''] - end - - def clean_desk - Dir[File.join @fs.desk, '*', '*', '*', '*', 'status.txt'].each do |fn| - File.write fn, "ungraded" if File.read(fn) == "graded" - end - FileUtils.rm_rf Dir[File.join @fs.desk, '*', '*', '*', '*', 'pending'] - end end end diff --git a/lib/kgrader/filesystem.rb b/lib/kgrader/filesystem.rb index 439dce0..195833c 100644 --- a/lib/kgrader/filesystem.rb +++ b/lib/kgrader/filesystem.rb @@ -31,7 +31,11 @@ module KGrader end def assignment(courseid, name) - File.join course(courseid), name, '_config.yml' + File.join course(courseid), name + end + + def assignment_config(courseid, name) + File.join assignment(courseid, name), '_config.yml' end def roster(courseid, semester) @@ -49,7 +53,7 @@ module KGrader end def assignments(courseid) - Dir[assignment courseid, '*'].map! { |fn| File.basename File.dirname fn } + Dir[File.join course(courseid), '*', ''].map! { |fn| File.basename fn } end def semesters(courseid) @@ -74,5 +78,20 @@ module KGrader rescue SystemCallError # Errno::ENOENT, etc. raise FilesystemError, "can't read file: #{path}" end + + def reset_jail + FileUtils.rm_rf jail + end + + def reset_desk + FileUtils.rm_rf Dir[File.join desk, '*', ''] + end + + def clean_desk + Dir[File.join desk, '*', '*', '*', '*', 'status.txt'].each do |fn| + File.write fn, "ungraded" if File.read(fn) == "graded" + end + FileUtils.rm_rf Dir[File.join desk, '*', '*', '*', '*', 'pending'] + end end end diff --git a/lib/kgrader/submission.rb b/lib/kgrader/submission.rb index c2f98ac..95e4b90 100644 --- a/lib/kgrader/submission.rb +++ b/lib/kgrader/submission.rb @@ -50,8 +50,10 @@ module KGrader def grade # TODO: # self.status = :ungraded + stage # [grade the stuff] # [save report to gradefile] + # @fs.reset_jail # FileUtils.touch pendingfile # self.status = :graded # return grade summary string @@ -104,5 +106,19 @@ module KGrader @course.backend.update repo, rev rev end + + def stage + @fs.reset_jail + FileUtils.mkdir_p @fs.jail + + # puts + # @assignment.manifest[:provided].each { |fn| p fn } + # abort + + # p @assignment.manifest[:provided], @assignment.manifest[:graded], @assignment.manifest[:report] + + # copytree files matching manifest from student submission + # use assignment.stage + end end end