Description:
merge
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r232:da875364b006 - - 2 files changed: 101 inserted, 16 deleted
@@ -0,0 +1,85 | |||
|
1 | + #!/usr/bin/env ruby | |
|
2 | + | |
|
3 | + def config | |
|
4 | + Grader::Configuration.get_instance | |
|
5 | + end | |
|
6 | + | |
|
7 | + def display_manual | |
|
8 | + puts <<USAGE | |
|
9 | + load_testcases | |
|
10 | + using: load_testcases [problem_name ...] | |
|
11 | + problem_name are list of "short name" of the problems | |
|
12 | + | |
|
13 | + options: | |
|
14 | + --dry-run do nothing, just simulate the run | |
|
15 | + --all import all problem. This might take several minutes | |
|
16 | + | |
|
17 | + USAGE | |
|
18 | + end | |
|
19 | + | |
|
20 | + def process_options_and_stop_file | |
|
21 | + | |
|
22 | + # Process 'help' option | |
|
23 | + if (ARGV.length==1) and (/help/.match(ARGV[0])) | |
|
24 | + display_manual | |
|
25 | + exit(0) | |
|
26 | + end | |
|
27 | + | |
|
28 | + #default options | |
|
29 | + options = { | |
|
30 | + :dry_run => false, | |
|
31 | + } | |
|
32 | + | |
|
33 | + options[:dry_run] = (ARGV.delete('--dry') != nil) | |
|
34 | + options[:all] = (ARGV.delete('--all') != nil) | |
|
35 | + | |
|
36 | + return options | |
|
37 | + end | |
|
38 | + | |
|
39 | + def process_problem(prob,dry_run = false) | |
|
40 | + prob.testcases.destroy_all | |
|
41 | + testcases_root = File.expand_path(GRADER_ROOT+"/../ev/#{prob.name}/test_cases/") | |
|
42 | + num = 1 | |
|
43 | + puts "Processing problem #{prob.name}" | |
|
44 | + loop do | |
|
45 | + file_root = testcases_root + "/#{num}/" | |
|
46 | + puts " checking file #{file_root}" | |
|
47 | + break unless File.exists? file_root | |
|
48 | + input = File.read(file_root + "/input-#{num}.txt") | |
|
49 | + answer = File.read(file_root + "/answer-#{num}.txt") | |
|
50 | + puts " got test case ##{num} of size #{input.size} and #{answer.size}" | |
|
51 | + | |
|
52 | + #THIS IS JUST A PLACE HOLDER | |
|
53 | + group = num #this is wrong!!! fix it!! | |
|
54 | + score = 10 | |
|
55 | + #BEWARE | |
|
56 | + | |
|
57 | + prob.testcases.create(input: input,sol: answer, num: num, score:score,group: group) unless dry_run | |
|
58 | + num += 1 | |
|
59 | + end | |
|
60 | + end | |
|
61 | + | |
|
62 | + ######################################### | |
|
63 | + # main program | |
|
64 | + ######################################### | |
|
65 | + | |
|
66 | + options = process_options_and_stop_file | |
|
67 | + | |
|
68 | + # load grader environment | |
|
69 | + GRADER_ENV = 'grading' | |
|
70 | + require File.join(File.dirname(__FILE__),'config/environment') | |
|
71 | + | |
|
72 | + # boot rails, to be able to use the active record | |
|
73 | + RAILS_ENV = config.rails_env | |
|
74 | + require RAILS_ROOT + '/config/environment' | |
|
75 | + | |
|
76 | + if options[:all] | |
|
77 | + Problem.all.each { |prob| process_problem(prob,options[:all]) } | |
|
78 | + else | |
|
79 | + ARGV.each do |name| | |
|
80 | + prob = Problem.find_by(name: name) | |
|
81 | + process_problem(prob,options[:dry_run]) if prob | |
|
82 | + puts "Cannot find the problem #{name}" unless prob | |
|
83 | + end | |
|
84 | + end | |
|
85 | + |
@@ -123,88 +123,88 | |||
|
123 | 123 | create_dir_if_not_exists("#{problem_dir}/script") |
|
124 | 124 | create_dir_if_not_exists("#{problem_dir}/test_cases") |
|
125 | 125 | |
|
126 | 126 | puts "copying testcases" |
|
127 | 127 | |
|
128 | 128 | tr_num = 0 |
|
129 | 129 | |
|
130 | 130 | num_testcases = 0 |
|
131 | 131 | |
|
132 | 132 | testrun_info.each do |testrun| |
|
133 | 133 | tr_num += 1 |
|
134 | 134 | puts "testrun: #{tr_num}" |
|
135 | - | |
|
135 | + | |
|
136 | 136 | testrun.each do |testcase_info| |
|
137 | 137 | testcase_num, testcase_fname = testcase_info |
|
138 | - | |
|
138 | + | |
|
139 | 139 | puts "copy #{testcase_fname} to #{testcase_num}" |
|
140 | - | |
|
140 | + | |
|
141 | 141 | create_dir_if_not_exists("#{problem_dir}/test_cases/#{testcase_num}") |
|
142 | 142 | copy_testcase("#{testcase_dir}",testcase_fname,"#{problem_dir}/test_cases/#{testcase_num}",testcase_num) |
|
143 | - | |
|
143 | + | |
|
144 | 144 | num_testcases += 1 |
|
145 | 145 | end |
|
146 | 146 | end |
|
147 | - | |
|
147 | + | |
|
148 | 148 | # generating all_tests.cfg |
|
149 | 149 | puts "generating testcase config file" |
|
150 | - | |
|
150 | + | |
|
151 | 151 | template = File.open(SCRIPT_DIR + "/templates/all_tests.cfg.erb").read |
|
152 | 152 | all_test_cfg = ERB.new(template) |
|
153 | - | |
|
153 | + | |
|
154 | 154 | cfg_file = File.open("#{problem_dir}/test_cases/all_tests.cfg","w") |
|
155 | 155 | cfg_file.puts all_test_cfg.result binding |
|
156 | 156 | cfg_file.close |
|
157 | - | |
|
157 | + | |
|
158 | 158 | # copy check script |
|
159 | 159 | if res = /^wrapper:(.*)$/.match(check_script) |
|
160 | 160 | # wrapper script |
|
161 | 161 | check_script_fname = res[1] |
|
162 | 162 | script_name = File.basename(check_script_fname) |
|
163 | 163 | check_wrapper_template = File.open(SCRIPT_DIR + "/templates/check_wrapper").read |
|
164 | 164 | check_wrapper = ERB.new(check_wrapper_template) |
|
165 | - | |
|
165 | + | |
|
166 | 166 | check_file = File.open("#{problem_dir}/script/check","w") |
|
167 | 167 | check_file.puts check_wrapper.result binding |
|
168 | 168 | check_file.close |
|
169 | - | |
|
169 | + | |
|
170 | 170 | File.chmod(0755,"#{problem_dir}/script/check") |
|
171 | - | |
|
171 | + | |
|
172 | 172 | FileUtils.cp("#{check_script_fname}", "#{problem_dir}/script/#{script_name}") |
|
173 | 173 | else |
|
174 | 174 | if File.exists?(SCRIPT_DIR + "/templates/check.#{check_script}") |
|
175 | 175 | check_script_fname = SCRIPT_DIR + "/templates/check.#{check_script}" |
|
176 | 176 | else |
|
177 | 177 | check_script_fname = check_script |
|
178 | 178 | end |
|
179 | 179 | FileUtils.cp("#{check_script_fname}", "#{problem_dir}/script/check", :preserve => true) |
|
180 | 180 | end |
|
181 | - | |
|
181 | + | |
|
182 | 182 | # generating test_request directory |
|
183 | 183 | puts "generating test_request template" |
|
184 | 184 | FileUtils.mkdir_p("#{ev_dir}/test_request/#{problem}/script") |
|
185 | 185 | FileUtils.mkdir_p("#{ev_dir}/test_request/#{problem}/test_cases/1") |
|
186 | - | |
|
186 | + | |
|
187 | 187 | template = File.open(SCRIPT_DIR + "/templates/test_request_all_tests.cfg.erb").read |
|
188 | 188 | test_request_all_test_cfg = ERB.new(template) |
|
189 | - | |
|
189 | + | |
|
190 | 190 | cfg_file = File.open("#{ev_dir}/test_request/#{problem}/test_cases/all_tests.cfg","w") |
|
191 | 191 | cfg_file.puts test_request_all_test_cfg.result |
|
192 | 192 | cfg_file.close |
|
193 | - | |
|
193 | + | |
|
194 | 194 | FileUtils.cp("#{SCRIPT_DIR}/templates/check_empty", |
|
195 | 195 | "#{ev_dir}/test_request/#{problem}/script/check") |
|
196 | 196 | FileUtils.cp("#{SCRIPT_DIR}/templates/answer-1.txt", |
|
197 | 197 | "#{ev_dir}/test_request/#{problem}/test_cases/1") |
|
198 | - | |
|
198 | + | |
|
199 | 199 | puts "done" |
|
200 | 200 | end |
|
201 | 201 | |
|
202 | 202 | |
|
203 | 203 | SCRIPT_DIR = File.dirname(__FILE__) |
|
204 | 204 | |
|
205 | 205 | # print usage |
|
206 | 206 | if (ARGV.length < 3) or (ARGV[2][0,1]=="-") |
|
207 | 207 | print_usage |
|
208 | 208 | exit(127) |
|
209 | 209 | end |
|
210 | 210 |
You need to be logged in to leave comments.
Login now