Description:
fix reimport bug when creating existing dirs
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r100:384e1befe70e - - 1 file changed: 16 inserted, 11 deleted

@@ -1,10 +1,9
1 1 #!/usr/bin/ruby
2 2
3 3 require 'erb'
4 - require 'ftools'
5 4 require 'fileutils'
6 5 require File.join(File.dirname(__FILE__),'lib/import_helper')
7 6
8 7 JUDGE_ENVIRONMENTS = [:grading, :exam]
9 8 ENV_INFO = {
10 9 :grading => {
@@ -30,14 +29,14
30 29 File.basename((/(.*)\.in/.match(filename))[1])
31 30 end
32 31 build_testrun_info(num_testruns,filenames,raw_prefix)
33 32 end
34 33
35 34 def copy_testcase(importing_test_dir,fname,dir,i)
36 - File.copy("#{importing_test_dir}/#{fname}.in", "#{input_filename(dir,i)}")
37 - File.copy("#{importing_test_dir}/#{fname}.sol", "#{answer_filename(dir,i)}")
35 + FileUtils.cp("#{importing_test_dir}/#{fname}.in", "#{input_filename(dir,i)}")
36 + FileUtils.cp("#{importing_test_dir}/#{fname}.sol", "#{answer_filename(dir,i)}")
38 37 end
39 38
40 39 def process_options(options)
41 40 i = 3
42 41 while i<ARGV.length
43 42 if ARGV[i]=='-t'
@@ -98,12 +97,18
98 97 return n
99 98 end
100 99 n += 1
101 100 end while true
102 101 end
103 102
103 + def create_dir_if_not_exists(dir)
104 + if ! FileTest.exists? dir
105 + FileUtils.mkdir(dir)
106 + end
107 + end
108 +
104 109 def import_problem(ev_dir, problem, testcase_dir, num_testruns, raw_prefix, check_script, options)
105 110 testrun_info = build_testrun_info_from_dir(num_testruns, testcase_dir, raw_prefix)
106 111
107 112 if !(FileTest.exists? ev_dir)
108 113 puts "Testdata dir (#{ev_dir}) not found."
109 114 return
@@ -111,15 +116,15
111 116
112 117 problem_dir = "#{ev_dir}/#{problem}"
113 118
114 119 # start working
115 120 puts "creating directories"
116 121
117 - File.makedirs("#{problem_dir}")
118 - File.makedirs("#{problem_dir}/script")
119 - File.makedirs("#{problem_dir}/test_cases")
122 + create_dir_if_not_exists("#{problem_dir}")
123 + create_dir_if_not_exists("#{problem_dir}/script")
124 + create_dir_if_not_exists("#{problem_dir}/test_cases")
120 125
121 126 puts "copying testcases"
122 127
123 128 tr_num = 0
124 129
125 130 num_testcases = 0
@@ -130,13 +135,13
130 135
131 136 testrun.each do |testcase_info|
132 137 testcase_num, testcase_fname = testcase_info
133 138
134 139 puts "copy #{testcase_fname} to #{testcase_num}"
135 140
136 - File.makedirs("#{problem_dir}/test_cases/#{testcase_num}")
141 + create_dir_if_not_exists("#{problem_dir}/test_cases/#{testcase_num}")
137 142 copy_testcase("#{testcase_dir}",testcase_fname,"#{problem_dir}/test_cases/#{testcase_num}",testcase_num)
138 143
139 144 num_testcases += 1
140 145 end
141 146 end
142 147
@@ -161,20 +166,20
161 166 check_file = File.open("#{problem_dir}/script/check","w")
162 167 check_file.puts check_wrapper.result binding
163 168 check_file.close
164 169
165 170 File.chmod(0755,"#{problem_dir}/script/check")
166 171
167 - File.copy("#{check_script_fname}", "#{problem_dir}/script/#{script_name}")
172 + FileUtils.cp("#{check_script_fname}", "#{problem_dir}/script/#{script_name}")
168 173 else
169 174 if File.exists?(SCRIPT_DIR + "/templates/check.#{check_script}")
170 175 check_script_fname = SCRIPT_DIR + "/templates/check.#{check_script}"
171 176 else
172 177 check_script_fname = check_script
173 178 end
174 - File.copy("#{check_script_fname}", "#{problem_dir}/script/check")
179 + FileUtils.cp("#{check_script_fname}", "#{problem_dir}/script/check")
175 180 end
176 181
177 182 # generating test_request directory
178 183 puts "generating test_request template"
179 184 FileUtils.mkdir_p("#{ev_dir}/test_request/#{problem}/script")
180 185 FileUtils.mkdir_p("#{ev_dir}/test_request/#{problem}/test_cases/1")
@@ -183,15 +188,15
183 188 test_request_all_test_cfg = ERB.new(template)
184 189
185 190 cfg_file = File.open("#{ev_dir}/test_request/#{problem}/test_cases/all_tests.cfg","w")
186 191 cfg_file.puts test_request_all_test_cfg.result
187 192 cfg_file.close
188 193
189 - File.copy("#{SCRIPT_DIR}/templates/check_empty",
194 + FileUtils.cp("#{SCRIPT_DIR}/templates/check_empty",
190 195 "#{ev_dir}/test_request/#{problem}/script/check")
191 - File.copy("#{SCRIPT_DIR}/templates/answer-1.txt",
196 + FileUtils.cp("#{SCRIPT_DIR}/templates/answer-1.txt",
192 197 "#{ev_dir}/test_request/#{problem}/test_cases/1")
193 198
194 199 puts "done"
195 200 end
196 201
197 202
You need to be logged in to leave comments. Login now