From fa3200755571d6687e46324bb84a14b4609f45be Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Thu, 24 Mar 2016 00:28:11 -0400 Subject: [PATCH] Implement more stuff --- lib/kgrader/cli.rb | 31 ++++++++++++++++++++----------- lib/kgrader/course.rb | 17 +++++++++++++++++ lib/kgrader/filesystem.rb | 28 ++++++++++++++++++++++------ lib/kgrader/roster.rb | 6 ++++++ lib/kgrader/util.rb | 4 ++++ spec/cs241h | 2 +- 6 files changed, 70 insertions(+), 18 deletions(-) diff --git a/lib/kgrader/cli.rb b/lib/kgrader/cli.rb index 621e26b..e534587 100644 --- a/lib/kgrader/cli.rb +++ b/lib/kgrader/cli.rb @@ -9,8 +9,20 @@ module KGrader end def list - # TODO - puts "[list]" + @fs.courses.each do |name| + puts "course: #{name}" + course = Course.new(@fs, name) + + puts " rosters:" + course.rosters.each do |roster| + puts " - #{roster.semester} (#{roster.students.size} students)" + end + + puts " assignments:" + course.assignments.each do |assignment| + puts " - #{assignment}" + end + end end def roster(course, semester, rosterfile) @@ -18,18 +30,15 @@ module KGrader end def grade(course, semester, assignment, options = {}) - # TODO - # need to get default semester... - semester ||= 'DEFAULT' - task = Course.new(@fs, course).task semester, assignment - task.grade options + course = Course.new @fs, course + semester ||= course.current_semester + course.task(semester, assignment).grade options end def commit(course, semester, assignment, options = {}) - # TODO - semester ||= 'DEFAULT' - task = Course.new(@fs, course).task semester, assignment - task.commit options + course = Course.new @fs, course + semester ||= course.current_semester + course.task(semester, assignment).commit options end def clean diff --git a/lib/kgrader/course.rb b/lib/kgrader/course.rb index c73d8c9..b6bd37f 100644 --- a/lib/kgrader/course.rb +++ b/lib/kgrader/course.rb @@ -20,5 +20,22 @@ module KGrader # TODO: cache Task.new @fs, self, semester, assignment end + + def rosters + @fs.semesters(@name).map! { |semester| roster semester } + end + + def assignments + @fs.assignments @name + end + + def current_semester + case @config['semesters'] + when 'faspYY' + KGrader::season + DateTime.now.strftime('%y') + when 'faspYYYY' + KGrader::season + DateTime.now.strftime('%Y') + end + end end end diff --git a/lib/kgrader/filesystem.rb b/lib/kgrader/filesystem.rb index ca38535..8e29759 100644 --- a/lib/kgrader/filesystem.rb +++ b/lib/kgrader/filesystem.rb @@ -7,8 +7,20 @@ module KGrader @root = root end + def desk + File.join @root, 'desk' + end + + def jail + File.join @root, 'jail' + end + + def spec + File.join @root, 'spec' + end + def course(name) - File.join @root, 'spec', name + File.join spec, name end def course_config(name) @@ -16,15 +28,19 @@ module KGrader end def courses - Dir[File.join @root, 'spec', '*', ''].each { |fn| File.basename fn } + Dir[File.join spec, '*', ''].map! { |fn| File.basename fn } end - def desk - File.join @root, 'desk' + def assignments(course) + Dir[File.join spec, course, '*', '_config.yml'].map! do |fn| + File.basename File.dirname fn + end end - def jail - File.join @root, 'jail' + def semesters(course) + Dir[File.join desk, course, '*', '_roster.csv'].map! do |fn| + File.basename File.dirname fn + end end def load(path) diff --git a/lib/kgrader/roster.rb b/lib/kgrader/roster.rb index faea976..108a5d4 100644 --- a/lib/kgrader/roster.rb +++ b/lib/kgrader/roster.rb @@ -1,5 +1,6 @@ module KGrader class Roster + attr_reader :semester def initialize(filesystem, course, semester) @fs = filesystem @@ -11,5 +12,10 @@ module KGrader # TODO puts "Loading roster for #{@course.name}:#{@semester} from [#{filename}]..." end + + def students + # TODO + ["ksmith12"] + end end end diff --git a/lib/kgrader/util.rb b/lib/kgrader/util.rb index 07adbd0..9855047 100644 --- a/lib/kgrader/util.rb +++ b/lib/kgrader/util.rb @@ -33,4 +33,8 @@ module KGrader abort "too many arguments" if args.size > num return args, options end + + def self.season + DateTime.now.strftime('%m').to_i <= 6 ? 'sp' : 'fa' + end end diff --git a/spec/cs241h b/spec/cs241h index 54398ad..3c6f5d0 160000 --- a/spec/cs241h +++ b/spec/cs241h @@ -1 +1 @@ -Subproject commit 54398ad4a16ac3d9f7344ecf680f4dd167e05818 +Subproject commit 3c6f5d050d8a66de6b3c36ce1985c225700a5c2f