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
@@ -1,114 +1,114 | |||||
|
1 | #!/usr/bin/ruby |
|
1 | #!/usr/bin/ruby |
|
2 |
|
2 | ||
|
3 | def stop_grader(id) |
|
3 | def stop_grader(id) |
|
4 | if id==:all |
|
4 | if id==:all |
|
5 | File.open(File.dirname(__FILE__) + "/stop.all",'w').close |
|
5 | File.open(File.dirname(__FILE__) + "/stop.all",'w').close |
|
6 | else |
|
6 | else |
|
7 | File.open(File.dirname(__FILE__) + "/stop.#{id}",'w').close |
|
7 | File.open(File.dirname(__FILE__) + "/stop.#{id}",'w').close |
|
8 | end |
|
8 | end |
|
9 | end |
|
9 | end |
|
10 |
|
10 | ||
|
11 | def check_stopfile |
|
11 | def check_stopfile |
|
12 | FileTest.exist?(File.dirname(__FILE__) + "/stop.all") or |
|
12 | FileTest.exist?(File.dirname(__FILE__) + "/stop.all") or |
|
13 | FileTest.exist?(File.dirname(__FILE__) + "/stop.#{Process.pid}") |
|
13 | FileTest.exist?(File.dirname(__FILE__) + "/stop.#{Process.pid}") |
|
14 | end |
|
14 | end |
|
15 |
|
15 | ||
|
16 | def clear_stopfile |
|
16 | def clear_stopfile |
|
17 | if FileTest.exist?(File.dirname(__FILE__) + "/stop.#{Process.pid}") |
|
17 | if FileTest.exist?(File.dirname(__FILE__) + "/stop.#{Process.pid}") |
|
18 |
- |
|
18 | + File.delete(File.dirname(__FILE__) + "/stop.#{Process.pid}") |
|
19 | end |
|
19 | end |
|
20 | end |
|
20 | end |
|
21 |
|
21 | ||
|
22 | def config |
|
22 | def config |
|
23 | Grader::Configuration.get_instance |
|
23 | Grader::Configuration.get_instance |
|
24 | end |
|
24 | end |
|
25 |
|
25 | ||
|
26 | def log_file_name |
|
26 | def log_file_name |
|
27 | if !File.exists?(config.log_dir) |
|
27 | if !File.exists?(config.log_dir) |
|
28 | raise "Log directory does not exist: #{config.log_dir}" |
|
28 | raise "Log directory does not exist: #{config.log_dir}" |
|
29 | end |
|
29 | end |
|
30 | config.log_dir + |
|
30 | config.log_dir + |
|
31 | "/#{GRADER_ENV}_#{config.grader_mode}.#{Process.pid}" |
|
31 | "/#{GRADER_ENV}_#{config.grader_mode}.#{Process.pid}" |
|
32 | end |
|
32 | end |
|
33 |
|
33 | ||
|
34 | def log(str) |
|
34 | def log(str) |
|
35 | if config.talkative |
|
35 | if config.talkative |
|
36 | puts str |
|
36 | puts str |
|
37 | end |
|
37 | end |
|
38 | if config.logging |
|
38 | if config.logging |
|
39 | fp = File.open(log_file_name,"a") |
|
39 | fp = File.open(log_file_name,"a") |
|
40 | fp.puts("GRADER: #{Time.new.strftime("%H:%M")} #{str}") |
|
40 | fp.puts("GRADER: #{Time.new.strftime("%H:%M")} #{str}") |
|
41 | fp.close |
|
41 | fp.close |
|
42 | end |
|
42 | end |
|
43 | end |
|
43 | end |
|
44 |
|
44 | ||
|
45 | def display_manual |
|
45 | def display_manual |
|
46 | puts <<USAGE |
|
46 | puts <<USAGE |
|
47 | Grader. |
|
47 | Grader. |
|
48 | using: (1) grader |
|
48 | using: (1) grader |
|
49 | (2) grader environment [mode] |
|
49 | (2) grader environment [mode] |
|
50 | (3) grader stop [all|pids-list] |
|
50 | (3) grader stop [all|pids-list] |
|
51 | (4) grader --help |
|
51 | (4) grader --help |
|
52 | (1) call grader with environment = 'exam', mode = 'queue' |
|
52 | (1) call grader with environment = 'exam', mode = 'queue' |
|
53 | (2) possible modes are: 'queue', 'prob', 'test_request' |
|
53 | (2) possible modes are: 'queue', 'prob', 'test_request' |
|
54 | (3) create stop-file to stop running grader in queue mode |
|
54 | (3) create stop-file to stop running grader in queue mode |
|
55 | (4) You are here. |
|
55 | (4) You are here. |
|
56 | USAGE |
|
56 | USAGE |
|
57 | end |
|
57 | end |
|
58 |
|
58 | ||
|
59 | def process_options_and_stop_file |
|
59 | def process_options_and_stop_file |
|
60 | # The list of options are: |
|
60 | # The list of options are: |
|
61 | # - stop [all|process ids] |
|
61 | # - stop [all|process ids] |
|
62 | # - |
|
62 | # - |
|
63 |
|
63 | ||
|
64 | # Process 'help' option |
|
64 | # Process 'help' option |
|
65 | if (ARGV.length==1) and (/help/.match(ARGV[0])) |
|
65 | if (ARGV.length==1) and (/help/.match(ARGV[0])) |
|
66 | display_manual |
|
66 | display_manual |
|
67 | exit(0) |
|
67 | exit(0) |
|
68 | end |
|
68 | end |
|
69 |
|
69 | ||
|
70 | # Process 'stop' option. |
|
70 | # Process 'stop' option. |
|
71 | if (ARGV.length >= 1) and (ARGV[0]=='stop') |
|
71 | if (ARGV.length >= 1) and (ARGV[0]=='stop') |
|
72 | if ARGV.length==1 |
|
72 | if ARGV.length==1 |
|
73 | puts "you should specify pid-list or 'all'" |
|
73 | puts "you should specify pid-list or 'all'" |
|
74 | display_manual |
|
74 | display_manual |
|
75 | elsif (ARGV.length==2) and (ARGV[1]=='all') |
|
75 | elsif (ARGV.length==2) and (ARGV[1]=='all') |
|
76 | stop_grader(:all) |
|
76 | stop_grader(:all) |
|
77 | puts "A global stop file ('stop.all') created." |
|
77 | puts "A global stop file ('stop.all') created." |
|
78 | puts "You should remove it manually later." |
|
78 | puts "You should remove it manually later." |
|
79 | else |
|
79 | else |
|
80 | (1..ARGV.length-1).each do |i| |
|
80 | (1..ARGV.length-1).each do |i| |
|
81 | stop_grader(ARGV[i]) |
|
81 | stop_grader(ARGV[i]) |
|
82 | end |
|
82 | end |
|
83 | puts "stop file(s) created" |
|
83 | puts "stop file(s) created" |
|
84 | end |
|
84 | end |
|
85 | exit(0) |
|
85 | exit(0) |
|
86 | end |
|
86 | end |
|
87 |
|
87 | ||
|
88 | # Check stop file. |
|
88 | # Check stop file. |
|
89 | if check_stopfile |
|
89 | if check_stopfile |
|
90 | puts "Stop file exists. Terminated." |
|
90 | puts "Stop file exists. Terminated." |
|
91 | clear_stopfile |
|
91 | clear_stopfile |
|
92 | exit(0) |
|
92 | exit(0) |
|
93 | end |
|
93 | end |
|
94 |
|
94 | ||
|
95 | #default options |
|
95 | #default options |
|
96 | options = { |
|
96 | options = { |
|
97 | :mode => 'queue', |
|
97 | :mode => 'queue', |
|
98 | :environment => 'exam', |
|
98 | :environment => 'exam', |
|
99 | :dry_run => false, |
|
99 | :dry_run => false, |
|
100 | } |
|
100 | } |
|
101 |
|
101 | ||
|
102 | # Process mode and environment option |
|
102 | # Process mode and environment option |
|
103 | if ARGV.length >= 1 |
|
103 | if ARGV.length >= 1 |
|
104 | options[:environment] = ARGV.shift |
|
104 | options[:environment] = ARGV.shift |
|
105 | if ARGV.length >=1 |
|
105 | if ARGV.length >=1 |
|
106 | options[:mode] = ARGV.shift |
|
106 | options[:mode] = ARGV.shift |
|
107 | end |
|
107 | end |
|
108 | end |
|
108 | end |
|
109 |
|
109 | ||
|
110 | options[:dry_run] = (ARGV.delete('--dry') != nil) |
|
110 | options[:dry_run] = (ARGV.delete('--dry') != nil) |
|
111 | if options[:dry_run] and (not ['prob','contest'].include? options[:mode]) |
|
111 | if options[:dry_run] and (not ['prob','contest'].include? options[:mode]) |
|
112 | puts "Dry run currently works only for 'prob' or 'contest' modes." |
|
112 | puts "Dry run currently works only for 'prob' or 'contest' modes." |
|
113 | exit(0) |
|
113 | exit(0) |
|
114 | end |
|
114 | end |
@@ -1,110 +1,89 | |||||
|
1 | #!/usr/bin/ruby |
|
1 | #!/usr/bin/ruby |
|
2 |
|
2 | ||
|
3 | def talk(str) |
|
3 | def talk(str) |
|
4 | if TALKATIVE |
|
4 | if TALKATIVE |
|
5 | puts str |
|
5 | puts str |
|
6 | end |
|
6 | end |
|
7 | end |
|
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 | def save_source(submission,dir,fname) |
|
9 | def save_source(submission,dir,fname) |
|
17 | f = File.open("#{dir}/#{fname}","w") |
|
10 | f = File.open("#{dir}/#{fname}","w") |
|
18 | f.write(submission.source) |
|
11 | f.write(submission.source) |
|
19 | f.close |
|
12 | f.close |
|
20 | end |
|
13 | end |
|
21 |
|
14 | ||
|
22 | def call_judge(problem_home,language,problem_out_dir,fname) |
|
15 | def call_judge(problem_home,language,problem_out_dir,fname) |
|
23 | ENV['PROBLEM_HOME'] = problem_home |
|
16 | ENV['PROBLEM_HOME'] = problem_home |
|
24 | Dir.chdir problem_out_dir |
|
17 | Dir.chdir problem_out_dir |
|
25 | cmd = "#{problem_home}/script/judge #{language} #{fname}" |
|
18 | cmd = "#{problem_home}/script/judge #{language} #{fname}" |
|
26 | # puts "CMD: #{cmd}" |
|
19 | # puts "CMD: #{cmd}" |
|
27 | system(cmd) |
|
20 | system(cmd) |
|
28 | end |
|
21 | end |
|
29 |
|
22 | ||
|
30 | def read_result(test_result_dir) |
|
23 | def read_result(test_result_dir) |
|
31 | cmp_msg_fname = "#{test_result_dir}/compiler_message" |
|
24 | cmp_msg_fname = "#{test_result_dir}/compiler_message" |
|
32 | cmp_msg = File.open(cmp_msg_fname).read |
|
25 | cmp_msg = File.open(cmp_msg_fname).read |
|
33 |
|
26 | ||
|
34 | result_fname = "#{test_result_dir}/result" |
|
27 | result_fname = "#{test_result_dir}/result" |
|
35 | comment_fname = "#{test_result_dir}/comment" |
|
28 | comment_fname = "#{test_result_dir}/comment" |
|
36 | if FileTest.exist?(result_fname) |
|
29 | if FileTest.exist?(result_fname) |
|
37 | result = File.open(result_fname).readline.to_i |
|
30 | result = File.open(result_fname).readline.to_i |
|
38 | comment = File.open(comment_fname).readline.chomp |
|
31 | comment = File.open(comment_fname).readline.chomp |
|
39 | return {:points => result, |
|
32 | return {:points => result, |
|
40 | :comment => comment, |
|
33 | :comment => comment, |
|
41 | :cmp_msg => cmp_msg} |
|
34 | :cmp_msg => cmp_msg} |
|
42 | else |
|
35 | else |
|
43 | return {:points => 0, |
|
36 | return {:points => 0, |
|
44 | :comment => 'compile error', |
|
37 | :comment => 'compile error', |
|
45 | :cmp_msg => cmp_msg} |
|
38 | :cmp_msg => cmp_msg} |
|
46 | end |
|
39 | end |
|
47 | end |
|
40 | end |
|
48 |
|
41 | ||
|
49 | def save_result(submission,result) |
|
42 | def save_result(submission,result) |
|
50 | submission.graded_at = Time.now |
|
43 | submission.graded_at = Time.now |
|
51 | submission.points = result[:points] |
|
44 | submission.points = result[:points] |
|
52 | submission.grader_comment = report_comment(result[:comment]) |
|
45 | submission.grader_comment = report_comment(result[:comment]) |
|
53 | submission.compiler_message = result[:cmp_msg] |
|
46 | submission.compiler_message = result[:cmp_msg] |
|
54 | submission.save |
|
47 | submission.save |
|
55 | end |
|
48 | end |
|
56 |
|
49 | ||
|
57 | def grade(submission_id) |
|
50 | def grade(submission_id) |
|
58 | sub = Submission.find(submission_id) |
|
51 | sub = Submission.find(submission_id) |
|
59 | user = sub.user |
|
52 | user = sub.user |
|
60 | problem = sub.problem |
|
53 | problem = sub.problem |
|
61 |
|
54 | ||
|
62 | language = sub.language.name |
|
55 | language = sub.language.name |
|
63 | lang_ext = sub.language.ext |
|
56 | lang_ext = sub.language.ext |
|
64 | # FIX THIS |
|
57 | # FIX THIS |
|
65 | talk 'some hack on language' |
|
58 | talk 'some hack on language' |
|
66 | if language == 'cpp' |
|
59 | if language == 'cpp' |
|
67 | language = 'c++' |
|
60 | language = 'c++' |
|
68 | end |
|
61 | end |
|
69 |
|
62 | ||
|
70 | user_dir = "#{USER_RESULT_DIR}/#{user.login}" |
|
63 | user_dir = "#{USER_RESULT_DIR}/#{user.login}" |
|
71 | Dir.mkdir(user_dir) if !FileTest.exist?(user_dir) |
|
64 | Dir.mkdir(user_dir) if !FileTest.exist?(user_dir) |
|
72 |
|
65 | ||
|
73 | problem_out_dir = "#{user_dir}/#{problem.name}" |
|
66 | problem_out_dir = "#{user_dir}/#{problem.name}" |
|
74 | Dir.mkdir(problem_out_dir) if !FileTest.exist?(problem_out_dir) |
|
67 | Dir.mkdir(problem_out_dir) if !FileTest.exist?(problem_out_dir) |
|
75 |
|
68 | ||
|
76 | problem_home = "#{PROBLEMS_DIR}/#{problem.name}" |
|
69 | problem_home = "#{PROBLEMS_DIR}/#{problem.name}" |
|
77 | source_name = "#{problem.name}.#{lang_ext}" |
|
70 | source_name = "#{problem.name}.#{lang_ext}" |
|
78 |
|
71 | ||
|
79 | save_source(sub,problem_out_dir,source_name) |
|
72 | save_source(sub,problem_out_dir,source_name) |
|
80 | call_judge(problem_home,language,problem_out_dir,source_name) |
|
73 | call_judge(problem_home,language,problem_out_dir,source_name) |
|
81 | save_result(sub,read_result("#{problem_out_dir}/test-result")) |
|
74 | save_result(sub,read_result("#{problem_out_dir}/test-result")) |
|
82 | end |
|
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 | # reading environment and options |
|
77 | # reading environment and options |
|
97 | GRADER_ENV = 'exam' |
|
78 | GRADER_ENV = 'exam' |
|
98 | puts "environment: #{GRADER_ENV}" |
|
79 | puts "environment: #{GRADER_ENV}" |
|
99 | require File.dirname(__FILE__) + "/environment.rb" |
|
80 | require File.dirname(__FILE__) + "/environment.rb" |
|
100 |
|
81 | ||
|
101 | #main program |
|
82 | #main program |
|
102 | talk 'Reading rails environment' |
|
83 | talk 'Reading rails environment' |
|
103 |
|
84 | ||
|
104 | RAILS_ENV = 'development' |
|
85 | RAILS_ENV = 'development' |
|
105 | require RAILS_APP_DIR + '/config/environment' |
|
86 | require RAILS_APP_DIR + '/config/environment' |
|
106 |
|
87 | ||
|
107 | current_dir = `pwd` |
|
88 | current_dir = `pwd` |
|
108 | grade(ARGV[0].to_i) |
|
89 | grade(ARGV[0].to_i) |
|
109 | - |
|
||
|
110 | - |
|
@@ -1,228 +1,231 | |||||
|
1 | #!/usr/bin/ruby |
|
1 | #!/usr/bin/ruby |
|
2 |
|
2 | ||
|
3 | require 'erb' |
|
3 | require 'erb' |
|
|
4 | + require 'ftools' | ||
|
4 | require 'fileutils' |
|
5 | require 'fileutils' |
|
5 | require File.join(File.dirname(__FILE__),'lib/import_helper') |
|
6 | require File.join(File.dirname(__FILE__),'lib/import_helper') |
|
6 |
|
7 | ||
|
7 | JUDGE_ENVIRONMENTS = [:grading, :exam] |
|
8 | JUDGE_ENVIRONMENTS = [:grading, :exam] |
|
8 | ENV_INFO = { |
|
9 | ENV_INFO = { |
|
9 | :grading => { |
|
10 | :grading => { |
|
10 | :ev_dir => 'ev', |
|
11 | :ev_dir => 'ev', |
|
11 | :raw_prefix => '', |
|
12 | :raw_prefix => '', |
|
12 | }, |
|
13 | }, |
|
13 | :exam => { |
|
14 | :exam => { |
|
14 | :ev_dir => 'ev-exam', |
|
15 | :ev_dir => 'ev-exam', |
|
15 | :raw_prefix => 'ex.', |
|
16 | :raw_prefix => 'ex.', |
|
16 | } |
|
17 | } |
|
17 | } |
|
18 | } |
|
18 |
|
19 | ||
|
19 | def input_filename(dir,i) |
|
20 | def input_filename(dir,i) |
|
20 | "#{dir}/input-#{i}.txt" |
|
21 | "#{dir}/input-#{i}.txt" |
|
21 | end |
|
22 | end |
|
22 |
|
23 | ||
|
23 | def answer_filename(dir,i) |
|
24 | def answer_filename(dir,i) |
|
24 | "#{dir}/answer-#{i}.txt" |
|
25 | "#{dir}/answer-#{i}.txt" |
|
25 | end |
|
26 | end |
|
26 |
|
27 | ||
|
27 | def build_testrun_info_from_dir(num_testruns, importing_test_dir, raw_prefix='') |
|
28 | def build_testrun_info_from_dir(num_testruns, importing_test_dir, raw_prefix='') |
|
28 | filenames = Dir["#{importing_test_dir}/#{raw_prefix}*.in"].collect do |filename| |
|
29 | filenames = Dir["#{importing_test_dir}/#{raw_prefix}*.in"].collect do |filename| |
|
29 | File.basename((/(.*)\.in/.match(filename))[1]) |
|
30 | File.basename((/(.*)\.in/.match(filename))[1]) |
|
30 | end |
|
31 | end |
|
31 | build_testrun_info(num_testruns,filenames,raw_prefix) |
|
32 | build_testrun_info(num_testruns,filenames,raw_prefix) |
|
32 | end |
|
33 | end |
|
33 |
|
34 | ||
|
34 | def copy_testcase(importing_test_dir,fname,dir,i) |
|
35 | def copy_testcase(importing_test_dir,fname,dir,i) |
|
35 |
- |
|
36 | + File.copy("#{importing_test_dir}/#{fname}.in", "#{input_filename(dir,i)}") |
|
36 |
- |
|
37 | + File.copy("#{importing_test_dir}/#{fname}.sol", "#{answer_filename(dir,i)}") |
|
37 | end |
|
38 | end |
|
38 |
|
39 | ||
|
39 | def process_options(options) |
|
40 | def process_options(options) |
|
40 | i = 3 |
|
41 | i = 3 |
|
41 | while i<ARGV.length |
|
42 | while i<ARGV.length |
|
42 | if ARGV[i]=='-t' |
|
43 | if ARGV[i]=='-t' |
|
43 | options[:time_limit] = ARGV[i+1].to_f if ARGV.length>i+1 |
|
44 | options[:time_limit] = ARGV[i+1].to_f if ARGV.length>i+1 |
|
44 | i += 1 |
|
45 | i += 1 |
|
45 | end |
|
46 | end |
|
46 | if ARGV[i]=='-m' |
|
47 | if ARGV[i]=='-m' |
|
47 | options[:mem_limit] = ARGV[i+1].to_i if ARGV.length>i+1 |
|
48 | options[:mem_limit] = ARGV[i+1].to_i if ARGV.length>i+1 |
|
48 | i += 1 |
|
49 | i += 1 |
|
49 | end |
|
50 | end |
|
50 | i += 1 |
|
51 | i += 1 |
|
51 | end |
|
52 | end |
|
52 | end |
|
53 | end |
|
53 |
|
54 | ||
|
54 | def print_usage |
|
55 | def print_usage |
|
55 | puts "using: import_problem_new name dir check [options] |
|
56 | puts "using: import_problem_new name dir check [options] |
|
56 |
|
57 | ||
|
57 | where: name = problem_name (put '-' (dash) to use dir name) |
|
58 | where: name = problem_name (put '-' (dash) to use dir name) |
|
58 | dir = importing testcase directory |
|
59 | dir = importing testcase directory |
|
59 | check = check script, which can be |
|
60 | check = check script, which can be |
|
60 | 'integer', 'text' (for standard script), |
|
61 | 'integer', 'text' (for standard script), |
|
61 | path_to_your_script, or |
|
62 | path_to_your_script, or |
|
62 | 'wrapper:(path_to_your_wrapped_script)' |
|
63 | 'wrapper:(path_to_your_wrapped_script)' |
|
63 | options: -t time-limit (in seconds) |
|
64 | options: -t time-limit (in seconds) |
|
64 | -m memory-limit (in megabytes) |
|
65 | -m memory-limit (in megabytes) |
|
65 |
|
66 | ||
|
66 | The script looks at test data files in the dir of the forms: *.in and |
|
67 | The script looks at test data files in the dir of the forms: *.in and |
|
67 | *.sol and import them to the evaluation dir for their environment, |
|
68 | *.sol and import them to the evaluation dir for their environment, |
|
68 | based on their prefixes. |
|
69 | based on their prefixes. |
|
69 |
|
70 | ||
|
70 | Currently supporting environments are:" |
|
71 | Currently supporting environments are:" |
|
71 |
|
72 | ||
|
72 | JUDGE_ENVIRONMENTS.each do |env| |
|
73 | JUDGE_ENVIRONMENTS.each do |env| |
|
73 | prefix = ENV_INFO[env][:raw_prefix] |
|
74 | prefix = ENV_INFO[env][:raw_prefix] |
|
74 | prefix = 'no prefix' if prefix=='' |
|
75 | prefix = 'no prefix' if prefix=='' |
|
75 | puts " * #{env}" |
|
76 | puts " * #{env}" |
|
76 | puts " import to: #{ENV_INFO[env][:ev_dir]}" |
|
77 | puts " import to: #{ENV_INFO[env][:ev_dir]}" |
|
77 | puts " prefix with: #{prefix} (e.g., #{ENV_INFO[env][:raw_prefix]}1.in, #{ENV_INFO[env][:raw_prefix]}5a.sol)" |
|
78 | puts " prefix with: #{prefix} (e.g., #{ENV_INFO[env][:raw_prefix]}1.in, #{ENV_INFO[env][:raw_prefix]}5a.sol)" |
|
78 | end |
|
79 | end |
|
79 |
|
80 | ||
|
80 | puts" |
|
81 | puts" |
|
81 | For each environment, the script |
|
82 | For each environment, the script |
|
82 | * creates a directory for a problem in ev dir of that environment, |
|
83 | * creates a directory for a problem in ev dir of that environment, |
|
83 | * copies testdata in the old format and create standard testcase config file |
|
84 | * copies testdata in the old format and create standard testcase config file |
|
84 | * copies a check script for grading |
|
85 | * copies a check script for grading |
|
85 | * creates a test_request template in the ev dir + '/test_request' |
|
86 | * creates a test_request template in the ev dir + '/test_request' |
|
86 |
|
87 | ||
|
87 | For wrapped checked script see comment in templates/check_wrapper for |
|
88 | For wrapped checked script see comment in templates/check_wrapper for |
|
88 | information." |
|
89 | information." |
|
89 | end |
|
90 | end |
|
90 |
|
91 | ||
|
91 | def count_testruns(testcase_dir, raw_prefix) |
|
92 | def count_testruns(testcase_dir, raw_prefix) |
|
92 | n = 0 |
|
93 | n = 0 |
|
93 | begin |
|
94 | begin |
|
94 | # check for test case n+1 |
|
95 | # check for test case n+1 |
|
95 | if ((Dir["#{testcase_dir}/#{raw_prefix}#{n+1}.in"].length==0) and |
|
96 | if ((Dir["#{testcase_dir}/#{raw_prefix}#{n+1}.in"].length==0) and |
|
96 | (Dir["#{testcase_dir}/#{raw_prefix}#{n+1}[a-z].in"].length==0)) |
|
97 | (Dir["#{testcase_dir}/#{raw_prefix}#{n+1}[a-z].in"].length==0)) |
|
97 | return n |
|
98 | return n |
|
98 | end |
|
99 | end |
|
99 | n += 1 |
|
100 | n += 1 |
|
100 | end while true |
|
101 | end while true |
|
101 | end |
|
102 | end |
|
102 |
|
103 | ||
|
103 | def import_problem(ev_dir, problem, testcase_dir, num_testruns, raw_prefix, check_script, options) |
|
104 | def import_problem(ev_dir, problem, testcase_dir, num_testruns, raw_prefix, check_script, options) |
|
104 | testrun_info = build_testrun_info_from_dir(num_testruns, testcase_dir, raw_prefix) |
|
105 | testrun_info = build_testrun_info_from_dir(num_testruns, testcase_dir, raw_prefix) |
|
105 |
|
106 | ||
|
106 | if !(FileTest.exists? ev_dir) |
|
107 | if !(FileTest.exists? ev_dir) |
|
107 | puts "Testdata dir (#{ev_dir}) not found." |
|
108 | puts "Testdata dir (#{ev_dir}) not found." |
|
108 | return |
|
109 | return |
|
109 | end |
|
110 | end |
|
110 |
|
111 | ||
|
111 | problem_dir = "#{ev_dir}/#{problem}" |
|
112 | problem_dir = "#{ev_dir}/#{problem}" |
|
112 |
|
113 | ||
|
113 | # start working |
|
114 | # start working |
|
114 | puts "creating directories" |
|
115 | puts "creating directories" |
|
115 |
|
116 | ||
|
116 |
- |
|
117 | + File.makedirs("#{problem_dir}") |
|
117 |
- |
|
118 | + File.makedirs("#{problem_dir}/script") |
|
118 |
- |
|
119 | + File.makedirs("#{problem_dir}/test_cases") |
|
119 |
|
120 | ||
|
120 | puts "copying testcases" |
|
121 | puts "copying testcases" |
|
121 |
|
122 | ||
|
122 | tr_num = 0 |
|
123 | tr_num = 0 |
|
123 |
|
124 | ||
|
124 | num_testcases = 0 |
|
125 | num_testcases = 0 |
|
125 |
|
126 | ||
|
126 | testrun_info.each do |testrun| |
|
127 | testrun_info.each do |testrun| |
|
127 | tr_num += 1 |
|
128 | tr_num += 1 |
|
128 | puts "testrun: #{tr_num}" |
|
129 | puts "testrun: #{tr_num}" |
|
129 |
|
130 | ||
|
130 | testrun.each do |testcase_info| |
|
131 | testrun.each do |testcase_info| |
|
131 | testcase_num, testcase_fname = testcase_info |
|
132 | testcase_num, testcase_fname = testcase_info |
|
132 |
|
133 | ||
|
133 | puts "copy #{testcase_fname} to #{testcase_num}" |
|
134 | puts "copy #{testcase_fname} to #{testcase_num}" |
|
134 |
|
135 | ||
|
135 |
- |
|
136 | + File.makedirs("#{problem_dir}/test_cases/#{testcase_num}") |
|
136 | copy_testcase("#{testcase_dir}",testcase_fname,"#{problem_dir}/test_cases/#{testcase_num}",testcase_num) |
|
137 | copy_testcase("#{testcase_dir}",testcase_fname,"#{problem_dir}/test_cases/#{testcase_num}",testcase_num) |
|
137 |
|
138 | ||
|
138 | num_testcases += 1 |
|
139 | num_testcases += 1 |
|
139 | end |
|
140 | end |
|
140 | end |
|
141 | end |
|
141 |
|
142 | ||
|
142 | # generating all_tests.cfg |
|
143 | # generating all_tests.cfg |
|
143 | puts "generating testcase config file" |
|
144 | puts "generating testcase config file" |
|
144 |
|
145 | ||
|
145 | template = File.open(SCRIPT_DIR + "/templates/all_tests.cfg.erb").read |
|
146 | template = File.open(SCRIPT_DIR + "/templates/all_tests.cfg.erb").read |
|
146 | all_test_cfg = ERB.new(template) |
|
147 | all_test_cfg = ERB.new(template) |
|
147 |
|
148 | ||
|
148 | cfg_file = File.open("#{problem_dir}/test_cases/all_tests.cfg","w") |
|
149 | cfg_file = File.open("#{problem_dir}/test_cases/all_tests.cfg","w") |
|
149 | cfg_file.puts all_test_cfg.result binding |
|
150 | cfg_file.puts all_test_cfg.result binding |
|
150 | cfg_file.close |
|
151 | cfg_file.close |
|
151 |
|
152 | ||
|
152 | # copy check script |
|
153 | # copy check script |
|
153 | if res = /^wrapper:(.*)$/.match(check_script) |
|
154 | if res = /^wrapper:(.*)$/.match(check_script) |
|
154 | # wrapper script |
|
155 | # wrapper script |
|
155 | check_script_fname = res[1] |
|
156 | check_script_fname = res[1] |
|
156 | script_name = File.basename(check_script_fname) |
|
157 | script_name = File.basename(check_script_fname) |
|
157 | check_wrapper_template = File.open(SCRIPT_DIR + "/templates/check_wrapper").read |
|
158 | check_wrapper_template = File.open(SCRIPT_DIR + "/templates/check_wrapper").read |
|
158 | check_wrapper = ERB.new(check_wrapper_template) |
|
159 | check_wrapper = ERB.new(check_wrapper_template) |
|
159 |
|
160 | ||
|
160 | check_file = File.open("#{problem_dir}/script/check","w") |
|
161 | check_file = File.open("#{problem_dir}/script/check","w") |
|
161 | check_file.puts check_wrapper.result binding |
|
162 | check_file.puts check_wrapper.result binding |
|
162 | check_file.close |
|
163 | check_file.close |
|
163 |
|
164 | ||
|
164 | File.chmod(0755,"#{problem_dir}/script/check") |
|
165 | File.chmod(0755,"#{problem_dir}/script/check") |
|
165 |
|
166 | ||
|
166 |
- |
|
167 | + File.copy("#{check_script_fname}", "#{problem_dir}/script/#{script_name}") |
|
167 | else |
|
168 | else |
|
168 | if File.exists?(SCRIPT_DIR + "/templates/check.#{check_script}") |
|
169 | if File.exists?(SCRIPT_DIR + "/templates/check.#{check_script}") |
|
169 | check_script_fname = SCRIPT_DIR + "/templates/check.#{check_script}" |
|
170 | check_script_fname = SCRIPT_DIR + "/templates/check.#{check_script}" |
|
170 | else |
|
171 | else |
|
171 | check_script_fname = check_script |
|
172 | check_script_fname = check_script |
|
172 | end |
|
173 | end |
|
173 |
- |
|
174 | + File.copy("#{check_script_fname}", "#{problem_dir}/script/check") |
|
174 | end |
|
175 | end |
|
175 |
|
176 | ||
|
176 | # generating test_request directory |
|
177 | # generating test_request directory |
|
177 | puts "generating test_request template" |
|
178 | puts "generating test_request template" |
|
178 | FileUtils.mkdir_p("#{ev_dir}/test_request/#{problem}/script") |
|
179 | FileUtils.mkdir_p("#{ev_dir}/test_request/#{problem}/script") |
|
179 | FileUtils.mkdir_p("#{ev_dir}/test_request/#{problem}/test_cases/1") |
|
180 | FileUtils.mkdir_p("#{ev_dir}/test_request/#{problem}/test_cases/1") |
|
180 |
|
181 | ||
|
181 | template = File.open(SCRIPT_DIR + "/templates/test_request_all_tests.cfg.erb").read |
|
182 | template = File.open(SCRIPT_DIR + "/templates/test_request_all_tests.cfg.erb").read |
|
182 | test_request_all_test_cfg = ERB.new(template) |
|
183 | test_request_all_test_cfg = ERB.new(template) |
|
183 |
|
184 | ||
|
184 | cfg_file = File.open("#{ev_dir}/test_request/#{problem}/test_cases/all_tests.cfg","w") |
|
185 | cfg_file = File.open("#{ev_dir}/test_request/#{problem}/test_cases/all_tests.cfg","w") |
|
185 | cfg_file.puts test_request_all_test_cfg.result |
|
186 | cfg_file.puts test_request_all_test_cfg.result |
|
186 | cfg_file.close |
|
187 | cfg_file.close |
|
187 |
|
188 | ||
|
188 | - system("cp #{SCRIPT_DIR}/templates/check_empty #{ev_dir}/test_request/#{problem}/script/check") |
|
189 | + File.copy("#{SCRIPT_DIR}/templates/check_empty", |
|
189 | - system("cp #{SCRIPT_DIR}/templates/answer-1.txt #{ev_dir}/test_request/#{problem}/test_cases/1") |
|
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 | puts "done" |
|
194 | puts "done" |
|
192 | end |
|
195 | end |
|
193 |
|
196 | ||
|
194 |
|
197 | ||
|
195 | SCRIPT_DIR = File.dirname(__FILE__) |
|
198 | SCRIPT_DIR = File.dirname(__FILE__) |
|
196 |
|
199 | ||
|
197 | # print usage |
|
200 | # print usage |
|
198 | if (ARGV.length < 3) or (ARGV[2][0,1]=="-") |
|
201 | if (ARGV.length < 3) or (ARGV[2][0,1]=="-") |
|
199 | print_usage |
|
202 | print_usage |
|
200 | exit(127) |
|
203 | exit(127) |
|
201 | end |
|
204 | end |
|
202 |
|
205 | ||
|
203 | # processing arguments |
|
206 | # processing arguments |
|
204 | problem = ARGV[0] |
|
207 | problem = ARGV[0] |
|
205 | testcase_dir = ARGV[1] |
|
208 | testcase_dir = ARGV[1] |
|
206 | problem = File.basename(testcase_dir) if problem=="-" |
|
209 | problem = File.basename(testcase_dir) if problem=="-" |
|
207 | check_script = ARGV[2] |
|
210 | check_script = ARGV[2] |
|
208 | options = {:time_limit => 1, :mem_limit => 16} |
|
211 | options = {:time_limit => 1, :mem_limit => 16} |
|
209 | process_options(options) |
|
212 | process_options(options) |
|
210 |
|
213 | ||
|
211 | JUDGE_ENVIRONMENTS.each do |env| |
|
214 | JUDGE_ENVIRONMENTS.each do |env| |
|
212 | ev_dir = ENV_INFO[env][:ev_dir] |
|
215 | ev_dir = ENV_INFO[env][:ev_dir] |
|
213 | raw_prefix = ENV_INFO[env][:raw_prefix] |
|
216 | raw_prefix = ENV_INFO[env][:raw_prefix] |
|
214 |
|
217 | ||
|
215 | num_testruns = count_testruns(testcase_dir,raw_prefix) |
|
218 | num_testruns = count_testruns(testcase_dir,raw_prefix) |
|
216 |
|
219 | ||
|
217 | puts "" |
|
220 | puts "" |
|
218 | puts "*** Environment: #{env} (#{num_testruns} test runs) ***" |
|
221 | puts "*** Environment: #{env} (#{num_testruns} test runs) ***" |
|
219 | puts "" |
|
222 | puts "" |
|
220 |
|
223 | ||
|
221 | import_problem(ev_dir, |
|
224 | import_problem(ev_dir, |
|
222 | problem, |
|
225 | problem, |
|
223 | testcase_dir, |
|
226 | testcase_dir, |
|
224 | num_testruns, |
|
227 | num_testruns, |
|
225 | raw_prefix, |
|
228 | raw_prefix, |
|
226 | check_script, |
|
229 | check_script, |
|
227 | options) |
|
230 | options) |
|
228 | end |
|
231 | end |
You need to be logged in to leave comments.
Login now