A code autograder for student homework submissions
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.4 KiB

  1. require 'nokogiri'
  2. require 'open3'
  3. module KGrader::Backend
  4. class SVN
  5. def initialize(filesystem, course, config)
  6. @fs = filesystem
  7. @course = course
  8. @config = config
  9. end
  10. def revision(repo)
  11. xml = Nokogiri::XML run('log', '--xml', '-l', '1', repo).first
  12. xml.css('logentry').attr('revision').value.to_i
  13. end
  14. def clone(repo, semester, assignment, student)
  15. url = get_url semester, assignment, student
  16. run 'checkout', '--ignore-externals', url, repo
  17. end
  18. def update(repo, revision = nil)
  19. args = 'update', '--ignore-externals', '--accept', 'tf'
  20. args.push "-r#{revision}" unless revision.nil?
  21. run *args, repo
  22. end
  23. def log(repo)
  24. xml = Nokogiri::XML run('log', '--xml', repo).first
  25. xml.css('logentry').map do |elem|
  26. { :rev => elem.attr('revision').to_i,
  27. :date => Time.parse(elem.css('date').text) }
  28. end
  29. end
  30. def commit(repo, message, paths = nil)
  31. # TODO
  32. end
  33. def commit_date(repo)
  34. xml = Nokogiri::XML run('log', '--xml', '-l', '1', repo).first
  35. Time.parse xml.css('logentry date').text
  36. end
  37. private
  38. def run(*cmd)
  39. Open3.capture2e('svn', *cmd)
  40. end
  41. def get_url(semester, assignment, student)
  42. @config['url'] % {
  43. :semester => semester,
  44. :assignment => assignment,
  45. :student => student
  46. }
  47. end
  48. end
  49. end