Переглянути джерело

Add some error handling; tweak.

master
Ben Kurtovic 8 роки тому
джерело
коміт
7a478b6712
7 змінених файлів з 38 додано та 13 видалено
  1. +8
    -3
      README.md
  2. +1
    -0
      lib/kgrader.rb
  3. +11
    -3
      lib/kgrader/cli.rb
  4. +7
    -0
      lib/kgrader/errors.rb
  5. +4
    -0
      lib/kgrader/filesystem.rb
  6. +4
    -4
      lib/kgrader/util.rb
  7. +3
    -3
      rakefile

+ 8
- 3
README.md Переглянути файл

@@ -31,9 +31,13 @@ To show all known classes, semesters, and assignments:

rake list

To load a roster for a course semester:
To load a roster for a specific semester:

rake roster cs123 sp2016 myroster.csv
rake roster cs123 myroster.csv semester=sp16

To load a roster for the current semester:

rake roster cs123 myroster.csv

### Grading

@@ -83,4 +87,5 @@ repo has changed since the last run. To forcibly regrade:

rake grade cs123 mp1 regrade=yes

You can combine these arguments in any meaningful way.
You can combine these arguments in any meaningful way. `semester` is available
for `roster` and `commit`, and and `students` is available for `commit`.

+ 1
- 0
lib/kgrader.rb Переглянути файл

@@ -1,5 +1,6 @@
require_relative 'kgrader/cli'
require_relative 'kgrader/course'
require_relative 'kgrader/errors'
require_relative 'kgrader/filesystem'
require_relative 'kgrader/roster'
require_relative 'kgrader/task'


+ 11
- 3
lib/kgrader/cli.rb Переглянути файл

@@ -26,17 +26,19 @@ module KGrader
end

def roster(course, semester, rosterfile)
Course.new(@fs, course).roster(semester).load rosterfile
course = fetch_course course
semester ||= course.current_semester
course.roster(semester).load rosterfile
end

def grade(course, semester, assignment, options = {})
course = Course.new @fs, course
course = fetch_course course
semester ||= course.current_semester
course.task(semester, assignment).grade options
end

def commit(course, semester, assignment, options = {})
course = Course.new @fs, course
course = fetch_course course
semester ||= course.current_semester
course.task(semester, assignment).commit options
end
@@ -56,6 +58,12 @@ module KGrader
end

private
def fetch_course(course)
Course.new(@fs, course)
rescue FilesystemError
KGrader::die "unknown course"
end

def reset_jail
FileUtils.rm_rf @fs.jail
FileUtils.mkdir @fs.jail


+ 7
- 0
lib/kgrader/errors.rb Переглянути файл

@@ -0,0 +1,7 @@
module KGrader
class KGraderError < StandardError
end

class FilesystemError < KGraderError
end
end

+ 4
- 0
lib/kgrader/filesystem.rb Переглянути файл

@@ -51,7 +51,11 @@ module KGrader
YAML.load File.read(path)
when '.csv'
File.read(path).split("\n").map! { |line| line.split "," }
else
raise FilesystemError, "unknown file type"
end
rescue SystemCallError # Errno::ENOENT, etc.
raise FilesystemError, "can't read file"
end
end
end

+ 4
- 4
lib/kgrader/util.rb Переглянути файл

@@ -1,7 +1,7 @@
require 'date'

module KGrader
def self.abort(error)
def self.die(error)
Kernel::abort "fatal: #{error}"
end

@@ -13,7 +13,7 @@ module KGrader
if arg.include? '='
key, val = arg.split('=', 2)
key = key.to_sym
abort "unknown keyword #{key}" unless keywords.include? key
die "unknown keyword #{key}" unless keywords.include? key
options[key] = case keywords[key]
when :string
val
@@ -29,8 +29,8 @@ module KGrader
end
end

abort "too few arguments" if args.size < num
abort "too many arguments" if args.size > num
die "too few arguments" if args.size < num
die "too many arguments" if args.size > num
return args, options
end



+ 3
- 3
rakefile Переглянути файл

@@ -15,7 +15,7 @@ task :default => :help do ; end
task :help do
puts %{usage:
- rake list
- rake roster <course> <semester> <rosterfile>
- rake roster <course> <rosterfile> [semester=<...>]
- rake grade <course> <assignment> [semester=<...>] [students=<...>]
[due=<...>] [fetch=<yes/no>] [regrade=<yes/no>]
- rake commit <course> <assignment> [semester=<...>] [students=<...>]
@@ -28,8 +28,8 @@ task :list do
end

task :roster do
course, semester, rosterfile = parse_args 3
cli.roster course, semester, rosterfile
course, rosterfile, options = parse_args 2, { :semester => :string }
cli.roster course, options[:semester], rosterfile
end

task :grade do


Завантаження…
Відмінити
Зберегти