Description:
added --dry option to grader prob mode
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r91:5df0d71260f4 - - 2 files changed: 72 inserted, 46 deleted
@@ -57,51 +57,79 | |||
|
57 | 57 | end |
|
58 | 58 | |
|
59 | 59 | ######################################### |
|
60 | 60 | # main program |
|
61 | 61 | ######################################### |
|
62 | 62 | |
|
63 | - # with --help | |
|
64 | - if (ARGV.length==1) and (/help/.match(ARGV[0])) | |
|
65 | - display_manual | |
|
66 | - exit(0) | |
|
63 | + # Reading environment and options. | |
|
64 | + | |
|
65 | + def process_options_and_stop_file | |
|
66 | + # The list of options are: | |
|
67 | + # - stop [all|process ids] | |
|
68 | + # - | |
|
69 | + | |
|
70 | + # Process 'help' option | |
|
71 | + if (ARGV.length==1) and (/help/.match(ARGV[0])) | |
|
72 | + display_manual | |
|
73 | + exit(0) | |
|
74 | + end | |
|
75 | + | |
|
76 | + # Process 'stop' option. | |
|
77 | + if (ARGV.length >= 1) and (ARGV[0]=='stop') | |
|
78 | + if ARGV.length==1 | |
|
79 | + puts "you should specify pid-list or 'all'" | |
|
80 | + display_manual | |
|
81 | + elsif (ARGV.length==2) and (ARGV[1]=='all') | |
|
82 | + stop_grader(:all) | |
|
83 | + puts "A global stop file ('stop.all') created." | |
|
84 | + puts "You should remove it manually later." | |
|
85 | + else | |
|
86 | + (1..ARGV.length-1).each do |i| | |
|
87 | + stop_grader(ARGV[i]) | |
|
88 | + end | |
|
89 | + puts "stop file(s) created" | |
|
90 | + end | |
|
91 | + exit(0) | |
|
92 | + end | |
|
93 | + | |
|
94 | + # Check stop file. | |
|
95 | + if check_stopfile | |
|
96 | + puts "Stop file exists. Terminated." | |
|
97 | + clear_stopfile | |
|
98 | + exit(0) | |
|
99 | + end | |
|
100 | + | |
|
101 | + #default options | |
|
102 | + options = { | |
|
103 | + :mode => 'queue', | |
|
104 | + :environment => 'exam', | |
|
105 | + :dry_run => false, | |
|
106 | + } | |
|
107 | + | |
|
108 | + # Process mode and environment option | |
|
109 | + if ARGV.length >= 1 | |
|
110 | + options[:environment] = ARGV.shift | |
|
111 | + if ARGV.length >=1 | |
|
112 | + options[:mode] = ARGV.shift | |
|
113 | + end | |
|
114 | + end | |
|
115 | + | |
|
116 | + options[:dry_run] = (ARGV.delete('--dry') != nil) | |
|
117 | + if options[:dry_run] and (not options[:mode] == 'prob') | |
|
118 | + puts "Dry run currently works for 'prob' mode." | |
|
119 | + exit(0) | |
|
120 | + end | |
|
121 | + | |
|
122 | + return options | |
|
67 | 123 | end |
|
68 | 124 | |
|
69 | - # reading environment and options | |
|
70 | - if (ARGV.length >= 1) and (ARGV[0]=='stop') | |
|
71 | - if ARGV.length==1 | |
|
72 | - puts "you should specify pid-list or 'all'" | |
|
73 | - display_manual | |
|
74 | - elsif (ARGV.length==2) and (ARGV[1]=='all') | |
|
75 | - stop_grader(:all) | |
|
76 | - puts "A global stop file ('stop.all') created." | |
|
77 | - puts "You should remove it manually later." | |
|
78 | - else | |
|
79 | - (1..ARGV.length-1).each do |i| | |
|
80 | - stop_grader(ARGV[i]) | |
|
81 | - end | |
|
82 | - puts "stop file(s) created" | |
|
83 | - end | |
|
84 | - exit(0) | |
|
85 | - end | |
|
86 | - | |
|
87 | - if check_stopfile | |
|
88 | - puts "Stop file exists. Terminated." | |
|
89 | - clear_stopfile | |
|
90 | - exit(0) | |
|
91 | - end | |
|
92 | - | |
|
93 | - grader_mode = 'queue' | |
|
94 | - if ARGV.length >= 1 | |
|
95 | - GRADER_ENV = ARGV[0] | |
|
96 | - if ARGV.length >=2 | |
|
97 | - grader_mode = ARGV[1] | |
|
98 | - end | |
|
99 | - else | |
|
100 | - GRADER_ENV = 'exam' | |
|
101 | - end | |
|
125 | + # ======= Main ======== | |
|
126 | + options = process_options_and_stop_file | |
|
127 | + GRADER_ENV = options[:environment] | |
|
128 | + grader_mode = options[:mode] | |
|
129 | + dry_run = options[:dry_run] | |
|
102 | 130 | |
|
103 | 131 | puts "environment: #{GRADER_ENV}" |
|
104 | 132 | require File.join(File.dirname(__FILE__),'config/environment') |
|
105 | 133 | |
|
106 | 134 | # add grader_mode to config |
|
107 | 135 | # this is needed because method log needs it. TODO: clean this up |
@@ -167,20 +195,17 | |||
|
167 | 195 | if task==nil |
|
168 | 196 | sleep(1) |
|
169 | 197 | end |
|
170 | 198 | end |
|
171 | 199 | |
|
172 | 200 | when "prob" |
|
173 | - engine = Grader::Engine.new | |
|
201 | + engine = Grader::Engine.new(nil, Grader::SubmissionReporter.new(dry_run)) | |
|
174 | 202 | runner = Grader::Runner.new(engine, grader_proc) |
|
175 | 203 | |
|
176 | 204 | grader_proc.report_active if grader_proc!=nil |
|
177 | 205 | |
|
178 | - ARGV.shift | |
|
179 | - ARGV.shift | |
|
180 | - | |
|
181 | 206 | ARGV.each do |prob_name| |
|
182 | 207 | prob = Problem.find_by_name(prob_name) |
|
183 | 208 | if prob==nil |
|
184 | 209 | puts "cannot find problem: #{prob_name}" |
|
185 | 210 | else |
|
186 | 211 | runner.grade_problem(prob) |
@@ -190,15 +215,12 | |||
|
190 | 215 | when "sub" |
|
191 | 216 | engine = Grader::Engine.new |
|
192 | 217 | runner = Grader::Runner.new(engine, grader_proc) |
|
193 | 218 | |
|
194 | 219 | grader_proc.report_active if grader_proc!=nil |
|
195 | 220 | |
|
196 | - ARGV.shift | |
|
197 | - ARGV.shift | |
|
198 | - | |
|
199 | 221 | ARGV.each do |sub_id| |
|
200 | 222 | puts "Grading #{sub_id}" |
|
201 | 223 | begin |
|
202 | 224 | submission = Submission.find(sub_id.to_i) |
|
203 | 225 | rescue ActiveRecord::RecordNotFound |
|
204 | 226 | puts "Record not found" |
@@ -29,14 +29,15 | |||
|
29 | 29 | |
|
30 | 30 | def clean_up(submission) |
|
31 | 31 | end |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | 34 | class SubmissionReporter |
|
35 | - def initialize | |
|
35 | + def initialize(dry_run=false) | |
|
36 | 36 | @config = Grader::Configuration.get_instance |
|
37 | + @dry_run = dry_run | |
|
37 | 38 | end |
|
38 | 39 | |
|
39 | 40 | def report(sub,test_result_dir) |
|
40 | 41 | save_result(sub,read_result(test_result_dir)) |
|
41 | 42 | end |
|
42 | 43 | |
@@ -112,12 +113,15 | |||
|
112 | 113 | submission.grader_comment = 'PASSED: ' + comment + '(inconsistent score)' |
|
113 | 114 | else |
|
114 | 115 | #submission.grader_comment = 'FAILED: ' + comment |
|
115 | 116 | submission.grader_comment = comment |
|
116 | 117 | end |
|
117 | 118 | submission.compiler_message = result[:cmp_msg] or '' |
|
118 | - submission.save | |
|
119 | + | |
|
120 | + if not @dry_run | |
|
121 | + submission.save | |
|
122 | + end | |
|
119 | 123 | end |
|
120 | 124 | |
|
121 | 125 | end |
|
122 | 126 | |
|
123 | 127 | end |
You need to be logged in to leave comments.
Login now