Description:
new default config file
git-svn-id: http://theory.cpe.ku.ac.th/grader/cli/trunk/scripts@25 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r12:dd4ebb184900 - - 1 file changed: 2 inserted, 2 deleted
@@ -26,113 +26,113 | |||
|
26 | 26 | Dir.chdir problem_out_dir |
|
27 | 27 | cmd = "#{problem_home}/script/judge #{language} #{fname}" |
|
28 | 28 | # puts "CMD: #{cmd}" |
|
29 | 29 | system(cmd) |
|
30 | 30 | end |
|
31 | 31 | |
|
32 | 32 | def read_result(test_result_dir) |
|
33 | 33 | cmp_msg_fname = "#{test_result_dir}/compiler_message" |
|
34 | 34 | cmp_file = File.open(cmp_msg_fname) |
|
35 | 35 | cmp_msg = cmp_file.read |
|
36 | 36 | cmp_file.close |
|
37 | 37 | |
|
38 | 38 | result_fname = "#{test_result_dir}/result" |
|
39 | 39 | comment_fname = "#{test_result_dir}/comment" |
|
40 | 40 | if FileTest.exist?(result_fname) |
|
41 | 41 | result_file = File.open(result_fname) |
|
42 | 42 | result = result_file.readline.to_i |
|
43 | 43 | result_file.close |
|
44 | 44 | |
|
45 | 45 | comment_file = File.open(comment_fname) |
|
46 | 46 | comment = comment_file.readline.chomp |
|
47 | 47 | comment_file.close |
|
48 | 48 | |
|
49 | 49 | return {:points => result, |
|
50 | 50 | :comment => comment, |
|
51 | 51 | :cmp_msg => cmp_msg} |
|
52 | 52 | else |
|
53 | 53 | return {:points => 0, |
|
54 | 54 | :comment => 'compile error', |
|
55 | 55 | :cmp_msg => cmp_msg} |
|
56 | 56 | end |
|
57 | 57 | end |
|
58 | 58 | |
|
59 | 59 | def save_result(submission,result) |
|
60 | 60 | problem = Problem.find(submission.problem_id) |
|
61 | 61 | submission.graded_at = Time.now |
|
62 | 62 | submission.points = result[:points] |
|
63 | 63 | if submission.points == problem.full_score |
|
64 | 64 | submission.grader_comment = 'PASSED: ' + report_comment(result[:comment]) |
|
65 | 65 | else |
|
66 | 66 | submission.grader_comment = 'FAILED: ' + report_comment(result[:comment]) |
|
67 | 67 | end |
|
68 | 68 | submission.compiler_message = result[:cmp_msg] |
|
69 | 69 | submission.save |
|
70 | 70 | end |
|
71 | 71 | |
|
72 | 72 | def copy_script(problem_home) |
|
73 | 73 | script_dir = "#{problem_home}/script" |
|
74 |
- std_script_dir = File.dirname(__FILE__) + '/std-script |
|
|
74 | + std_script_dir = File.dirname(__FILE__) + '/std-script' | |
|
75 | 75 | scripts = Dir[std_script_dir + '/*'] |
|
76 | 76 | |
|
77 | 77 | copied = [] |
|
78 | 78 | |
|
79 | 79 | scripts.each do |s| |
|
80 | 80 | fname = File.basename(s) |
|
81 | 81 | if !FileTest.exist?("#{script_dir}/#{fname}") |
|
82 | 82 | copied << fname |
|
83 | 83 | system("cp #{s} #{script_dir}") |
|
84 | 84 | end |
|
85 | 85 | end |
|
86 | 86 | |
|
87 | 87 | return copied |
|
88 | 88 | end |
|
89 | 89 | |
|
90 |
- def clear_script(problem_home |
|
|
90 | + def clear_script(log,problem_home) | |
|
91 | 91 | log.each do |s| |
|
92 | 92 | system("rm #{problem_home}/script/#{s}") |
|
93 | 93 | end |
|
94 | 94 | end |
|
95 | 95 | |
|
96 | 96 | def grade(submission_id) |
|
97 | 97 | current_dir = `pwd`.chomp |
|
98 | 98 | |
|
99 | 99 | sub = Submission.find(submission_id) |
|
100 | 100 | user = sub.user |
|
101 | 101 | problem = sub.problem |
|
102 | 102 | |
|
103 | 103 | language = sub.language.name |
|
104 | 104 | lang_ext = sub.language.ext |
|
105 | 105 | # FIX THIS |
|
106 | 106 | talk 'some hack on language' |
|
107 | 107 | if language == 'cpp' |
|
108 | 108 | language = 'c++' |
|
109 | 109 | end |
|
110 | 110 | |
|
111 | 111 | user_dir = "#{USER_RESULT_DIR}/#{user.login}" |
|
112 | 112 | Dir.mkdir(user_dir) if !FileTest.exist?(user_dir) |
|
113 | 113 | |
|
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 |
You need to be logged in to leave comments.
Login now