Description:
add python support
we compile it into bytecode before run
(see 'judge' and 'run')
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r154:3e585749d18c - - 3 files changed: 28 inserted, 7 deleted
@@ -27,12 +27,15 | |||||
|
27 | CPLUSPLUS_COMPILER = "/usr/bin/g++" |
|
27 | CPLUSPLUS_COMPILER = "/usr/bin/g++" |
|
28 | PASCAL_COMPILER = "/usr/bin/fpc" |
|
28 | PASCAL_COMPILER = "/usr/bin/fpc" |
|
29 | JAVA_COMPILER = "/usr/bin/javac" |
|
29 | JAVA_COMPILER = "/usr/bin/javac" |
|
30 | - RUBY_INTEPRETER = "/home/dae/.rvm/rubies/ruby-1.9.2-p320/bin/ruby" |
|
30 | + RUBY_INTERPRETER = "/home/dae/.rvm/rubies/ruby-1.9.2-p320/bin/ruby" |
|
|
31 | + PYTHON_INTERPRETER = "/usr/bin/python" | ||
|
|
32 | + PYTHON_CHECKER = "/usr/bin/pyflakes" | ||
|
31 |
|
33 | ||
|
32 | C_OPTIONS = "-O2 -s -static -std=c99 -DCONTEST -lm -Wall" |
|
34 | C_OPTIONS = "-O2 -s -static -std=c99 -DCONTEST -lm -Wall" |
|
33 | CPLUSPLUS_OPTIONS = "-O2 -s -static -DCONTEST -lm -Wall" |
|
35 | CPLUSPLUS_OPTIONS = "-O2 -s -static -DCONTEST -lm -Wall" |
|
34 | PASCAL_OPTIONS = "-O1 -XS -dCONTEST" |
|
36 | PASCAL_OPTIONS = "-O1 -XS -dCONTEST" |
|
35 | JAVA_OPTIONS = "" |
|
37 | JAVA_OPTIONS = "" |
|
|
38 | + PYTHON_OPTIONS = "" | ||
|
36 |
|
39 | ||
|
37 | # Check for the correct number of arguments. Otherwise, print usage. |
|
40 | # Check for the correct number of arguments. Otherwise, print usage. |
|
38 | if ARGV.length == 0 or ARGV.length > 4 |
|
41 | if ARGV.length == 0 or ARGV.length > 4 |
@@ -118,16 +121,31 | |||||
|
118 | end |
|
121 | end |
|
119 |
|
122 | ||
|
120 |
|
|
123 | when "ruby" |
|
121 | - command = "#{RUBY_INTEPRETER} -c #{params[:source_file]} > #{params[:message_file]}" |
|
124 | + command = "#{RUBY_INTERPRETER} -c #{params[:source_file]} > #{params[:message_file]}" |
|
122 | system(command) |
|
125 | system(command) |
|
123 | File.open(params[:output_file],"w") do |out_file| |
|
126 | File.open(params[:output_file],"w") do |out_file| |
|
124 | - out_file.puts "#!#{RUBY_INTEPRETER}" |
|
127 | + out_file.puts "#!#{RUBY_INTERPRETER}" |
|
125 | File.open(params[:source_file],"r").each do |line| |
|
128 | File.open(params[:source_file],"r").each do |line| |
|
126 | out_file.print line |
|
129 | out_file.print line |
|
127 | end |
|
130 | end |
|
128 | end |
|
131 | end |
|
129 | File.chmod(0755, params[:output_file]) |
|
132 | File.chmod(0755, params[:output_file]) |
|
130 |
|
133 | ||
|
|
134 | + when "python" | ||
|
|
135 | + command = "#{PYTHON_CHECKER} #{params[:source_file]} > #{params[:message_file]}" | ||
|
|
136 | + if system(command) | ||
|
|
137 | + #compile to python bytecode | ||
|
|
138 | + command = "#{PYTHON_INTERPRETER} -m py_compile #{params[:source_file]}" | ||
|
|
139 | + puts "compile: #{command}" | ||
|
|
140 | + system(command) | ||
|
|
141 | + puts "pwd: " + Dir.pwd | ||
|
|
142 | + Dir.new('.').each {|file| puts file} | ||
|
|
143 | + File.open(params[:output_file],"w") do |out_file| | ||
|
|
144 | + out_file.puts "#!#{PYTHON_INTERPRETER} #{params[:source_file]}c" | ||
|
|
145 | + end | ||
|
|
146 | + File.chmod(0755, params[:output_file]) | ||
|
|
147 | + end | ||
|
|
148 | + | ||
|
131 |
|
|
149 | else |
|
132 | talk("ERROR: Invalid language specified!") |
|
150 | talk("ERROR: Invalid language specified!") |
|
133 | open(params[:message_file],"w") do |f| |
|
151 | open(params[:message_file],"w") do |f| |
@@ -53,7 +53,7 | |||||
|
53 | end |
|
53 | end |
|
54 |
|
54 | ||
|
55 | language = ARGV[0] |
|
55 | language = ARGV[0] |
|
56 | - if language != "c" && language != "c++" && language != "pas" && language != "java" && language != "ruby" |
|
56 | + if language != "c" && language != "c++" && language != "pas" && language != "java" && language != "ruby" && language != "python" |
|
57 | log "You specified a language that is not supported: #{language}." |
|
57 | log "You specified a language that is not supported: #{language}." |
|
58 | exit(127) |
|
58 | exit(127) |
|
59 | end |
|
59 | end |
@@ -111,6 +111,7 | |||||
|
111 | call_and_log("Cannot move the compiled program to #{test_result_dir}") { |
|
111 | call_and_log("Cannot move the compiled program to #{test_result_dir}") { |
|
112 | FileUtils.mv("a.out",test_result_dir) |
|
112 | FileUtils.mv("a.out",test_result_dir) |
|
113 | if language == "java" then Dir["*.class"].each { |file| FileUtils.mv(file,test_result_dir)} end |
|
113 | if language == "java" then Dir["*.class"].each { |file| FileUtils.mv(file,test_result_dir)} end |
|
|
114 | + if language == "python" then Dir["*.pyc"].each { |file| FileUtils.mv(file,test_result_dir)} end | ||
|
114 | } |
|
115 | } |
|
115 | FileUtils.rm_rf("#{sandbox_dir}/.") |
|
116 | FileUtils.rm_rf("#{sandbox_dir}/.") |
|
116 | end |
|
117 | end |
@@ -135,6 +136,7 | |||||
|
135 | call_and_log("Cannot copy the compiled program into #{sandbox_dir}") { |
|
136 | call_and_log("Cannot copy the compiled program into #{sandbox_dir}") { |
|
136 | FileUtils.cp("#{test_result_dir}/a.out", sandbox_dir, :preserve => true) |
|
137 | FileUtils.cp("#{test_result_dir}/a.out", sandbox_dir, :preserve => true) |
|
137 | if language == "java" then Dir["#{test_result_dir}/*.class"].each { |file| FileUtils.cp(file,sandbox_dir)} end |
|
138 | if language == "java" then Dir["#{test_result_dir}/*.class"].each { |file| FileUtils.cp(file,sandbox_dir)} end |
|
|
139 | + if language == "python" then Dir["#{test_result_dir}/*.pyc"].each { |file| FileUtils.cp(file,sandbox_dir)} end | ||
|
138 | } |
|
140 | } |
|
139 |
|
141 | ||
|
140 | begin |
|
142 | begin |
@@ -96,9 +96,10 | |||||
|
96 | run_command = "#{problem_home}/script/box -T -t #{time_limit} -s getppid -s clone -s wait4 -p /usr/bin/ -p ./ -i #{input_file_name} -o output.txt #{program_name} 2>run_result" |
|
96 | run_command = "#{problem_home}/script/box -T -t #{time_limit} -s getppid -s clone -s wait4 -p /usr/bin/ -p ./ -i #{input_file_name} -o output.txt #{program_name} 2>run_result" |
|
97 | when "ruby" |
|
97 | when "ruby" |
|
98 | run_command = "#{problem_home}/script/box -T -t #{time_limit} -s getppid -s wait4 -s clone -s set_robust_list -s futex -s sigaltstack -p /dev/urandom -p ./ -p /home/dae/.rvm/rubies/ruby-1.9.2-p320/ -p #{problem_home}/ -i #{input_file_name} -o output.txt #{program_name} 2>run_result" |
|
98 | run_command = "#{problem_home}/script/box -T -t #{time_limit} -s getppid -s wait4 -s clone -s set_robust_list -s futex -s sigaltstack -p /dev/urandom -p ./ -p /home/dae/.rvm/rubies/ruby-1.9.2-p320/ -p #{problem_home}/ -i #{input_file_name} -o output.txt #{program_name} 2>run_result" |
|
99 |
- when " |
|
99 | + when "python" |
|
100 | - run_command = "#{problem_home}/script/box -a 2 -f -T -t #{time_limit} -m #{mem_limit} -i #{input_file_name} -o output.txt #{program_name} 2>run_result" |
|
100 | + #this code just run without any checking |
|
101 | - else |
|
101 | + run_command = "#{problem_home}/script/box -T -t #{time_limit} -p #{problem_home}/ -i #{input_file_name} -o output.txt #{program_name} 2>run_result" |
|
|
102 | + else # for c++, pascal, we do the normal checking | ||
|
102 | run_command = "#{problem_home}/script/box -a 2 -f -T -t #{time_limit} -m #{mem_limit} -i #{input_file_name} -o output.txt #{program_name} 2>run_result" |
|
103 | run_command = "#{problem_home}/script/box -a 2 -f -T -t #{time_limit} -m #{mem_limit} -i #{input_file_name} -o output.txt #{program_name} 2>run_result" |
|
103 | end |
|
104 | end |
|
104 |
|
105 |
You need to be logged in to leave comments.
Login now