Description:
translates test_request input/output file paths for remote grading test_request
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r117:cc3e1102f8c6 - - 5 files changed: 35 inserted, 2 deleted

@@ -13,8 +13,11
13 config.report_grader = true
13 config.report_grader = true
14
14
15 config.test_request_input_base_dir = RAILS_ROOT + "/data/test_request/input"
15 config.test_request_input_base_dir = RAILS_ROOT + "/data/test_request/input"
16 config.test_request_output_base_dir = RAILS_ROOT + "/data/test_request/output"
16 config.test_request_output_base_dir = RAILS_ROOT + "/data/test_request/output"
17 config.test_request_problem_templates_dir = config.problems_dir + "/test_request"
17 config.test_request_problem_templates_dir = config.problems_dir + "/test_request"
18
18
19 + # change this if you want the path on the output to be translated
20 + config.test_request_org_output_base_dir = config.test_request_output_base_dir
21 +
19 config.comment_report_style = :short
22 config.comment_report_style = :short
20 end
23 end
@@ -12,8 +12,11
12 config.report_grader = true
12 config.report_grader = true
13
13
14 config.test_request_input_base_dir = RAILS_ROOT + "/data/test_request/input"
14 config.test_request_input_base_dir = RAILS_ROOT + "/data/test_request/input"
15 config.test_request_output_base_dir = RAILS_ROOT + "/data/test_request/output"
15 config.test_request_output_base_dir = RAILS_ROOT + "/data/test_request/output"
16 config.test_request_problem_templates_dir = config.problems_dir + "/test_request"
16 config.test_request_problem_templates_dir = config.problems_dir + "/test_request"
17
17
18 + # change this if you want the path on the output to be translated
19 + config.test_request_org_output_base_dir = config.test_request_output_base_dir
20 +
18 config.comment_report_style = :full
21 config.comment_report_style = :full
19 end
22 end
@@ -14,12 +14,15
14 config.comment_report_style = :full
14 config.comment_report_style = :full
15
15
16 config.test_request_input_base_dir = GRADER_ROOT + "/test/data/test_request/input"
16 config.test_request_input_base_dir = GRADER_ROOT + "/test/data/test_request/input"
17 config.test_request_output_base_dir = GRADER_ROOT + "/test/sandbox/test_request/output"
17 config.test_request_output_base_dir = GRADER_ROOT + "/test/sandbox/test_request/output"
18 config.test_request_problem_templates_dir = GRADER_ROOT + "/test/data/test_request/problems"
18 config.test_request_problem_templates_dir = GRADER_ROOT + "/test/data/test_request/problems"
19
19
20 + # change this if you want the path on the output to be translated
21 + config.test_request_org_output_base_dir = config.test_request_output_base_dir
22 +
20 #
23 #
21 # These options are for testing
24 # These options are for testing
22 #
25 #
23 class << config
26 class << config
24 attr_accessor :test_data_dir, :test_sandbox_dir
27 attr_accessor :test_data_dir, :test_sandbox_dir
25 end
28 end
@@ -30,12 +30,16
30
30
31 # These are directories related to the test interface.
31 # These are directories related to the test interface.
32 attr_accessor :test_request_input_base_dir
32 attr_accessor :test_request_input_base_dir
33 attr_accessor :test_request_output_base_dir
33 attr_accessor :test_request_output_base_dir
34 attr_accessor :test_request_problem_templates_dir
34 attr_accessor :test_request_problem_templates_dir
35
35
36 + # this is for linking output from test request
37 + # TODO: find a cleaner way to do this.
38 + attr_accessor :test_request_org_output_base_dir
39 +
36 # Comment received from the grading script will be filtered
40 # Comment received from the grading script will be filtered
37 # through Configuration#report_comment. How this method behave
41 # through Configuration#report_comment. How this method behave
38 # depends on this option; right now only two formats, :short and
42 # depends on this option; right now only two formats, :short and
39 # :long
43 # :long
40 attr_accessor :comment_report_style
44 attr_accessor :comment_report_style
41
45
@@ -2,12 +2,18
2 # This part contains various test_request helpers for interfacing
2 # This part contains various test_request helpers for interfacing
3 # with Grader::Engine. There are TestRequestRoomMaker and
3 # with Grader::Engine. There are TestRequestRoomMaker and
4 # TestRequestReporter.
4 # TestRequestReporter.
5
5
6 module Grader
6 module Grader
7
7
8 + def self.translate_filepath(filename, marker, new_base_path)
9 + p = filename.index(marker)
10 + end_path = filename[(p+marker.length)..-1]
11 + return new_base_path + end_path
12 + end
13 +
8 def self.link_or_copy(src, des)
14 def self.link_or_copy(src, des)
9 begin
15 begin
10 FileUtils.ln_s(src, des)
16 FileUtils.ln_s(src, des)
11 rescue NotImplementedError
17 rescue NotImplementedError
12 FileUtils.cp(src,des)
18 FileUtils.cp(src,des)
13 end
19 end
@@ -101,14 +107,21
101 def copy_problem_template(template_dir,problem_home)
107 def copy_problem_template(template_dir,problem_home)
102 Grader::call_and_log("Test Request: cannot copy problem template") {
108 Grader::call_and_log("Test Request: cannot copy problem template") {
103 FileUtils.cp_r("#{template_dir}/.","#{problem_home}")
109 FileUtils.cp_r("#{template_dir}/.","#{problem_home}")
104 }
110 }
105 end
111 end
106
112
113 + def translate_input_filename(filename)
114 + return Grader::translate_filepath(filename,
115 + 'input',
116 + @config.test_request_input_base_dir)
117 + end
118 +
107 def link_input_file(test_request, problem_home)
119 def link_input_file(test_request, problem_home)
108 - input_fname = "#{test_request.input_file_name}"
120 + input_fname = translate_input_filename(test_request.input_file_name)
121 +
109 if !File.exists?(input_fname)
122 if !File.exists?(input_fname)
110 raise "Test Request: input file not found."
123 raise "Test Request: input file not found."
111 end
124 end
112
125
113 input_fname_problem_home = "#{problem_home}/test_cases/1/input-1.txt"
126 input_fname_problem_home = "#{problem_home}/test_cases/1/input-1.txt"
114 if File.exists?(input_fname_problem_home)
127 if File.exists?(input_fname_problem_home)
@@ -211,14 +224,15
211 :memory_usage => memory_used
224 :memory_usage => memory_used
212 }
225 }
213 end
226 end
214
227
215 def save_result(test_request,result)
228 def save_result(test_request,result)
216 if result[:output_file_name]!=nil
229 if result[:output_file_name]!=nil
217 - test_request.output_file_name = link_output_file(test_request,
230 + org_filename = link_output_file(test_request,
218 result[:output_file_name])
231 result[:output_file_name])
232 + test_request.output_file_name = translate_output_filename(org_filename)
219 end
233 end
220 test_request.graded_at = Time.now
234 test_request.graded_at = Time.now
221 test_request.compiler_message = (result[:cmp_msg] or '')
235 test_request.compiler_message = (result[:cmp_msg] or '')
222 test_request.grader_comment = (result[:comment] or '')
236 test_request.grader_comment = (result[:comment] or '')
223 if result[:running_stat]!=nil
237 if result[:running_stat]!=nil
224 test_request.running_stat = (result[:running_stat][:msg] or '')
238 test_request.running_stat = (result[:running_stat][:msg] or '')
@@ -229,12 +243,18
229 test_request.running_stat = ''
243 test_request.running_stat = ''
230 end
244 end
231 test_request.save
245 test_request.save
232 end
246 end
233
247
234 protected
248 protected
249 + def translate_output_filename(filename)
250 + return Grader::translate_filepath(filename,
251 + 'output',
252 + @config.test_request_org_output_base_dir)
253 + end
254 +
235 def link_output_file(test_request, fname)
255 def link_output_file(test_request, fname)
236 target_file_name = random_output_file_name(test_request.user,
256 target_file_name = random_output_file_name(test_request.user,
237 test_request.problem)
257 test_request.problem)
238 FileUtils.mkdir_p(File.dirname(target_file_name))
258 FileUtils.mkdir_p(File.dirname(target_file_name))
239 Grader::link_or_copy("#{fname}", "#{target_file_name}")
259 Grader::link_or_copy("#{fname}", "#{target_file_name}")
240 return target_file_name
260 return target_file_name
You need to be logged in to leave comments. Login now