Description:
[grader] added check_wrapper
git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@111 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r28:b806077acf3a - - 2 files changed: 65 inserted, 4 deleted
@@ -0,0 +1,45 | |||||
|
|
1 | + #!/usr/bin/ruby | ||
|
|
2 | + | ||
|
|
3 | + # | ||
|
|
4 | + # This is a check script wrapper. It read all required information | ||
|
|
5 | + # and call a real check script call REAL_CHECK_SCRIPT in directory | ||
|
|
6 | + # [problem_home]/script | ||
|
|
7 | + # | ||
|
|
8 | + | ||
|
|
9 | + REAL_CHECK_SCRIPT = "<%= script_name %>" | ||
|
|
10 | + | ||
|
|
11 | + # The REAL_CHECK_SCRIPT is called with: | ||
|
|
12 | + # | ||
|
|
13 | + # (script) <lang> <test-num> <in-file> <out-file> <ans-file> <full-score> | ||
|
|
14 | + # | ||
|
|
15 | + # and REAL_CHECK_SCRIPT's output to standard out is redirected to | ||
|
|
16 | + # 'check_result' as required by normal check script. | ||
|
|
17 | + | ||
|
|
18 | + problem_home = ENV['PROBLEM_HOME'] | ||
|
|
19 | + require "#{problem_home}/script/test_dsl.rb" | ||
|
|
20 | + | ||
|
|
21 | + if ARGV.length < 2 | ||
|
|
22 | + puts "Usage: check <language> <test-number> [<output-file>]" | ||
|
|
23 | + exit(0) | ||
|
|
24 | + end | ||
|
|
25 | + | ||
|
|
26 | + language = ARGV[0] | ||
|
|
27 | + test_num = ARGV[1].to_i | ||
|
|
28 | + if ARGV.length >= 3 | ||
|
|
29 | + output_file_name = ARGV[2] | ||
|
|
30 | + else | ||
|
|
31 | + output_file_name = "output.txt" | ||
|
|
32 | + end | ||
|
|
33 | + | ||
|
|
34 | + load "#{problem_home}/test_cases/all_tests.cfg" | ||
|
|
35 | + problem = Problem.get_instance | ||
|
|
36 | + | ||
|
|
37 | + answer_file_name = File.new("#{problem_home}/test_cases/#{test_num}/answer-#{test_num}.txt") | ||
|
|
38 | + input_file_name = File.new("#{problem_home}/test_cases/#{test_num}/input-#{test_num}.txt") | ||
|
|
39 | + | ||
|
|
40 | + score = Problem.get_score(test_num) | ||
|
|
41 | + | ||
|
|
42 | + cmd = "#{problem_home}/script/#{REAL_CHECK_SCRIPT} " + | ||
|
|
43 | + "#{language} #{test_num} #{input_file_name} #{output_file_name} " + | ||
|
|
44 | + "#{answer_file_name} #{score} > check_result" | ||
|
|
45 | + |
@@ -91,18 +91,34 | |||||
|
91 | cfg_file = File.open("#{problem}/test_cases/all_tests.cfg","w") |
|
91 | cfg_file = File.open("#{problem}/test_cases/all_tests.cfg","w") |
|
92 | cfg_file.puts all_test_cfg.result |
|
92 | cfg_file.puts all_test_cfg.result |
|
93 | cfg_file.close |
|
93 | cfg_file.close |
|
94 |
|
94 | ||
|
95 |
|
95 | ||
|
96 | # copy check script |
|
96 | # copy check script |
|
97 | - if File.exists?(SCRIPT_DIR + "/templates/check.#{check_script}") |
|
97 | + if res = /^wrapper:(.*)$/.match(check_script) |
|
98 | - check_script_fname = SCRIPT_DIR + "/templates/check.#{check_script}" |
|
98 | + # wrapper script |
|
|
99 | + check_script_fname = res[1] | ||
|
|
100 | + script_name = File.basename(check_script_fname) | ||
|
|
101 | + check_wrapper_template = File.open(SCRIPT_DIR + "/templates/check_wrapper") | ||
|
|
102 | + check_wrapper = ERB.new(template) | ||
|
|
103 | + | ||
|
|
104 | + check_file = File.open("#{problem}/script/check","w") | ||
|
|
105 | + check_file.puts check_wrapper | ||
|
|
106 | + check_file.close | ||
|
|
107 | + | ||
|
|
108 | + File.chmod(0755,"#{problem}/script/check") | ||
|
|
109 | + | ||
|
|
110 | + system("cp #{check_script_fname} #{problem}/script/#{script_name}") | ||
|
99 | else |
|
111 | else |
|
100 | - check_script_fname = check_script |
|
112 | + if File.exists?(SCRIPT_DIR + "/templates/check.#{check_script}") |
|
|
113 | + check_script_fname = SCRIPT_DIR + "/templates/check.#{check_script}" | ||
|
|
114 | + else | ||
|
|
115 | + check_script_fname = check_script | ||
|
|
116 | + end | ||
|
|
117 | + system("cp #{check_script_fname} #{problem}/script/check") | ||
|
101 | end |
|
118 | end |
|
102 | - system("cp #{check_script_fname} #{problem}/script/check") |
|
||
|
103 |
|
119 | ||
|
104 | # generating test_request directory |
|
120 | # generating test_request directory |
|
105 | puts "generating test_request template" |
|
121 | puts "generating test_request template" |
|
106 | FileUtils.mkdir_p("test_request/#{problem}/script") |
|
122 | FileUtils.mkdir_p("test_request/#{problem}/script") |
|
107 | FileUtils.mkdir_p("test_request/#{problem}/test_cases/1") |
|
123 | FileUtils.mkdir_p("test_request/#{problem}/test_cases/1") |
|
108 |
|
124 |
You need to be logged in to leave comments.
Login now