A code autograder for student homework submissions
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

63 lignes
1.5 KiB

  1. require 'open3'
  2. require 'time'
  3. module KGrader
  4. def self.version
  5. git = Open3.capture2e('git', 'rev-parse', '--short', 'HEAD')
  6. return git[0].strip if git[1].exited? && git[1].exitstatus == 0
  7. end
  8. def self.parse_args(raw, range, keywords)
  9. args = []
  10. options = {}
  11. raw.each do |arg|
  12. if arg.include? '='
  13. key, val = arg.split('=', 2)
  14. key = key.to_sym
  15. unless keywords.include? key
  16. raise ArgumentError, "unknown keyword: #{key}"
  17. end
  18. options[key] = case keywords[key]
  19. when :string
  20. val
  21. when :bool
  22. %w(true yes 1 t y).include? val.downcase
  23. when :array
  24. val.split(",").map! { |x| x.strip.downcase }
  25. when :time
  26. Time.parse(val)
  27. end
  28. else
  29. args << arg
  30. end
  31. end
  32. raise ArgumentError, "too few arguments" if args.size < range.begin
  33. raise ArgumentError, "too many arguments" if args.size > range.end
  34. args[range.end - 1] = nil unless args.size == range.end
  35. return args, options
  36. end
  37. def self.backend(type)
  38. case type
  39. when 'svn'
  40. Backend::SVN
  41. else
  42. raise ConfigError, "unknown backend: #{type}"
  43. end
  44. end
  45. def self.current_semester(format)
  46. season = Time.now.strftime('%m').to_i <= 6 ? 'sp' : 'fa'
  47. case format
  48. when 'faspYY'
  49. season + Time.now.strftime('%y')
  50. when 'faspYYYY'
  51. season + Time.now.strftime('%Y')
  52. else
  53. raise ConfigError, "unknown semester format: #{format}"
  54. end
  55. end
  56. end