Browse Source

Framework for staging submissions.

master
Ben Kurtovic 8 years ago
parent
commit
91eec83975
4 changed files with 61 additions and 23 deletions
  1. +20
    -2
      lib/kgrader/assignment.rb
  2. +4
    -19
      lib/kgrader/cli.rb
  3. +21
    -2
      lib/kgrader/filesystem.rb
  4. +16
    -0
      lib/kgrader/submission.rb

+ 20
- 2
lib/kgrader/assignment.rb View File

@@ -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

+ 4
- 19
lib/kgrader/cli.rb View File

@@ -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

+ 21
- 2
lib/kgrader/filesystem.rb View File

@@ -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

+ 16
- 0
lib/kgrader/submission.rb View File

@@ -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

Loading…
Cancel
Save