Description:
merge
Commit status:
[Not Reviewed]
References:
merge java
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

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 +
@@ -132,29 +132,29
132 testrun_info.each do |testrun|
132 testrun_info.each do |testrun|
133 tr_num += 1
133 tr_num += 1
134 puts "testrun: #{tr_num}"
134 puts "testrun: #{tr_num}"
135 -
135 +
136 testrun.each do |testcase_info|
136 testrun.each do |testcase_info|
137 testcase_num, testcase_fname = testcase_info
137 testcase_num, testcase_fname = testcase_info
138 -
138 +
139 puts "copy #{testcase_fname} to #{testcase_num}"
139 puts "copy #{testcase_fname} to #{testcase_num}"
140 -
140 +
141 create_dir_if_not_exists("#{problem_dir}/test_cases/#{testcase_num}")
141 create_dir_if_not_exists("#{problem_dir}/test_cases/#{testcase_num}")
142 copy_testcase("#{testcase_dir}",testcase_fname,"#{problem_dir}/test_cases/#{testcase_num}",testcase_num)
142 copy_testcase("#{testcase_dir}",testcase_fname,"#{problem_dir}/test_cases/#{testcase_num}",testcase_num)
143 -
143 +
144 num_testcases += 1
144 num_testcases += 1
145 end
145 end
146 end
146 end
147 -
147 +
148 # generating all_tests.cfg
148 # generating all_tests.cfg
149 puts "generating testcase config file"
149 puts "generating testcase config file"
150 -
150 +
151 template = File.open(SCRIPT_DIR + "/templates/all_tests.cfg.erb").read
151 template = File.open(SCRIPT_DIR + "/templates/all_tests.cfg.erb").read
152 all_test_cfg = ERB.new(template)
152 all_test_cfg = ERB.new(template)
153 -
153 +
154 cfg_file = File.open("#{problem_dir}/test_cases/all_tests.cfg","w")
154 cfg_file = File.open("#{problem_dir}/test_cases/all_tests.cfg","w")
155 cfg_file.puts all_test_cfg.result binding
155 cfg_file.puts all_test_cfg.result binding
156 cfg_file.close
156 cfg_file.close
157 -
157 +
158 # copy check script
158 # copy check script
159 if res = /^wrapper:(.*)$/.match(check_script)
159 if res = /^wrapper:(.*)$/.match(check_script)
160 # wrapper script
160 # wrapper script
@@ -162,13 +162,13
162 script_name = File.basename(check_script_fname)
162 script_name = File.basename(check_script_fname)
163 check_wrapper_template = File.open(SCRIPT_DIR + "/templates/check_wrapper").read
163 check_wrapper_template = File.open(SCRIPT_DIR + "/templates/check_wrapper").read
164 check_wrapper = ERB.new(check_wrapper_template)
164 check_wrapper = ERB.new(check_wrapper_template)
165 -
165 +
166 check_file = File.open("#{problem_dir}/script/check","w")
166 check_file = File.open("#{problem_dir}/script/check","w")
167 check_file.puts check_wrapper.result binding
167 check_file.puts check_wrapper.result binding
168 check_file.close
168 check_file.close
169 -
169 +
170 File.chmod(0755,"#{problem_dir}/script/check")
170 File.chmod(0755,"#{problem_dir}/script/check")
171 -
171 +
172 FileUtils.cp("#{check_script_fname}", "#{problem_dir}/script/#{script_name}")
172 FileUtils.cp("#{check_script_fname}", "#{problem_dir}/script/#{script_name}")
173 else
173 else
174 if File.exists?(SCRIPT_DIR + "/templates/check.#{check_script}")
174 if File.exists?(SCRIPT_DIR + "/templates/check.#{check_script}")
@@ -178,24 +178,24
178 end
178 end
179 FileUtils.cp("#{check_script_fname}", "#{problem_dir}/script/check", :preserve => true)
179 FileUtils.cp("#{check_script_fname}", "#{problem_dir}/script/check", :preserve => true)
180 end
180 end
181 -
181 +
182 # generating test_request directory
182 # generating test_request directory
183 puts "generating test_request template"
183 puts "generating test_request template"
184 FileUtils.mkdir_p("#{ev_dir}/test_request/#{problem}/script")
184 FileUtils.mkdir_p("#{ev_dir}/test_request/#{problem}/script")
185 FileUtils.mkdir_p("#{ev_dir}/test_request/#{problem}/test_cases/1")
185 FileUtils.mkdir_p("#{ev_dir}/test_request/#{problem}/test_cases/1")
186 -
186 +
187 template = File.open(SCRIPT_DIR + "/templates/test_request_all_tests.cfg.erb").read
187 template = File.open(SCRIPT_DIR + "/templates/test_request_all_tests.cfg.erb").read
188 test_request_all_test_cfg = ERB.new(template)
188 test_request_all_test_cfg = ERB.new(template)
189 -
189 +
190 cfg_file = File.open("#{ev_dir}/test_request/#{problem}/test_cases/all_tests.cfg","w")
190 cfg_file = File.open("#{ev_dir}/test_request/#{problem}/test_cases/all_tests.cfg","w")
191 cfg_file.puts test_request_all_test_cfg.result
191 cfg_file.puts test_request_all_test_cfg.result
192 cfg_file.close
192 cfg_file.close
193 -
193 +
194 FileUtils.cp("#{SCRIPT_DIR}/templates/check_empty",
194 FileUtils.cp("#{SCRIPT_DIR}/templates/check_empty",
195 "#{ev_dir}/test_request/#{problem}/script/check")
195 "#{ev_dir}/test_request/#{problem}/script/check")
196 FileUtils.cp("#{SCRIPT_DIR}/templates/answer-1.txt",
196 FileUtils.cp("#{SCRIPT_DIR}/templates/answer-1.txt",
197 "#{ev_dir}/test_request/#{problem}/test_cases/1")
197 "#{ev_dir}/test_request/#{problem}/test_cases/1")
198 -
198 +
199 puts "done"
199 puts "done"
200 end
200 end
201
201
You need to be logged in to leave comments. Login now