Description:
removes RUBYOPT env before calling judge scripts
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r139:1e721a756b43 - - 1 file changed: 1 inserted, 0 deleted
@@ -19,169 +19,170 | |||||
|
19 | options[:room_maker] = Grader::SubmissionRoomMaker.new |
|
19 | options[:room_maker] = Grader::SubmissionRoomMaker.new |
|
20 | end |
|
20 | end |
|
21 | if not options.include? :reporter |
|
21 | if not options.include? :reporter |
|
22 | options[:reporter] = Grader::SubmissionReporter.new |
|
22 | options[:reporter] = Grader::SubmissionReporter.new |
|
23 | end |
|
23 | end |
|
24 |
|
24 | ||
|
25 | @config = Grader::Configuration.get_instance |
|
25 | @config = Grader::Configuration.get_instance |
|
26 |
|
26 | ||
|
27 | @room_maker = options[:room_maker] |
|
27 | @room_maker = options[:room_maker] |
|
28 | @reporter = options[:reporter] |
|
28 | @reporter = options[:reporter] |
|
29 | end |
|
29 | end |
|
30 |
|
30 | ||
|
31 | # takes a submission, asks room_maker to produce grading directories, |
|
31 | # takes a submission, asks room_maker to produce grading directories, |
|
32 | # calls grader scripts, and asks reporter to save the result |
|
32 | # calls grader scripts, and asks reporter to save the result |
|
33 | def grade(submission) |
|
33 | def grade(submission) |
|
34 | current_dir = FileUtils.pwd |
|
34 | current_dir = FileUtils.pwd |
|
35 |
|
35 | ||
|
36 | user = submission.user |
|
36 | user = submission.user |
|
37 | problem = submission.problem |
|
37 | problem = submission.problem |
|
38 |
|
38 | ||
|
39 | # TODO: will have to create real exception for this |
|
39 | # TODO: will have to create real exception for this |
|
40 | if user==nil or problem == nil |
|
40 | if user==nil or problem == nil |
|
41 | @reporter.report_error(submission,"Grading error: problem with submission") |
|
41 | @reporter.report_error(submission,"Grading error: problem with submission") |
|
42 | #raise "engine: user or problem is nil" |
|
42 | #raise "engine: user or problem is nil" |
|
43 | end |
|
43 | end |
|
44 |
|
44 | ||
|
45 | # TODO: this is another hack so that output only task can be judged |
|
45 | # TODO: this is another hack so that output only task can be judged |
|
46 | if submission.language!=nil |
|
46 | if submission.language!=nil |
|
47 | language = submission.language.name |
|
47 | language = submission.language.name |
|
48 | lang_ext = submission.language.ext |
|
48 | lang_ext = submission.language.ext |
|
49 | else |
|
49 | else |
|
50 | language = 'c' |
|
50 | language = 'c' |
|
51 | lang_ext = 'c' |
|
51 | lang_ext = 'c' |
|
52 | end |
|
52 | end |
|
53 |
|
53 | ||
|
54 | # This is needed because older version of std-scripts/compile |
|
54 | # This is needed because older version of std-scripts/compile |
|
55 | # only look for c++. |
|
55 | # only look for c++. |
|
56 | if language == 'cpp' |
|
56 | if language == 'cpp' |
|
57 | language = 'c++' |
|
57 | language = 'c++' |
|
58 | end |
|
58 | end |
|
59 |
|
59 | ||
|
60 | # COMMENT: should it be only source.ext? |
|
60 | # COMMENT: should it be only source.ext? |
|
61 | if problem!=nil |
|
61 | if problem!=nil |
|
62 | source_name = "#{problem.name}.#{lang_ext}" |
|
62 | source_name = "#{problem.name}.#{lang_ext}" |
|
63 | else |
|
63 | else |
|
64 | source_name = "source.#{lang_ext}" |
|
64 | source_name = "source.#{lang_ext}" |
|
65 | end |
|
65 | end |
|
66 |
|
66 | ||
|
67 | begin |
|
67 | begin |
|
68 | grading_dir = @room_maker.produce_grading_room(submission) |
|
68 | grading_dir = @room_maker.produce_grading_room(submission) |
|
69 | @room_maker.save_source(submission,source_name) |
|
69 | @room_maker.save_source(submission,source_name) |
|
70 | problem_home = @room_maker.find_problem_home(submission) |
|
70 | problem_home = @room_maker.find_problem_home(submission) |
|
71 |
|
71 | ||
|
72 | # puts "GRADING DIR: #{grading_dir}" |
|
72 | # puts "GRADING DIR: #{grading_dir}" |
|
73 | # puts "PROBLEM DIR: #{problem_home}" |
|
73 | # puts "PROBLEM DIR: #{problem_home}" |
|
74 |
|
74 | ||
|
75 | if !FileTest.exist?(problem_home) |
|
75 | if !FileTest.exist?(problem_home) |
|
76 | raise "No test data." |
|
76 | raise "No test data." |
|
77 | end |
|
77 | end |
|
78 |
|
78 | ||
|
79 | dinit = DirInit::Manager.new(problem_home) |
|
79 | dinit = DirInit::Manager.new(problem_home) |
|
80 |
|
80 | ||
|
81 | dinit.setup do |
|
81 | dinit.setup do |
|
82 | copy_log = copy_script(problem_home) |
|
82 | copy_log = copy_script(problem_home) |
|
83 | save_copy_log(problem_home,copy_log) |
|
83 | save_copy_log(problem_home,copy_log) |
|
84 | end |
|
84 | end |
|
85 |
|
85 | ||
|
86 | call_judge(problem_home,language,grading_dir,source_name) |
|
86 | call_judge(problem_home,language,grading_dir,source_name) |
|
87 |
|
87 | ||
|
88 | @reporter.report(submission,"#{grading_dir}/test-result") |
|
88 | @reporter.report(submission,"#{grading_dir}/test-result") |
|
89 |
|
89 | ||
|
90 | dinit.teardown do |
|
90 | dinit.teardown do |
|
91 | copy_log = load_copy_log(problem_home) |
|
91 | copy_log = load_copy_log(problem_home) |
|
92 | clear_copy_log(problem_home) |
|
92 | clear_copy_log(problem_home) |
|
93 | clear_script(copy_log,problem_home) |
|
93 | clear_script(copy_log,problem_home) |
|
94 | end |
|
94 | end |
|
95 |
|
95 | ||
|
96 | rescue RuntimeError => msg |
|
96 | rescue RuntimeError => msg |
|
97 | @reporter.report_error(submission, msg) |
|
97 | @reporter.report_error(submission, msg) |
|
98 |
|
98 | ||
|
99 | ensure |
|
99 | ensure |
|
100 | @room_maker.clean_up(submission) |
|
100 | @room_maker.clean_up(submission) |
|
101 | Dir.chdir(current_dir) # this is really important |
|
101 | Dir.chdir(current_dir) # this is really important |
|
102 | end |
|
102 | end |
|
103 | end |
|
103 | end |
|
104 |
|
104 | ||
|
105 | protected |
|
105 | protected |
|
106 |
|
106 | ||
|
107 | def talk(str) |
|
107 | def talk(str) |
|
108 | if @config.talkative |
|
108 | if @config.talkative |
|
109 | puts str |
|
109 | puts str |
|
110 | end |
|
110 | end |
|
111 | end |
|
111 | end |
|
112 |
|
112 | ||
|
113 | def call_judge(problem_home,language,grading_dir,fname) |
|
113 | def call_judge(problem_home,language,grading_dir,fname) |
|
114 | ENV['PROBLEM_HOME'] = problem_home |
|
114 | ENV['PROBLEM_HOME'] = problem_home |
|
|
115 | + ENV['RUBYOPT'] = '' | ||
|
115 |
|
116 | ||
|
116 | talk grading_dir |
|
117 | talk grading_dir |
|
117 | Dir.chdir grading_dir |
|
118 | Dir.chdir grading_dir |
|
118 | cmd = "#{problem_home}/script/judge #{language} #{fname}" |
|
119 | cmd = "#{problem_home}/script/judge #{language} #{fname}" |
|
119 | talk "CMD: #{cmd}" |
|
120 | talk "CMD: #{cmd}" |
|
120 | system(cmd) |
|
121 | system(cmd) |
|
121 | end |
|
122 | end |
|
122 |
|
123 | ||
|
123 | def get_std_script_dir |
|
124 | def get_std_script_dir |
|
124 | GRADER_ROOT + '/std-script' |
|
125 | GRADER_ROOT + '/std-script' |
|
125 | end |
|
126 | end |
|
126 |
|
127 | ||
|
127 | def copy_script(problem_home) |
|
128 | def copy_script(problem_home) |
|
128 | script_dir = "#{problem_home}/script" |
|
129 | script_dir = "#{problem_home}/script" |
|
129 | std_script_dir = get_std_script_dir |
|
130 | std_script_dir = get_std_script_dir |
|
130 |
|
131 | ||
|
131 | raise "std-script directory not found" if !FileTest.exist?(std_script_dir) |
|
132 | raise "std-script directory not found" if !FileTest.exist?(std_script_dir) |
|
132 |
|
133 | ||
|
133 | scripts = Dir[std_script_dir + '/*'] |
|
134 | scripts = Dir[std_script_dir + '/*'] |
|
134 |
|
135 | ||
|
135 | copied = [] |
|
136 | copied = [] |
|
136 |
|
137 | ||
|
137 | scripts.each do |s| |
|
138 | scripts.each do |s| |
|
138 | fname = File.basename(s) |
|
139 | fname = File.basename(s) |
|
139 | next if FileTest.directory?(s) |
|
140 | next if FileTest.directory?(s) |
|
140 | if !FileTest.exist?("#{script_dir}/#{fname}") |
|
141 | if !FileTest.exist?("#{script_dir}/#{fname}") |
|
141 | copied << fname |
|
142 | copied << fname |
|
142 | FileUtils.cp(s, "#{script_dir}", :preserve => true) |
|
143 | FileUtils.cp(s, "#{script_dir}", :preserve => true) |
|
143 | end |
|
144 | end |
|
144 | end |
|
145 | end |
|
145 |
|
146 | ||
|
146 | return copied |
|
147 | return copied |
|
147 | end |
|
148 | end |
|
148 |
|
149 | ||
|
149 | def copy_log_filename(problem_home) |
|
150 | def copy_log_filename(problem_home) |
|
150 | return File.join(problem_home, '.scripts_copied') |
|
151 | return File.join(problem_home, '.scripts_copied') |
|
151 | end |
|
152 | end |
|
152 |
|
153 | ||
|
153 | def save_copy_log(problem_home, log) |
|
154 | def save_copy_log(problem_home, log) |
|
154 | f = File.new(copy_log_filename(problem_home),"w") |
|
155 | f = File.new(copy_log_filename(problem_home),"w") |
|
155 | log.each do |fname| |
|
156 | log.each do |fname| |
|
156 | f.write("#{fname}\n") |
|
157 | f.write("#{fname}\n") |
|
157 | end |
|
158 | end |
|
158 | f.close |
|
159 | f.close |
|
159 | end |
|
160 | end |
|
160 |
|
161 | ||
|
161 | def load_copy_log(problem_home) |
|
162 | def load_copy_log(problem_home) |
|
162 | f = File.new(copy_log_filename(problem_home),"r") |
|
163 | f = File.new(copy_log_filename(problem_home),"r") |
|
163 | log = [] |
|
164 | log = [] |
|
164 | f.readlines.each do |line| |
|
165 | f.readlines.each do |line| |
|
165 | log << line.strip |
|
166 | log << line.strip |
|
166 | end |
|
167 | end |
|
167 | f.close |
|
168 | f.close |
|
168 | log |
|
169 | log |
|
169 | end |
|
170 | end |
|
170 |
|
171 | ||
|
171 | def clear_copy_log(problem_home) |
|
172 | def clear_copy_log(problem_home) |
|
172 | File.delete(copy_log_filename(problem_home)) |
|
173 | File.delete(copy_log_filename(problem_home)) |
|
173 | end |
|
174 | end |
|
174 |
|
175 | ||
|
175 | def clear_script(log,problem_home) |
|
176 | def clear_script(log,problem_home) |
|
176 | log.each do |s| |
|
177 | log.each do |s| |
|
177 | FileUtils.rm("#{problem_home}/script/#{s}") |
|
178 | FileUtils.rm("#{problem_home}/script/#{s}") |
|
178 | end |
|
179 | end |
|
179 | end |
|
180 | end |
|
180 |
|
181 | ||
|
181 | def mkdir_if_does_not_exist(dirname) |
|
182 | def mkdir_if_does_not_exist(dirname) |
|
182 | Dir.mkdir(dirname) if !FileTest.exist?(dirname) |
|
183 | Dir.mkdir(dirname) if !FileTest.exist?(dirname) |
|
183 | end |
|
184 | end |
|
184 |
|
185 | ||
|
185 | end |
|
186 | end |
|
186 |
|
187 | ||
|
187 | end |
|
188 | end |
You need to be logged in to leave comments.
Login now