# HG changeset patch # User jittat # Date 2008-03-12 11:23:38 # Node ID b806077acf3a4aab459c39f1bc9d1febe0781e73 # Parent 914f6c15de62778d3e41e0730f66654c396677a5 [grader] added check_wrapper git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@111 6386c4cd-e34a-4fa8-8920-d93eb39b512e diff --git a/import_problem b/import_problem --- a/import_problem +++ b/import_problem @@ -94,12 +94,28 @@ # copy check script -if File.exists?(SCRIPT_DIR + "/templates/check.#{check_script}") - check_script_fname = SCRIPT_DIR + "/templates/check.#{check_script}" +if res = /^wrapper:(.*)$/.match(check_script) + # wrapper script + check_script_fname = res[1] + script_name = File.basename(check_script_fname) + check_wrapper_template = File.open(SCRIPT_DIR + "/templates/check_wrapper") + check_wrapper = ERB.new(template) + + check_file = File.open("#{problem}/script/check","w") + check_file.puts check_wrapper + check_file.close + + File.chmod(0755,"#{problem}/script/check") + + system("cp #{check_script_fname} #{problem}/script/#{script_name}") else - check_script_fname = check_script + if File.exists?(SCRIPT_DIR + "/templates/check.#{check_script}") + check_script_fname = SCRIPT_DIR + "/templates/check.#{check_script}" + else + check_script_fname = check_script + end + system("cp #{check_script_fname} #{problem}/script/check") end -system("cp #{check_script_fname} #{problem}/script/check") # generating test_request directory puts "generating test_request template" diff --git a/templates/check_wrapper b/templates/check_wrapper new file mode 100644 --- /dev/null +++ b/templates/check_wrapper @@ -0,0 +1,45 @@ +#!/usr/bin/ruby + +# +# This is a check script wrapper. It read all required information +# and call a real check script call REAL_CHECK_SCRIPT in directory +# [problem_home]/script +# + +REAL_CHECK_SCRIPT = "<%= script_name %>" + +# The REAL_CHECK_SCRIPT is called with: +# +# (script) +# +# and REAL_CHECK_SCRIPT's output to standard out is redirected to +# 'check_result' as required by normal check script. + +problem_home = ENV['PROBLEM_HOME'] +require "#{problem_home}/script/test_dsl.rb" + +if ARGV.length < 2 + puts "Usage: check []" + exit(0) +end + +language = ARGV[0] +test_num = ARGV[1].to_i +if ARGV.length >= 3 + output_file_name = ARGV[2] +else + output_file_name = "output.txt" +end + +load "#{problem_home}/test_cases/all_tests.cfg" +problem = Problem.get_instance + +answer_file_name = File.new("#{problem_home}/test_cases/#{test_num}/answer-#{test_num}.txt") +input_file_name = File.new("#{problem_home}/test_cases/#{test_num}/input-#{test_num}.txt") + +score = Problem.get_score(test_num) + +cmd = "#{problem_home}/script/#{REAL_CHECK_SCRIPT} " + + "#{language} #{test_num} #{input_file_name} #{output_file_name} " + + "#{answer_file_name} #{score} > check_result" +