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