Description:
removed calls to 'pwd', other uses of back quotes
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r102:a3aedb7e3776 - - 4 files changed: 7 inserted, 5 deleted
@@ -1,14 +1,16 | |||||
|
1 | #!/usr/bin/ruby |
|
1 | #!/usr/bin/ruby |
|
2 |
|
2 | ||
|
|
3 | + require 'fileutils' | ||
|
|
4 | + | ||
|
3 | def talk(str) |
|
5 | def talk(str) |
|
4 | if TALKATIVE |
|
6 | if TALKATIVE |
|
5 | puts str |
|
7 | puts str |
|
6 | end |
|
8 | end |
|
7 | end |
|
9 | end |
|
8 |
|
10 | ||
|
9 | def save_source(submission,dir,fname) |
|
11 | def save_source(submission,dir,fname) |
|
10 | f = File.open("#{dir}/#{fname}","w") |
|
12 | f = File.open("#{dir}/#{fname}","w") |
|
11 | f.write(submission.source) |
|
13 | f.write(submission.source) |
|
12 | f.close |
|
14 | f.close |
|
13 | end |
|
15 | end |
|
14 |
|
16 | ||
@@ -76,14 +78,14 | |||||
|
76 |
|
78 | ||
|
77 | # reading environment and options |
|
79 | # reading environment and options |
|
78 | GRADER_ENV = 'exam' |
|
80 | GRADER_ENV = 'exam' |
|
79 | puts "environment: #{GRADER_ENV}" |
|
81 | puts "environment: #{GRADER_ENV}" |
|
80 | require File.dirname(__FILE__) + "/environment.rb" |
|
82 | require File.dirname(__FILE__) + "/environment.rb" |
|
81 |
|
83 | ||
|
82 | #main program |
|
84 | #main program |
|
83 | talk 'Reading rails environment' |
|
85 | talk 'Reading rails environment' |
|
84 |
|
86 | ||
|
85 | RAILS_ENV = 'development' |
|
87 | RAILS_ENV = 'development' |
|
86 | require RAILS_APP_DIR + '/config/environment' |
|
88 | require RAILS_APP_DIR + '/config/environment' |
|
87 |
|
89 | ||
|
88 |
- current_dir = |
|
90 | + current_dir = FileUtils.pwd |
|
89 | grade(ARGV[0].to_i) |
|
91 | grade(ARGV[0].to_i) |
@@ -22,25 +22,25 | |||||
|
22 | options[:reporter] = Grader::SubmissionReporter.new |
|
22 | options[:reporter] = Grader::SubmissionReporter.new |
|
23 | end |
|
23 | end |
|
24 |
|
24 | ||
|
25 | @config = Grader::Configuration.get_instance |
|
25 | @config = Grader::Configuration.get_instance |
|
26 |
|
26 | ||
|
27 | @room_maker = options[:room_maker] |
|
27 | @room_maker = options[:room_maker] |
|
28 | @reporter = options[:reporter] |
|
28 | @reporter = options[:reporter] |
|
29 | end |
|
29 | end |
|
30 |
|
30 | ||
|
31 | # takes a submission, asks room_maker to produce grading directories, |
|
31 | # takes a submission, asks room_maker to produce grading directories, |
|
32 | # calls grader scripts, and asks reporter to save the result |
|
32 | # calls grader scripts, and asks reporter to save the result |
|
33 | def grade(submission) |
|
33 | def grade(submission) |
|
34 |
- current_dir = |
|
34 | + current_dir = FileUtils.pwd |
|
35 |
|
35 | ||
|
36 | user = submission.user |
|
36 | user = submission.user |
|
37 | problem = submission.problem |
|
37 | problem = submission.problem |
|
38 |
|
38 | ||
|
39 | # TODO: will have to create real exception for this |
|
39 | # TODO: will have to create real exception for this |
|
40 | if user==nil or problem == nil |
|
40 | if user==nil or problem == nil |
|
41 | @reporter.report_error(submission,"Grading error: problem with submission") |
|
41 | @reporter.report_error(submission,"Grading error: problem with submission") |
|
42 | #raise "engine: user or problem is nil" |
|
42 | #raise "engine: user or problem is nil" |
|
43 | end |
|
43 | end |
|
44 |
|
44 | ||
|
45 | # TODO: this is another hack so that output only task can be judged |
|
45 | # TODO: this is another hack so that output only task can be judged |
|
46 | if submission.language!=nil |
|
46 | if submission.language!=nil |
@@ -57,25 +57,25 | |||||
|
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 |
|
60 |
|
60 | ||
|
61 | source_file = ARGV[1] |
|
61 | source_file = ARGV[1] |
|
62 | if File.exist?(source_file) == false |
|
62 | if File.exist?(source_file) == false |
|
63 | log "The source file does not exist." |
|
63 | log "The source file does not exist." |
|
64 | exit(127) |
|
64 | exit(127) |
|
65 | end |
|
65 | end |
|
66 |
|
66 | ||
|
67 | log "Making test result and sandbox directories..." |
|
67 | log "Making test result and sandbox directories..." |
|
68 |
|
68 | ||
|
69 |
- current_dir = |
|
69 | + current_dir = FileUtils.pwd |
|
70 | current_dir.strip! |
|
70 | current_dir.strip! |
|
71 |
|
71 | ||
|
72 | if ARGV.length >= 3 |
|
72 | if ARGV.length >= 3 |
|
73 | test_result_dir = ARGV[2] |
|
73 | test_result_dir = ARGV[2] |
|
74 | else |
|
74 | else |
|
75 | test_result_dir = "#{current_dir}/test-result" |
|
75 | test_result_dir = "#{current_dir}/test-result" |
|
76 | end |
|
76 | end |
|
77 |
|
77 | ||
|
78 | log "Test result directory: #{test_result_dir}" |
|
78 | log "Test result directory: #{test_result_dir}" |
|
79 | clear_and_create_empty_dir(test_result_dir) |
|
79 | clear_and_create_empty_dir(test_result_dir) |
|
80 |
|
80 | ||
|
81 | if ARGV.length >= 4 |
|
81 | if ARGV.length >= 4 |
@@ -90,25 +90,25 | |||||
|
90 | log |
|
90 | log |
|
91 | log "Compiling..." |
|
91 | log "Compiling..." |
|
92 | call_and_log("Cannot copy the source file to #{sandbox_dir}") { |
|
92 | call_and_log("Cannot copy the source file to #{sandbox_dir}") { |
|
93 | FileUtils.cp(source_file, sandbox_dir) |
|
93 | FileUtils.cp(source_file, sandbox_dir) |
|
94 | } |
|
94 | } |
|
95 | begin |
|
95 | begin |
|
96 | Dir.chdir sandbox_dir |
|
96 | Dir.chdir sandbox_dir |
|
97 | rescue |
|
97 | rescue |
|
98 | log "ERROR: Cannot change directory to #{sandbox_dir}." |
|
98 | log "ERROR: Cannot change directory to #{sandbox_dir}." |
|
99 | exit(127) |
|
99 | exit(127) |
|
100 | end |
|
100 | end |
|
101 | execute("#{problem_home}/script/compile #{language} #{source_file}", "Compilation error!") |
|
101 | execute("#{problem_home}/script/compile #{language} #{source_file}", "Compilation error!") |
|
102 |
- compile_message = |
|
102 | + compile_message = open("compiler_message").read |
|
103 | compile_message.strip! |
|
103 | compile_message.strip! |
|
104 | call_and_log("Cannot move the compiler message to #{test_result_dir}.") { |
|
104 | call_and_log("Cannot move the compiler message to #{test_result_dir}.") { |
|
105 | FileUtils.mv("compiler_message", test_result_dir) |
|
105 | FileUtils.mv("compiler_message", test_result_dir) |
|
106 | } |
|
106 | } |
|
107 | if !FileTest.exist?("a.out") |
|
107 | if !FileTest.exist?("a.out") |
|
108 | log "Cannot compile the source code. See message in #{test_result_dir}/compile_message" |
|
108 | log "Cannot compile the source code. See message in #{test_result_dir}/compile_message" |
|
109 | exit(127) |
|
109 | exit(127) |
|
110 | else |
|
110 | else |
|
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 | } |
|
113 | } |
|
114 | FileUtils.rm_rf("#{sandbox_dir}/.") |
|
114 | FileUtils.rm_rf("#{sandbox_dir}/.") |
@@ -102,25 +102,25 | |||||
|
102 |
|
102 | ||
|
103 | run_stat = run_result[run_result.length-1] |
|
103 | run_stat = run_result[run_result.length-1] |
|
104 | running_time = extract_time(run_stat) |
|
104 | running_time = extract_time(run_stat) |
|
105 |
|
105 | ||
|
106 | report = lambda{ |status, points, comment| |
|
106 | report = lambda{ |status, points, comment| |
|
107 | result_file.write status.strip |
|
107 | result_file.write status.strip |
|
108 | result_file.write "\n" |
|
108 | result_file.write "\n" |
|
109 | result_file.write points.to_s.strip |
|
109 | result_file.write points.to_s.strip |
|
110 | result_file.write "\n" |
|
110 | result_file.write "\n" |
|
111 | result_file.write run_stat.strip |
|
111 | result_file.write run_stat.strip |
|
112 | result_file.write "\n" |
|
112 | result_file.write "\n" |
|
113 | result_file.close |
|
113 | result_file.close |
|
114 |
- |
|
114 | + FileUtils.rm "run_result" |
|
115 | # `rm output.txt` --- keep the output |
|
115 | # `rm output.txt` --- keep the output |
|
116 |
|
116 | ||
|
117 | comment_file.write comment |
|
117 | comment_file.write comment |
|
118 |
|
118 | ||
|
119 | # added for debuggin --- jittat |
|
119 | # added for debuggin --- jittat |
|
120 | comment_file.write "--run-result--\n" |
|
120 | comment_file.write "--run-result--\n" |
|
121 | run_result.each do |l| |
|
121 | run_result.each do |l| |
|
122 | comment_file.write l |
|
122 | comment_file.write l |
|
123 | end |
|
123 | end |
|
124 |
|
124 | ||
|
125 | comment_file.close |
|
125 | comment_file.close |
|
126 |
|
126 |
You need to be logged in to leave comments.
Login now