Description:
[grader] hack on language for output-only task git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@190 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r50:6e02aa1a5841 - - 1 file changed: 10 inserted, 3 deleted

@@ -1,131 +1,138
1 require 'fileutils'
1 require 'fileutils'
2
2
3 module Grader
3 module Grader
4
4
5 #
5 #
6 # A grader engine grades a submission, against anything: a test
6 # A grader engine grades a submission, against anything: a test
7 # data, or a user submitted test data. It uses two helpers objects:
7 # data, or a user submitted test data. It uses two helpers objects:
8 # room_maker and reporter.
8 # room_maker and reporter.
9 #
9 #
10 class Engine
10 class Engine
11
11
12 attr_writer :room_maker
12 attr_writer :room_maker
13 attr_writer :reporter
13 attr_writer :reporter
14
14
15 def initialize(room_maker=nil, reporter=nil)
15 def initialize(room_maker=nil, reporter=nil)
16 @config = Grader::Configuration.get_instance
16 @config = Grader::Configuration.get_instance
17
17
18 @room_maker = room_maker || Grader::SubmissionRoomMaker.new
18 @room_maker = room_maker || Grader::SubmissionRoomMaker.new
19 @reporter = reporter || Grader::SubmissionReporter.new
19 @reporter = reporter || Grader::SubmissionReporter.new
20 end
20 end
21
21
22 # takes a submission, asks room_maker to produce grading directories,
22 # takes a submission, asks room_maker to produce grading directories,
23 # calls grader scripts, and asks reporter to save the result
23 # calls grader scripts, and asks reporter to save the result
24 def grade(submission)
24 def grade(submission)
25 current_dir = `pwd`.chomp
25 current_dir = `pwd`.chomp
26
26
27 user = submission.user
27 user = submission.user
28 problem = submission.problem
28 problem = submission.problem
29
29
30 # TODO: will have to create real exception for this
30 # TODO: will have to create real exception for this
31 if user==nil or problem == nil
31 if user==nil or problem == nil
32 @reporter.report_error(submission,"Grading error: problem with submission")
32 @reporter.report_error(submission,"Grading error: problem with submission")
33 #raise "engine: user or problem is nil"
33 #raise "engine: user or problem is nil"
34 end
34 end
35 -
35 +
36 - language = submission.language.name
36 + # TODO: this is another hack so that output only task can be judged
37 - lang_ext = submission.language.ext
37 + if submission.language!=nil
38 + language = submission.language.name
39 + lang_ext = submission.language.ext
40 + else
41 + language = 'c'
42 + lang_ext = 'c'
43 + end
44 +
38 # FIX THIS
45 # FIX THIS
39 talk 'some hack on language'
46 talk 'some hack on language'
40 if language == 'cpp'
47 if language == 'cpp'
41 language = 'c++'
48 language = 'c++'
42 end
49 end
43
50
44 # COMMENT: should it be only source.ext?
51 # COMMENT: should it be only source.ext?
45 if problem!=nil
52 if problem!=nil
46 source_name = "#{problem.name}.#{lang_ext}"
53 source_name = "#{problem.name}.#{lang_ext}"
47 else
54 else
48 source_name = "source.#{lang_ext}"
55 source_name = "source.#{lang_ext}"
49 end
56 end
50
57
51 begin
58 begin
52 grading_dir = @room_maker.produce_grading_room(submission)
59 grading_dir = @room_maker.produce_grading_room(submission)
53 @room_maker.save_source(submission,source_name)
60 @room_maker.save_source(submission,source_name)
54 problem_home = @room_maker.find_problem_home(submission)
61 problem_home = @room_maker.find_problem_home(submission)
55
62
56 # puts "GRADING DIR: #{grading_dir}"
63 # puts "GRADING DIR: #{grading_dir}"
57 # puts "PROBLEM DIR: #{problem_home}"
64 # puts "PROBLEM DIR: #{problem_home}"
58
65
59 copy_log = copy_script(problem_home)
66 copy_log = copy_script(problem_home)
60
67
61 call_judge(problem_home,language,grading_dir,source_name)
68 call_judge(problem_home,language,grading_dir,source_name)
62
69
63 @reporter.report(submission,"#{grading_dir}/test-result")
70 @reporter.report(submission,"#{grading_dir}/test-result")
64
71
65 clear_script(copy_log,problem_home)
72 clear_script(copy_log,problem_home)
66
73
67 rescue RuntimeError => msg
74 rescue RuntimeError => msg
68 @reporter.report_error(submission,"Grading error: #{msg}")
75 @reporter.report_error(submission,"Grading error: #{msg}")
69
76
70 ensure
77 ensure
71 @room_maker.clean_up(submission)
78 @room_maker.clean_up(submission)
72 Dir.chdir(current_dir) # this is really important
79 Dir.chdir(current_dir) # this is really important
73 end
80 end
74 end
81 end
75
82
76 protected
83 protected
77
84
78 def talk(str)
85 def talk(str)
79 if @config.talkative
86 if @config.talkative
80 puts str
87 puts str
81 end
88 end
82 end
89 end
83
90
84 def call_judge(problem_home,language,grading_dir,fname)
91 def call_judge(problem_home,language,grading_dir,fname)
85 ENV['PROBLEM_HOME'] = problem_home
92 ENV['PROBLEM_HOME'] = problem_home
86
93
87 talk grading_dir
94 talk grading_dir
88 Dir.chdir grading_dir
95 Dir.chdir grading_dir
89 cmd = "#{problem_home}/script/judge #{language} #{fname}"
96 cmd = "#{problem_home}/script/judge #{language} #{fname}"
90 talk "CMD: #{cmd}"
97 talk "CMD: #{cmd}"
91 system(cmd)
98 system(cmd)
92 end
99 end
93
100
94 def get_std_script_dir
101 def get_std_script_dir
95 GRADER_ROOT + '/std-script'
102 GRADER_ROOT + '/std-script'
96 end
103 end
97
104
98 def copy_script(problem_home)
105 def copy_script(problem_home)
99 script_dir = "#{problem_home}/script"
106 script_dir = "#{problem_home}/script"
100 std_script_dir = get_std_script_dir
107 std_script_dir = get_std_script_dir
101
108
102 raise "std-script directory not found" if !FileTest.exist?(std_script_dir)
109 raise "std-script directory not found" if !FileTest.exist?(std_script_dir)
103
110
104 scripts = Dir[std_script_dir + '/*']
111 scripts = Dir[std_script_dir + '/*']
105
112
106 copied = []
113 copied = []
107
114
108 scripts.each do |s|
115 scripts.each do |s|
109 fname = File.basename(s)
116 fname = File.basename(s)
110 if !FileTest.exist?("#{script_dir}/#{fname}")
117 if !FileTest.exist?("#{script_dir}/#{fname}")
111 copied << fname
118 copied << fname
112 system("cp #{s} #{script_dir}")
119 system("cp #{s} #{script_dir}")
113 end
120 end
114 end
121 end
115
122
116 return copied
123 return copied
117 end
124 end
118
125
119 def clear_script(log,problem_home)
126 def clear_script(log,problem_home)
120 log.each do |s|
127 log.each do |s|
121 system("rm #{problem_home}/script/#{s}")
128 system("rm #{problem_home}/script/#{s}")
122 end
129 end
123 end
130 end
124
131
125 def mkdir_if_does_not_exist(dirname)
132 def mkdir_if_does_not_exist(dirname)
126 Dir.mkdir(dirname) if !FileTest.exist?(dirname)
133 Dir.mkdir(dirname) if !FileTest.exist?(dirname)
127 end
134 end
128
135
129 end
136 end
130
137
131 end
138 end
You need to be logged in to leave comments. Login now