Description:
(previous) new way for default script files git-svn-id: http://theory.cpe.ku.ac.th/grader/cli/trunk/scripts@26 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

r13:f103b0ea2e2a - - 1 file changed: 1 inserted, 1 deleted

@@ -114,108 +114,108
114 114 problem_out_dir = "#{user_dir}/#{problem.name}"
115 115 Dir.mkdir(problem_out_dir) if !FileTest.exist?(problem_out_dir)
116 116
117 117 problem_home = "#{PROBLEMS_DIR}/#{problem.name}"
118 118 source_name = "#{problem.name}.#{lang_ext}"
119 119
120 120 save_source(sub,problem_out_dir,source_name)
121 121
122 122 copy_log = copy_script(problem_home)
123 123
124 124 call_judge(problem_home,language,problem_out_dir,source_name)
125 125 save_result(sub,read_result("#{problem_out_dir}/test-result"))
126 126
127 127 clear_script(copy_log,problem_home)
128 128
129 129 Dir.chdir(current_dir)
130 130 end
131 131
132 132 def stop_grader
133 133 File.open(File.dirname(__FILE__) + '/stop','w').close
134 134 end
135 135
136 136 def check_stopfile
137 137 FileTest.exist?(File.dirname(__FILE__) + '/stop')
138 138 end
139 139
140 140 def clear_stopfile
141 141 system("rm " + File.dirname(__FILE__) + '/stop')
142 142 end
143 143
144 144 #########################################
145 145 # main program
146 146 #########################################
147 147
148 148 # reading environment and options
149 149 if (ARGV.length >= 1) and (ARGV[0]=='stop')
150 150 stop_grader
151 151 puts "stop file created"
152 152 exit(0)
153 153 end
154 154
155 155 if check_stopfile
156 156 puts "stop file exists"
157 157 clear_stopfile
158 158 exit(0)
159 159 end
160 160
161 161 grader_mode = 'queue'
162 162 if ARGV.length >= 1
163 163 GRADER_ENV = ARGV[0]
164 164 if ARGV.length >=2
165 165 grader_mode = ARGV[1]
166 166 end
167 167 else
168 168 GRADER_ENV = 'exam'
169 169 end
170 170
171 171 puts "environment: #{GRADER_ENV}"
172 172 require File.dirname(__FILE__) + "/environment.rb"
173 173
174 174 #main program
175 175 talk 'Reading rails environment'
176 176
177 177 RAILS_ENV = 'development'
178 178 require RAILS_APP_DIR + '/config/environment'
179 179
180 180 case grader_mode
181 181 when "queue"
182 182 talk 'Grader queue'
183 183 while true
184 184 if check_stopfile # created by calling grader stop
185 185 clear_stopfile
186 186 puts "stopped"
187 187 exit(0)
188 188 end
189 189
190 190 task = Task.find(:first, :order => 'created_at')
191 191 if task!=nil
192 192 grade(task.submission_id)
193 193 task.destroy
194 194 else
195 195 sleep(1)
196 196 end
197 197 end
198 198
199 199 when "prob"
200 200 prob = Problem.find_by_name(ARGV[2])
201 201 if prob==nil
202 202 puts "cannot find problem: #{ARGV[2]}"
203 203 exit(0)
204 204 end
205 205 users = User.find(:all)
206 206 users.each do |u|
207 207 puts "user: #{u.login}"
208 208 last_sub = Submission.find(:first,
209 209 :conditions => "user_id = #{u.id} and " +
210 - "problem_id = #{prob.id}",
210 + "problem_id = #{prob.id}",
211 211 :order => 'submitted_at DESC')
212 212 if last_sub!=nil
213 213 grade(last_sub.id)
214 214 end
215 215 end
216 216 end
217 217
218 218
219 219
220 220
221 221
You need to be logged in to leave comments. Login now