Description:
add description to import_problem git-svn-id: http://theory.cpe.ku.ac.th/grader/cli/trunk/scripts@32 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

r15:a8e414606a2b - - 2 files changed: 115 inserted, 1 deleted

@@ -0,0 +1,110
1 + #!/usr/bin/ruby
2 +
3 + def talk(str)
4 + if TALKATIVE
5 + puts str
6 + end
7 + end
8 +
9 + def execute(command, error_message="")
10 + if not system(command)
11 + puts "ERROR: #{error_message}"
12 + exit(127)
13 + end
14 + end
15 +
16 + def save_source(submission,dir,fname)
17 + f = File.open("#{dir}/#{fname}","w")
18 + f.write(submission.source)
19 + f.close
20 + end
21 +
22 + def call_judge(problem_home,language,problem_out_dir,fname)
23 + ENV['PROBLEM_HOME'] = problem_home
24 + Dir.chdir problem_out_dir
25 + cmd = "#{problem_home}/script/judge #{language} #{fname}"
26 + # puts "CMD: #{cmd}"
27 + system(cmd)
28 + end
29 +
30 + def read_result(test_result_dir)
31 + cmp_msg_fname = "#{test_result_dir}/compiler_message"
32 + cmp_msg = File.open(cmp_msg_fname).read
33 +
34 + result_fname = "#{test_result_dir}/result"
35 + comment_fname = "#{test_result_dir}/comment"
36 + if FileTest.exist?(result_fname)
37 + result = File.open(result_fname).readline.to_i
38 + comment = File.open(comment_fname).readline.chomp
39 + return {:points => result,
40 + :comment => comment,
41 + :cmp_msg => cmp_msg}
42 + else
43 + return {:points => 0,
44 + :comment => 'compile error',
45 + :cmp_msg => cmp_msg}
46 + end
47 + end
48 +
49 + def save_result(submission,result)
50 + submission.graded_at = Time.now
51 + submission.points = result[:points]
52 + submission.grader_comment = report_comment(result[:comment])
53 + submission.compiler_message = result[:cmp_msg]
54 + submission.save
55 + end
56 +
57 + def grade(submission_id)
58 + sub = Submission.find(submission_id)
59 + user = sub.user
60 + problem = sub.problem
61 +
62 + language = sub.language.name
63 + lang_ext = sub.language.ext
64 + # FIX THIS
65 + talk 'some hack on language'
66 + if language == 'cpp'
67 + language = 'c++'
68 + end
69 +
70 + user_dir = "#{USER_RESULT_DIR}/#{user.login}"
71 + Dir.mkdir(user_dir) if !FileTest.exist?(user_dir)
72 +
73 + problem_out_dir = "#{user_dir}/#{problem.name}"
74 + Dir.mkdir(problem_out_dir) if !FileTest.exist?(problem_out_dir)
75 +
76 + problem_home = "#{PROBLEMS_DIR}/#{problem.name}"
77 + source_name = "#{problem.name}.#{lang_ext}"
78 +
79 + save_source(sub,problem_out_dir,source_name)
80 + call_judge(problem_home,language,problem_out_dir,source_name)
81 + save_result(sub,read_result("#{problem_out_dir}/test-result"))
82 + end
83 +
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')
94 + end
95 +
96 + # reading environment and options
97 + GRADER_ENV = 'exam'
98 + puts "environment: #{GRADER_ENV}"
99 + require File.dirname(__FILE__) + "/environment.rb"
100 +
101 + #main program
102 + talk 'Reading rails environment'
103 +
104 + RAILS_ENV = 'development'
105 + require RAILS_APP_DIR + '/config/environment'
106 +
107 + current_dir = `pwd`
108 + grade(ARGV[0].to_i)
109 +
110 +
@@ -38,7 +38,11
38
38
39 # print usage
39 # print usage
40 if ARGV.length < 3
40 if ARGV.length < 3
41 - puts "using: import_task problem importing_testcase_dir number_of_testcase [options]"
41 + puts "using: import_problem prob_name importing_testcase_dir num_of_testcase [options]
42 + * creates a directory for a problem in the current directory,
43 + * copy testdata in the old format and create standard testcase config file
44 + * options: -t time-limit (in seconds)
45 + -m memory-limit (in megabytes)"
42 exit(127)
46 exit(127)
43 end
47 end
44
48
You need to be logged in to leave comments. Login now