Browse Source

Rewinding, other tweaks

master
Ben Kurtovic 8 years ago
parent
commit
5d6dd9511e
4 changed files with 36 additions and 5 deletions
  1. +12
    -0
      lib/kgrader/backend/svn.rb
  2. +7
    -1
      lib/kgrader/errors.rb
  3. +13
    -4
      lib/kgrader/submission.rb
  4. +4
    -0
      lib/kgrader/task.rb

+ 12
- 0
lib/kgrader/backend/svn.rb View File

@@ -26,6 +26,18 @@ module KGrader::Backend
run *args, repo
end

def log(repo)
xml = Nokogiri::XML run('log', '--xml', repo).first
xml.css('logentry').map do |elem|
{ :rev => elem.attr('revision').to_i,
:date => Time.parse(elem.css('date').text) }
end
end

def commit(repo, message, paths = nil)
# TODO
end

private
def run(*cmd)
Open3.capture2e('svn', *cmd)


+ 7
- 1
lib/kgrader/errors.rb View File

@@ -14,9 +14,15 @@ module KGrader
class CourseError < KGraderError
end

class RosterError < KGraderError
end

class AssignmentError < KGraderError
end

class RosterError < KGraderError
class TaskError < KGraderError
end

class SubmissionError < KGraderError
end
end

+ 13
- 4
lib/kgrader/submission.rb View File

@@ -41,8 +41,8 @@ module KGrader
oldrev = revision if status == :graded
self.status = :fetching
@course.backend.update repo
rewind due
self.status = revision == oldrev ? :graded : :ungraded
newrev = rewind due
self.status = newrev == oldrev ? :graded : :ungraded
end
nil
end
@@ -63,7 +63,8 @@ module KGrader
def commit
# TODO:
# if status == :graded && File.exists? pendingfile
# [copy gradefile to repo and commit]
# [copy gradefile to repo]
# @course.backend.commit repo, <message>, <gradefile path>
# FileUtils.rm pendingfile
# end

@@ -93,7 +94,15 @@ module KGrader
end

def rewind(date)
# TODO
log = @course.backend.log repo
target = log.find { |commit| commit[:date] <= date }
if target.nil?
raise SubmissionError, "no commits before due date: #{student}"
end

rev = target[:rev]
@course.backend.update repo, rev
rev
end
end
end

+ 4
- 0
lib/kgrader/task.rb View File

@@ -16,6 +16,10 @@ module KGrader
fetch = options.fetch(:fetch, true)
regrade = options.fetch(:regrade, false)

if options.include?(:due) && !fetch
raise TaskError, "can't set a new due date without fetching"
end

subtask 'setup' do |sub|
sub.create unless sub.exists?
end


Loading…
Cancel
Save