Description:
removed 'system' from grader, grader_id, import_problem
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r99:f439789e790b - - 3 files changed: 14 inserted, 32 deleted
@@ -6,25 +6,25 | |||
|
6 | 6 | else |
|
7 | 7 | File.open(File.dirname(__FILE__) + "/stop.#{id}",'w').close |
|
8 | 8 | end |
|
9 | 9 | end |
|
10 | 10 | |
|
11 | 11 | def check_stopfile |
|
12 | 12 | FileTest.exist?(File.dirname(__FILE__) + "/stop.all") or |
|
13 | 13 | FileTest.exist?(File.dirname(__FILE__) + "/stop.#{Process.pid}") |
|
14 | 14 | end |
|
15 | 15 | |
|
16 | 16 | def clear_stopfile |
|
17 | 17 | if FileTest.exist?(File.dirname(__FILE__) + "/stop.#{Process.pid}") |
|
18 |
- |
|
|
18 | + File.delete(File.dirname(__FILE__) + "/stop.#{Process.pid}") | |
|
19 | 19 | end |
|
20 | 20 | end |
|
21 | 21 | |
|
22 | 22 | def config |
|
23 | 23 | Grader::Configuration.get_instance |
|
24 | 24 | end |
|
25 | 25 | |
|
26 | 26 | def log_file_name |
|
27 | 27 | if !File.exists?(config.log_dir) |
|
28 | 28 | raise "Log directory does not exist: #{config.log_dir}" |
|
29 | 29 | end |
|
30 | 30 | config.log_dir + |
@@ -1,27 +1,20 | |||
|
1 | 1 | #!/usr/bin/ruby |
|
2 | 2 | |
|
3 | 3 | def talk(str) |
|
4 | 4 | if TALKATIVE |
|
5 | 5 | puts str |
|
6 | 6 | end |
|
7 | 7 | end |
|
8 | 8 | |
|
9 | - def execute(command, error_message="") | |
|
10 | - if not system(command) | |
|
11 | - puts "ERROR: #{error_message}" | |
|
12 | - exit(127) | |
|
13 | - end | |
|
14 | - end | |
|
15 | - | |
|
16 | 9 | def save_source(submission,dir,fname) |
|
17 | 10 | f = File.open("#{dir}/#{fname}","w") |
|
18 | 11 | f.write(submission.source) |
|
19 | 12 | f.close |
|
20 | 13 | end |
|
21 | 14 | |
|
22 | 15 | def call_judge(problem_home,language,problem_out_dir,fname) |
|
23 | 16 | ENV['PROBLEM_HOME'] = problem_home |
|
24 | 17 | Dir.chdir problem_out_dir |
|
25 | 18 | cmd = "#{problem_home}/script/judge #{language} #{fname}" |
|
26 | 19 | # puts "CMD: #{cmd}" |
|
27 | 20 | system(cmd) |
@@ -72,39 +65,25 | |||
|
72 | 65 | |
|
73 | 66 | problem_out_dir = "#{user_dir}/#{problem.name}" |
|
74 | 67 | Dir.mkdir(problem_out_dir) if !FileTest.exist?(problem_out_dir) |
|
75 | 68 | |
|
76 | 69 | problem_home = "#{PROBLEMS_DIR}/#{problem.name}" |
|
77 | 70 | source_name = "#{problem.name}.#{lang_ext}" |
|
78 | 71 | |
|
79 | 72 | save_source(sub,problem_out_dir,source_name) |
|
80 | 73 | call_judge(problem_home,language,problem_out_dir,source_name) |
|
81 | 74 | save_result(sub,read_result("#{problem_out_dir}/test-result")) |
|
82 | 75 | end |
|
83 | 76 | |
|
84 | - def stop_grader | |
|
85 | - File.open(File.dirname(__FILE__) + '/stop','w') | |
|
86 | - end | |
|
87 | - | |
|
88 | - def check_stopfile | |
|
89 | - FileTest.exist?(File.dirname(__FILE__) + '/stop') | |
|
90 | - end | |
|
91 | - | |
|
92 | - def clear_stopfile | |
|
93 | - system("rm " + File.dirname(__FILE__) + '/stop') | |
|
94 | - end | |
|
95 | - | |
|
96 | 77 | # reading environment and options |
|
97 | 78 | GRADER_ENV = 'exam' |
|
98 | 79 | puts "environment: #{GRADER_ENV}" |
|
99 | 80 | require File.dirname(__FILE__) + "/environment.rb" |
|
100 | 81 | |
|
101 | 82 | #main program |
|
102 | 83 | talk 'Reading rails environment' |
|
103 | 84 | |
|
104 | 85 | RAILS_ENV = 'development' |
|
105 | 86 | require RAILS_APP_DIR + '/config/environment' |
|
106 | 87 | |
|
107 | 88 | current_dir = `pwd` |
|
108 | 89 | grade(ARGV[0].to_i) |
|
109 | - | |
|
110 | - |
@@ -1,15 +1,16 | |||
|
1 | 1 | #!/usr/bin/ruby |
|
2 | 2 | |
|
3 | 3 | require 'erb' |
|
4 | + require 'ftools' | |
|
4 | 5 | require 'fileutils' |
|
5 | 6 | require File.join(File.dirname(__FILE__),'lib/import_helper') |
|
6 | 7 | |
|
7 | 8 | JUDGE_ENVIRONMENTS = [:grading, :exam] |
|
8 | 9 | ENV_INFO = { |
|
9 | 10 | :grading => { |
|
10 | 11 | :ev_dir => 'ev', |
|
11 | 12 | :raw_prefix => '', |
|
12 | 13 | }, |
|
13 | 14 | :exam => { |
|
14 | 15 | :ev_dir => 'ev-exam', |
|
15 | 16 | :raw_prefix => 'ex.', |
@@ -23,26 +24,26 | |||
|
23 | 24 | def answer_filename(dir,i) |
|
24 | 25 | "#{dir}/answer-#{i}.txt" |
|
25 | 26 | end |
|
26 | 27 | |
|
27 | 28 | def build_testrun_info_from_dir(num_testruns, importing_test_dir, raw_prefix='') |
|
28 | 29 | filenames = Dir["#{importing_test_dir}/#{raw_prefix}*.in"].collect do |filename| |
|
29 | 30 | File.basename((/(.*)\.in/.match(filename))[1]) |
|
30 | 31 | end |
|
31 | 32 | build_testrun_info(num_testruns,filenames,raw_prefix) |
|
32 | 33 | end |
|
33 | 34 | |
|
34 | 35 | def copy_testcase(importing_test_dir,fname,dir,i) |
|
35 |
- |
|
|
36 |
- |
|
|
36 | + File.copy("#{importing_test_dir}/#{fname}.in", "#{input_filename(dir,i)}") | |
|
37 | + File.copy("#{importing_test_dir}/#{fname}.sol", "#{answer_filename(dir,i)}") | |
|
37 | 38 | end |
|
38 | 39 | |
|
39 | 40 | def process_options(options) |
|
40 | 41 | i = 3 |
|
41 | 42 | while i<ARGV.length |
|
42 | 43 | if ARGV[i]=='-t' |
|
43 | 44 | options[:time_limit] = ARGV[i+1].to_f if ARGV.length>i+1 |
|
44 | 45 | i += 1 |
|
45 | 46 | end |
|
46 | 47 | if ARGV[i]=='-m' |
|
47 | 48 | options[:mem_limit] = ARGV[i+1].to_i if ARGV.length>i+1 |
|
48 | 49 | i += 1 |
@@ -104,44 +105,44 | |||
|
104 | 105 | testrun_info = build_testrun_info_from_dir(num_testruns, testcase_dir, raw_prefix) |
|
105 | 106 | |
|
106 | 107 | if !(FileTest.exists? ev_dir) |
|
107 | 108 | puts "Testdata dir (#{ev_dir}) not found." |
|
108 | 109 | return |
|
109 | 110 | end |
|
110 | 111 | |
|
111 | 112 | problem_dir = "#{ev_dir}/#{problem}" |
|
112 | 113 | |
|
113 | 114 | # start working |
|
114 | 115 | puts "creating directories" |
|
115 | 116 | |
|
116 |
- |
|
|
117 |
- |
|
|
118 |
- |
|
|
117 | + File.makedirs("#{problem_dir}") | |
|
118 | + File.makedirs("#{problem_dir}/script") | |
|
119 | + File.makedirs("#{problem_dir}/test_cases") | |
|
119 | 120 | |
|
120 | 121 | puts "copying testcases" |
|
121 | 122 | |
|
122 | 123 | tr_num = 0 |
|
123 | 124 | |
|
124 | 125 | num_testcases = 0 |
|
125 | 126 | |
|
126 | 127 | testrun_info.each do |testrun| |
|
127 | 128 | tr_num += 1 |
|
128 | 129 | puts "testrun: #{tr_num}" |
|
129 | 130 | |
|
130 | 131 | testrun.each do |testcase_info| |
|
131 | 132 | testcase_num, testcase_fname = testcase_info |
|
132 | 133 | |
|
133 | 134 | puts "copy #{testcase_fname} to #{testcase_num}" |
|
134 | 135 | |
|
135 |
- |
|
|
136 | + File.makedirs("#{problem_dir}/test_cases/#{testcase_num}") | |
|
136 | 137 | copy_testcase("#{testcase_dir}",testcase_fname,"#{problem_dir}/test_cases/#{testcase_num}",testcase_num) |
|
137 | 138 | |
|
138 | 139 | num_testcases += 1 |
|
139 | 140 | end |
|
140 | 141 | end |
|
141 | 142 | |
|
142 | 143 | # generating all_tests.cfg |
|
143 | 144 | puts "generating testcase config file" |
|
144 | 145 | |
|
145 | 146 | template = File.open(SCRIPT_DIR + "/templates/all_tests.cfg.erb").read |
|
146 | 147 | all_test_cfg = ERB.new(template) |
|
147 | 148 | |
@@ -154,48 +155,50 | |||
|
154 | 155 | # wrapper script |
|
155 | 156 | check_script_fname = res[1] |
|
156 | 157 | script_name = File.basename(check_script_fname) |
|
157 | 158 | check_wrapper_template = File.open(SCRIPT_DIR + "/templates/check_wrapper").read |
|
158 | 159 | check_wrapper = ERB.new(check_wrapper_template) |
|
159 | 160 | |
|
160 | 161 | check_file = File.open("#{problem_dir}/script/check","w") |
|
161 | 162 | check_file.puts check_wrapper.result binding |
|
162 | 163 | check_file.close |
|
163 | 164 | |
|
164 | 165 | File.chmod(0755,"#{problem_dir}/script/check") |
|
165 | 166 | |
|
166 |
- |
|
|
167 | + File.copy("#{check_script_fname}", "#{problem_dir}/script/#{script_name}") | |
|
167 | 168 | else |
|
168 | 169 | if File.exists?(SCRIPT_DIR + "/templates/check.#{check_script}") |
|
169 | 170 | check_script_fname = SCRIPT_DIR + "/templates/check.#{check_script}" |
|
170 | 171 | else |
|
171 | 172 | check_script_fname = check_script |
|
172 | 173 | end |
|
173 |
- |
|
|
174 | + File.copy("#{check_script_fname}", "#{problem_dir}/script/check") | |
|
174 | 175 | end |
|
175 | 176 | |
|
176 | 177 | # generating test_request directory |
|
177 | 178 | puts "generating test_request template" |
|
178 | 179 | FileUtils.mkdir_p("#{ev_dir}/test_request/#{problem}/script") |
|
179 | 180 | FileUtils.mkdir_p("#{ev_dir}/test_request/#{problem}/test_cases/1") |
|
180 | 181 | |
|
181 | 182 | template = File.open(SCRIPT_DIR + "/templates/test_request_all_tests.cfg.erb").read |
|
182 | 183 | test_request_all_test_cfg = ERB.new(template) |
|
183 | 184 | |
|
184 | 185 | cfg_file = File.open("#{ev_dir}/test_request/#{problem}/test_cases/all_tests.cfg","w") |
|
185 | 186 | cfg_file.puts test_request_all_test_cfg.result |
|
186 | 187 | cfg_file.close |
|
187 | 188 | |
|
188 | - system("cp #{SCRIPT_DIR}/templates/check_empty #{ev_dir}/test_request/#{problem}/script/check") | |
|
189 | - system("cp #{SCRIPT_DIR}/templates/answer-1.txt #{ev_dir}/test_request/#{problem}/test_cases/1") | |
|
189 | + File.copy("#{SCRIPT_DIR}/templates/check_empty", | |
|
190 | + "#{ev_dir}/test_request/#{problem}/script/check") | |
|
191 | + File.copy("#{SCRIPT_DIR}/templates/answer-1.txt", | |
|
192 | + "#{ev_dir}/test_request/#{problem}/test_cases/1") | |
|
190 | 193 | |
|
191 | 194 | puts "done" |
|
192 | 195 | end |
|
193 | 196 | |
|
194 | 197 | |
|
195 | 198 | SCRIPT_DIR = File.dirname(__FILE__) |
|
196 | 199 | |
|
197 | 200 | # print usage |
|
198 | 201 | if (ARGV.length < 3) or (ARGV[2][0,1]=="-") |
|
199 | 202 | print_usage |
|
200 | 203 | exit(127) |
|
201 | 204 | end |
You need to be logged in to leave comments.
Login now