Description:
let import problem clear the testcase folder
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r242:f8ad085b45a7 - - 1 file changed: 5 inserted, 2 deleted

@@ -55,118 +55,121
55 55 puts "using: import_problem_new name dir check [options]
56 56
57 57 where: name = problem_name (put '-' (dash) to use dir name)
58 58 dir = importing testcase directory
59 59 check = check script, which can be
60 60 'integer', 'text' (for standard script),
61 61 path_to_your_script, or
62 62 'wrapper:(path_to_your_wrapped_script)'
63 63 options: -t time-limit (in seconds)
64 64 -m memory-limit (in megabytes)
65 65
66 66 The script looks at test data files in the dir of the forms: *.in and
67 67 *.sol and import them to the evaluation dir for their environment,
68 68 based on their prefixes.
69 69
70 70 Currently supporting environments are:"
71 71
72 72 JUDGE_ENVIRONMENTS.each do |env|
73 73 prefix = ENV_INFO[env][:raw_prefix]
74 74 prefix = 'no prefix' if prefix==''
75 75 puts " * #{env}"
76 76 puts " import to: #{ENV_INFO[env][:ev_dir]}"
77 77 puts " prefix with: #{prefix} (e.g., #{ENV_INFO[env][:raw_prefix]}1.in, #{ENV_INFO[env][:raw_prefix]}5a.sol)"
78 78 end
79 79
80 80 puts"
81 81 For each environment, the script
82 82 * creates a directory for a problem in ev dir of that environment,
83 83 * copies testdata in the old format and create standard testcase config file
84 84 * copies a check script for grading
85 85 * creates a test_request template in the ev dir + '/test_request'
86 86
87 87 For wrapped checked script see comment in templates/check_wrapper for
88 88 information."
89 89 end
90 90
91 91 def count_testruns(testcase_dir, raw_prefix)
92 92 n = 0
93 93 begin
94 94 # check for test case n+1
95 95 if ((Dir["#{testcase_dir}/#{raw_prefix}#{n+1}.in"].length==0) and
96 96 (Dir["#{testcase_dir}/#{raw_prefix}#{n+1}[a-z].in"].length==0))
97 97 return n
98 98 end
99 99 n += 1
100 100 end while true
101 101 end
102 102
103 - def create_dir_if_not_exists(dir)
103 + def create_dir_if_not_exists(dir, options = {} )
104 104 if ! FileTest.exists? dir
105 105 FileUtils.mkdir(dir)
106 106 end
107 +
108 + FileUtils.rm_rf(Dir.glob("#{dir}/*")) if options[:clear]
107 109 end
108 110
109 111 def import_problem(ev_dir, problem, testcase_dir, num_testruns, raw_prefix, check_script, options)
110 112 testrun_info = build_testrun_info_from_dir(num_testruns, testcase_dir, raw_prefix)
111 113
112 114 if !(FileTest.exists? ev_dir)
113 115 puts "Testdata dir (#{ev_dir}) not found."
114 116 return
115 117 end
116 118
117 119 problem_dir = "#{ev_dir}/#{problem}"
118 120
119 121 # start working
120 122 puts "creating directories"
121 123
122 124 create_dir_if_not_exists("#{problem_dir}")
123 125 create_dir_if_not_exists("#{problem_dir}/script")
124 - create_dir_if_not_exists("#{problem_dir}/test_cases")
126 + create_dir_if_not_exists("#{problem_dir}/test_cases",clear: true)
127 + # clear test cases directory
125 128
126 129 puts "copying testcases"
127 130
128 131 tr_num = 0
129 132
130 133 num_testcases = 0
131 134
132 135 testrun_info.each do |testrun|
133 136 tr_num += 1
134 137 puts "testrun: #{tr_num}"
135 138
136 139 testrun.each do |testcase_info|
137 140 testcase_num, testcase_fname = testcase_info
138 141
139 142 puts "copy #{testcase_fname} to #{testcase_num}"
140 143
141 144 create_dir_if_not_exists("#{problem_dir}/test_cases/#{testcase_num}")
142 145 copy_testcase("#{testcase_dir}",testcase_fname,"#{problem_dir}/test_cases/#{testcase_num}",testcase_num)
143 146
144 147 num_testcases += 1
145 148 end
146 149 end
147 150
148 151 #also include any .txt files
149 152 Dir.glob("#{testcase_dir}/*.txt") do |file|
150 153 puts "copy data file #{file}"
151 154 FileUtils.cp(file,"#{problem_dir}")
152 155 end
153 156
154 157 # generating all_tests.cfg
155 158 puts "generating testcase config file"
156 159
157 160 template = File.open(SCRIPT_DIR + "/templates/all_tests.cfg.erb").read
158 161 all_test_cfg = ERB.new(template)
159 162
160 163 cfg_file = File.open("#{problem_dir}/test_cases/all_tests.cfg","w")
161 164 cfg_file.puts all_test_cfg.result binding
162 165 cfg_file.close
163 166
164 167 # copy check script
165 168 if res = /^wrapper:(.*)$/.match(check_script)
166 169 # wrapper script
167 170 check_script_fname = res[1]
168 171 script_name = File.basename(check_script_fname)
169 172 check_wrapper_template = File.open(SCRIPT_DIR + "/templates/check_wrapper").read
170 173 check_wrapper = ERB.new(check_wrapper_template)
171 174
172 175 check_file = File.open("#{problem_dir}/script/check","w")
You need to be logged in to leave comments. Login now