@@ -4,6 +4,7 @@ require_relative 'kgrader/cli' | |||||
require_relative 'kgrader/course' | require_relative 'kgrader/course' | ||||
require_relative 'kgrader/errors' | require_relative 'kgrader/errors' | ||||
require_relative 'kgrader/filesystem' | require_relative 'kgrader/filesystem' | ||||
require_relative 'kgrader/jail' | |||||
require_relative 'kgrader/roster' | require_relative 'kgrader/roster' | ||||
require_relative 'kgrader/submission' | require_relative 'kgrader/submission' | ||||
require_relative 'kgrader/task' | require_relative 'kgrader/task' | ||||
@@ -24,12 +24,14 @@ module KGrader | |||||
end | end | ||||
manifest = @config['manifest'] | manifest = @config['manifest'] | ||||
provided = manifest['provided'].map do |glob| | |||||
Dir[File.join @root, 'provided', glob] | |||||
end.flatten | |||||
provided = manifest['provided'].map do |fn| | |||||
{ :name => fn, :path => File.join(@root, 'provided', fn) } | |||||
end | |||||
graded = manifest['graded'].map { |fn| { :name => fn } } | |||||
{ | { | ||||
:provided => provided, | :provided => provided, | ||||
:graded => manifest['graded'], | |||||
:graded => graded, | |||||
:report => manifest['report'] | :report => manifest['report'] | ||||
} | } | ||||
end | end | ||||
@@ -37,7 +37,7 @@ module KGrader | |||||
end | end | ||||
def clean | def clean | ||||
@fs.reset_jail | |||||
@fs.jail.reset | |||||
@fs.clean_desk | @fs.clean_desk | ||||
end | end | ||||
@@ -46,7 +46,7 @@ module KGrader | |||||
print "are you sure? [y/N] " | print "are you sure? [y/N] " | ||||
abort "aborted" unless ['y', 'yes'].include? STDIN.gets.strip.downcase | abort "aborted" unless ['y', 'yes'].include? STDIN.gets.strip.downcase | ||||
@fs.reset_jail | |||||
@fs.jail.reset | |||||
@fs.reset_desk | @fs.reset_desk | ||||
end | end | ||||
@@ -8,22 +8,8 @@ module KGrader | |||||
@root = root | @root = root | ||||
end | end | ||||
def desk | |||||
File.join @root, 'desk' | |||||
end | |||||
def jail | |||||
File.join @root, 'jail' | |||||
end | |||||
def spec | |||||
File.join @root, 'spec' | |||||
end | |||||
# ------------------------------------------------------------------------- | |||||
def course(name) | def course(name) | ||||
File.join spec, name | |||||
File.join spec_dir, name | |||||
end | end | ||||
def course_config(name) | def course_config(name) | ||||
@@ -39,17 +25,17 @@ module KGrader | |||||
end | end | ||||
def roster(courseid, semester) | def roster(courseid, semester) | ||||
File.join desk, courseid, semester, '_roster.csv' | |||||
File.join desk_dir, courseid, semester, '_roster.csv' | |||||
end | end | ||||
def submission(courseid, semester, assignment, student) | def submission(courseid, semester, assignment, student) | ||||
File.join desk, courseid, semester, assignment, student | |||||
File.join desk_dir, courseid, semester, assignment, student | |||||
end | end | ||||
# ------------------------------------------------------------------------- | # ------------------------------------------------------------------------- | ||||
def courses | def courses | ||||
Dir[File.join spec, '*', ''].map! { |fn| File.basename fn } | |||||
Dir[File.join spec_dir, '*', ''].map! { |fn| File.basename fn } | |||||
end | end | ||||
def assignments(courseid) | def assignments(courseid) | ||||
@@ -79,19 +65,34 @@ module KGrader | |||||
raise FilesystemError, "can't read file: #{path}" | raise FilesystemError, "can't read file: #{path}" | ||||
end | end | ||||
def reset_jail | |||||
FileUtils.rm_rf jail | |||||
def jail | |||||
@jail ||= Jail.new jail_dir | |||||
end | end | ||||
def reset_desk | def reset_desk | ||||
FileUtils.rm_rf Dir[File.join desk, '*', ''] | |||||
FileUtils.rm_rf Dir[File.join desk_dir, '*', ''] | |||||
end | end | ||||
def clean_desk | def clean_desk | ||||
Dir[File.join desk, '*', '*', '*', '*', 'status.txt'].each do |fn| | |||||
Dir[File.join desk_dir, '*', '*', '*', '*', 'status.txt'].each do |fn| | |||||
File.write fn, "ungraded" if File.read(fn) == "graded" | File.write fn, "ungraded" if File.read(fn) == "graded" | ||||
end | end | ||||
FileUtils.rm_rf Dir[File.join desk, '*', '*', '*', '*', 'pending'] | |||||
FileUtils.rm_rf Dir[File.join desk_dir, '*', '*', '*', '*', 'pending'] | |||||
end | |||||
# ------------------------------------------------------------------------- | |||||
private | |||||
def desk_dir | |||||
File.join @root, 'desk' | |||||
end | |||||
def jail_dir | |||||
File.join @root, 'jail' | |||||
end | |||||
def spec_dir | |||||
File.join @root, 'spec' | |||||
end | end | ||||
end | end | ||||
end | end |
@@ -0,0 +1,20 @@ | |||||
module KGrader | |||||
class Jail | |||||
def initialize(root) | |||||
@root = root | |||||
end | |||||
def init | |||||
FileUtils.mkdir_p @root | |||||
end | |||||
def reset | |||||
FileUtils.rm_rf @root | |||||
end | |||||
def stage(source, target) | |||||
puts "[chroot::stage] #{source} -> (jail)/#{target}" | |||||
end | |||||
end | |||||
end |
@@ -53,7 +53,7 @@ module KGrader | |||||
stage | stage | ||||
# [grade the stuff] | # [grade the stuff] | ||||
# [save report to gradefile] | # [save report to gradefile] | ||||
# @fs.reset_jail | |||||
# @fs.jail.reset | |||||
# FileUtils.touch pendingfile | # FileUtils.touch pendingfile | ||||
# self.status = :graded | # self.status = :graded | ||||
# return grade summary string | # return grade summary string | ||||
@@ -108,17 +108,15 @@ module KGrader | |||||
end | end | ||||
def stage | def stage | ||||
@fs.reset_jail | |||||
FileUtils.mkdir_p @fs.jail | |||||
@fs.jail.reset | |||||
@fs.jail.init | |||||
# 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 | |||||
@assignment.manifest[:provided].each do |entry| | |||||
@fs.jail.stage entry[:path], entry[:name] | |||||
end | |||||
@assignment.manifest[:graded].each do |entry| | |||||
@fs.jail.stage File.join(repo, entry[:name]), entry[:name] | |||||
end | |||||
end | end | ||||
end | end | ||||
end | end |