Description:
updated test_request.rb to work with grader git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@92 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

r43:305f703e60aa - - 1 file changed: 10 inserted, 6 deleted

@@ -14,24 +14,32
14 14 #
15 15
16 16 require 'fileutils'
17 17
18 18 class TestRequest < Task
19 19
20 20 set_table_name "test_requests"
21 21
22 22 belongs_to :user
23 23 belongs_to :problem
24 24 belongs_to :submission
25 25
26 + def problem_name
27 + TestRequest.name_of(self.problem)
28 + end
29 +
30 + def language
31 + self.submission.language
32 + end
33 +
26 34 def self.get_inqueue_and_change_status(status)
27 35 # since there will be only one grader grading TestRequest
28 36 # we do not need locking (hopefully)
29 37
30 38 task = Task.find(:first,
31 39 :order => "created_at",
32 40 :conditions => {:status=> Task::STATUS_INQUEUE})
33 41 if task!=nil
34 42 task.status = status
35 43 task.save!
36 44 end
37 45
@@ -45,48 +53,44
45 53 problem = Problem.find(params[:problem_id])
46 54 test_request.problem = problem
47 55 test_request.submission =
48 56 Submission.find_by_user_problem_number(user.id,
49 57 problem.id,
50 58 params[:submission_number])
51 59 test_request.input_file_name = save_input_file(params[:input_file], user, problem)
52 60 test_request.submitted_at = Time.new
53 61 test_request.status_inqueue
54 62 test_request
55 63 end
56 64
57 - def problem_name
58 - TestRequest.name_of(self.problem)
59 - end
60 -
61 65 protected
62 66
63 67 def self.name_of(problem)
64 68 if problem!=nil
65 69 problem.name
66 70 else
67 71 "default"
68 72 end
69 73 end
70 74
71 - def self.input_file_name(user,problem)
75 + def self.random_input_file_name(user,problem)
72 76 problem_name = TestRequest.name_of(problem)
73 77 begin
74 78 tmpname = TEST_REQUEST_INPUT_FILE_DIR + "/#{user.login}/#{problem_name}/#{rand(10000)}"
75 79 end while File.exists?(tmpname)
76 80 tmpname
77 81 end
78 82
79 83 def self.save_input_file(tempfile, user, problem)
80 - new_file_name = input_file_name(user,problem)
84 + new_file_name = random_input_file_name(user,problem)
81 85 dirname = File.dirname(new_file_name)
82 86 FileUtils.mkdir_p(File.dirname(new_file_name)) if !File.exists?(dirname)
83 87 if tempfile.instance_of?(Tempfile)
84 88 tempfile.close
85 89 FileUtils.move(tempfile.path,new_file_name)
86 90 else
87 91 File.open(new_file_name, "wb") do |f|
88 92 f.write(tempfile.read)
89 93 end
90 94 end
91 95 new_file_name
92 96 end
You need to be logged in to leave comments. Login now