diff --git a/lib/kgrader.rb b/lib/kgrader.rb index de89b03..b34a778 100644 --- a/lib/kgrader.rb +++ b/lib/kgrader.rb @@ -1,4 +1,5 @@ require_relative 'kgrader/assignment' +require_relative 'kgrader/backend' require_relative 'kgrader/cli' require_relative 'kgrader/course' require_relative 'kgrader/errors' diff --git a/lib/kgrader/assignment.rb b/lib/kgrader/assignment.rb index ee22e50..ee6544f 100644 --- a/lib/kgrader/assignment.rb +++ b/lib/kgrader/assignment.rb @@ -11,5 +11,9 @@ module KGrader rescue FilesystemError raise AssignmentError, "unknown assignment: #{name}" end + + def id + @config['id'] || @name + end end end diff --git a/lib/kgrader/backend.rb b/lib/kgrader/backend.rb new file mode 100644 index 0000000..ec73045 --- /dev/null +++ b/lib/kgrader/backend.rb @@ -0,0 +1 @@ +require_relative 'backend/svn' diff --git a/lib/kgrader/backend/svn.rb b/lib/kgrader/backend/svn.rb new file mode 100644 index 0000000..e6142b6 --- /dev/null +++ b/lib/kgrader/backend/svn.rb @@ -0,0 +1,17 @@ +module KGrader::Backend + class SVN + + def initialize(filesystem, config) + @fs = filesystem + @config = config + end + + def fetch(semester, assignment, student) + url = @config['url'] % { + :semester => semester, :assignment => assignment, :student => student } + + # TODO + puts "[fetching #{student}: #{url}]" + end + end +end diff --git a/lib/kgrader/course.rb b/lib/kgrader/course.rb index 1492de8..06ef294 100644 --- a/lib/kgrader/course.rb +++ b/lib/kgrader/course.rb @@ -1,12 +1,14 @@ module KGrader class Course - attr_reader :name + attr_reader :name, :backend def initialize(filesystem, name) @fs = filesystem @name = name @config = @fs.load @fs.course_config(@name) + type = @config['backend'] + @backend = KGrader::backend(type).new self, @config[type] @rosters = {} @assignments = {} rescue FilesystemError diff --git a/lib/kgrader/task.rb b/lib/kgrader/task.rb index f05a195..c7d7179 100644 --- a/lib/kgrader/task.rb +++ b/lib/kgrader/task.rb @@ -19,11 +19,17 @@ module KGrader regrade = options.fetch(:regrade, false) # TODO - puts "Grading #{@course.name}:#{@semester} assignment #{@assignment.name}..." - puts "- students: #{students.inspect}" - puts "- due: #{due}" - puts "- fetch: #{fetch}" - puts "- regrade: #{regrade}" + puts "[grading]" + puts "course => #{@course.name}" + puts "semester => #{@semester}" + puts "assignment => #{@assignment.name}" + puts "students => #{students.join ', '}" + puts "due => #{due}" + puts "fetch => #{fetch}" + puts "regrade => #{regrade}" + puts + + fetch_students students if fetch end def commit(options = {}) @@ -31,8 +37,18 @@ module KGrader students &= options[:students] unless options[:students].nil? # TODO - puts "Committing #{@course.name}:#{@semester} assignment #{@assignment.name}..." - puts "- students: #{students.inspect}" + puts "[committing]" + puts "course => #{@course.name}" + puts "semester => #{@semester}" + puts "assignment => #{@assignment.name}" + puts "students => #{students.join ', '}" + end + + private + def fetch_students(students) + students.each do |student| + @course.backend.fetch @semester, @assignment.id, student + end end end end diff --git a/lib/kgrader/util.rb b/lib/kgrader/util.rb index 0280377..419ef34 100644 --- a/lib/kgrader/util.rb +++ b/lib/kgrader/util.rb @@ -33,6 +33,15 @@ module KGrader return args, options end + def self.backend(type) + case type + when 'svn' + Backend::SVN + else + raise ConfigError, "unknown backend: #{type}" + end + end + def self.current_semester(format) season = Time.now.strftime('%m').to_i <= 6 ? 'sp' : 'fa' case format diff --git a/spec/cs241h b/spec/cs241h index 3c6f5d0..438e509 160000 --- a/spec/cs241h +++ b/spec/cs241h @@ -1 +1 @@ -Subproject commit 3c6f5d050d8a66de6b3c36ce1985c225700a5c2f +Subproject commit 438e509e4c9097894f275dd66a5ae37bbcb62c24