Description:
add grader stop, fix ARGV bug
git-svn-id: http://theory.cpe.ku.ac.th/grader/cli/trunk/scripts@19 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
r6:f3b2d1128766 - - 1 file changed: 37 inserted, 5 deleted
@@ -36,76 +36,108 | |||
|
36 | 36 | if FileTest.exist?(result_fname) |
|
37 | 37 | result = File.open(result_fname).readline.to_i |
|
38 | 38 | comment = File.open(comment_fname).readline.chomp |
|
39 | 39 | return {:points => result, |
|
40 | 40 | :comment => comment, |
|
41 | 41 | :cmp_msg => cmp_msg} |
|
42 | 42 | else |
|
43 | 43 | return {:points => 0, |
|
44 | 44 | :comment => 'compile error', |
|
45 | 45 | :cmp_msg => cmp_msg} |
|
46 | 46 | end |
|
47 | 47 | end |
|
48 | 48 | |
|
49 | 49 | def save_result(submission,result) |
|
50 | 50 | submission.graded_at = Time.now |
|
51 | 51 | submission.points = result[:points] |
|
52 | 52 | submission.grader_comment = report_comment(result[:comment]) |
|
53 | 53 | submission.compiler_message = result[:cmp_msg] |
|
54 | 54 | submission.save |
|
55 | 55 | end |
|
56 | 56 | |
|
57 | 57 | def grade(submission_id) |
|
58 | 58 | sub = Submission.find(submission_id) |
|
59 | 59 | user = sub.user |
|
60 | 60 | problem = sub.problem |
|
61 | 61 | |
|
62 | 62 | language = sub.language.name |
|
63 | 63 | lang_ext = sub.language.ext |
|
64 | 64 | # FIX THIS |
|
65 | 65 | talk 'some hack on language' |
|
66 | 66 | if language == 'cpp' |
|
67 | 67 | language = 'c++' |
|
68 | 68 | end |
|
69 | 69 | |
|
70 | 70 | user_dir = "#{USER_RESULT_DIR}/#{user.login}" |
|
71 | 71 | Dir.mkdir(user_dir) if !FileTest.exist?(user_dir) |
|
72 | 72 | |
|
73 | 73 | problem_out_dir = "#{user_dir}/#{problem.name}" |
|
74 | 74 | Dir.mkdir(problem_out_dir) if !FileTest.exist?(problem_out_dir) |
|
75 | 75 | |
|
76 | 76 | problem_home = "#{PROBLEMS_DIR}/#{problem.name}" |
|
77 | 77 | source_name = "#{problem.name}.#{lang_ext}" |
|
78 | 78 | |
|
79 | 79 | save_source(sub,problem_out_dir,source_name) |
|
80 | 80 | call_judge(problem_home,language,problem_out_dir,source_name) |
|
81 | 81 | save_result(sub,read_result("#{problem_out_dir}/test-result")) |
|
82 | 82 | end |
|
83 | 83 | |
|
84 | - # reading environment | |
|
85 | - GRADER_ENV = 'exam' | |
|
86 | - if ARGV.length > 1 | |
|
87 | - GRADER_ENV = ARGV[1] | |
|
84 | + def stop_grader | |
|
85 | + File.open(File.dirname(__FILE__) + '/stop','w') | |
|
86 | + end | |
|
87 | + | |
|
88 | + def check_stopfile | |
|
89 | + FileTest.exist?(File.dirname(__FILE__) + '/stop') | |
|
90 | + end | |
|
91 | + | |
|
92 | + def clear_stopfile | |
|
93 | + system("rm " + File.dirname(__FILE__) + '/stop') | |
|
88 | 94 | end |
|
95 | + | |
|
96 | + # reading environment and options | |
|
97 | + if (ARGV.length >= 1) and (ARGV[0]=='stop') | |
|
98 | + stop_grader | |
|
99 | + puts "stop file created" | |
|
100 | + exit(0) | |
|
101 | + end | |
|
102 | + | |
|
103 | + if check_stopfile | |
|
104 | + puts "stop file exists" | |
|
105 | + clear_stopfile | |
|
106 | + exit(0) | |
|
107 | + end | |
|
108 | + | |
|
109 | + if ARGV.length >= 1 | |
|
110 | + GRADER_ENV = ARGV[0] | |
|
111 | + else | |
|
112 | + GRADER_ENV = 'exam' | |
|
113 | + end | |
|
114 | + | |
|
115 | + puts "environment: #{GRADER_ENV}" | |
|
89 | 116 | require File.dirname(__FILE__) + "/environment.rb" |
|
90 | 117 | |
|
91 | 118 | #main program |
|
92 | - | |
|
93 | 119 | talk 'Reading rails environment' |
|
94 | 120 | |
|
95 | 121 | RAILS_ENV = 'development' |
|
96 | 122 | require RAILS_APP_DIR + '/config/environment' |
|
97 | 123 | |
|
98 | 124 | current_dir = `pwd` |
|
99 | 125 | |
|
100 | 126 | talk 'Grader queue' |
|
101 | 127 | while true |
|
128 | + if check_stopfile # created by calling grader stop | |
|
129 | + clear_stopfile | |
|
130 | + puts "stopped" | |
|
131 | + exit(0) | |
|
132 | + end | |
|
133 | + | |
|
102 | 134 | task = Task.find(:first, :order => 'created_at') |
|
103 | 135 | if task!=nil |
|
104 | 136 | grade(task.submission_id) |
|
105 | 137 | task.destroy |
|
106 | 138 | else |
|
107 | 139 | sleep(1) |
|
108 | 140 | end |
|
109 | 141 | end |
|
110 | 142 | |
|
111 | 143 |
You need to be logged in to leave comments.
Login now