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.

61 lines
1.5 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. # run 'commit', '-m', message, *paths.map { |fn| File.join repo, fn }
  33. end
  34. def commit_date(repo)
  35. xml = Nokogiri::XML run('log', '--xml', '-l', '1', repo).first
  36. Time.parse xml.css('logentry date').text
  37. end
  38. private
  39. def run(*cmd)
  40. Open3.capture2e('svn', *cmd)
  41. end
  42. def get_url(semester, assignment, student)
  43. @config['url'] % {
  44. :semester => semester,
  45. :assignment => assignment,
  46. :student => student
  47. }
  48. end
  49. end
  50. end