# HG changeset patch # User Nattee Niparnan # Date 2018-07-11 10:33:10 # Node ID 8d92eda439607be4f76ef281b8c5a43c8ee7f8d8 # Parent 0654ec1bf773f72aa16191b0c7db4c8146cb24ad - new install script - add comment in grader chain diff --git a/installer/install.sh b/installer/install.sh --- a/installer/install.sh +++ b/installer/install.sh @@ -1,25 +1,10 @@ #!/bin/sh +#installation script for cafe-grader, for ubuntu 16.04 + echo "This script will install and configure Cafe grader." -RUBY_VERSION=2.1.2 -echo "This will install Ruby $RUBY_VERSION under RVM" - -echo "Installing required apts" - -sudo apt-get update -sudo apt-get install mysql-server mysql-client \ - g++ gcc apache2 libmysqlclient20 build-essential \ - git-core openssl libreadline6 libreadline6-dev \ - zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev \ - sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev \ - ncurses-dev automake libtool bison subversion \ - pkg-config curl nodejs unzip pyflakes ruby default-jdk \ - libmysqld-dev mercurial python-setuptools python-dev python3-numpy - -echo "Installing RVM" -curl -k -L https://get.rvm.io | bash -s stable -source ~/.rvm/scripts/rvm +RUBY_VERSION=2.3.7 echo "Installing Ruby $RUBY_VERSION in RVM" @@ -32,7 +17,7 @@ mkdir cafe_grader cd cafe_grader -git clone -q git://github.com/jittat/cafe-grader-web.git web +git clone -q git://github.com/cafe-grader-team/cafe-grader-web.git web echo "Configuring rails app" @@ -132,6 +117,17 @@ rake assets:precompile +echo "setup the secret file" +SECRET_A=`rake secret` +SECRET_B=`rake secret` +SECRET_C=`rake secret` +echo "development:" > config/secrets.yml +echo " secret_key_base: '$SECRET_A'" >> config/secrets.yml +echo "test:" >> config/secrets.yml +echo " secret_key_base: '$SECRET_B'" >> config/secrets.yml +echo "production:" >> config/secrets.yml +echo " secret_key_base: '$SECRET_C'" >> config/secrets.yml + echo "Intalling web interface complete..." echo echo "Fetching grader" @@ -140,7 +136,7 @@ mkdir judge cd judge -git clone -q git://github.com/jittat/cafe-grader-judge-scripts.git scripts +git clone -q git://github.com/cafe-grader-team/cafe-grader-judge-scripts.git scripts mkdir raw mkdir ev-exam mkdir ev diff --git a/lib/engine.rb b/lib/engine.rb --- a/lib/engine.rb +++ b/lib/engine.rb @@ -9,7 +9,7 @@ # room_maker and reporter. # class Engine - + attr_writer :room_maker attr_writer :reporter @@ -27,7 +27,7 @@ @room_maker = options[:room_maker] @reporter = options[:reporter] end - + # takes a submission, asks room_maker to produce grading directories, # calls grader scripts, and asks reporter to save the result def grade(submission) @@ -77,17 +77,20 @@ raise "engine: No test data." end + # copy the source script, using lock dinit = DirInit::Manager.new(problem_home) + # lock the directory and copy the scripts dinit.setup do copy_log = copy_script(problem_home) save_copy_log(problem_home,copy_log) end - + call_judge(problem_home,language,grading_dir,source_name) @reporter.report(submission,"#{grading_dir}/test-result") + # unlock the directory dinit.teardown do copy_log = load_copy_log(problem_home) clear_copy_log(problem_home) @@ -103,19 +106,21 @@ Dir.chdir(current_dir) # this is really important end end - + protected - + def talk(str) if @config.talkative puts str end end + #change directory to problem_home + #call the "judge" script def call_judge(problem_home,language,grading_dir,fname) ENV['PROBLEM_HOME'] = problem_home ENV['RUBYOPT'] = '' - + talk grading_dir Dir.chdir grading_dir script_name = "#{problem_home}/script/judge" @@ -129,6 +134,9 @@ GRADER_ROOT + '/std-script' end + #copy any script presented in std-script directory that is not in the problem_home + #this allow a problem setter to provide their own version for each script + #in case that they want to hack something def copy_script(problem_home) script_dir = "#{problem_home}/script" std_script_dir = get_std_script_dir @@ -136,7 +144,7 @@ raise "engine: std-script directory not found" if !FileTest.exist?(std_script_dir) scripts = Dir[std_script_dir + '/*'] - + copied = [] scripts.each do |s| @@ -147,7 +155,7 @@ FileUtils.cp(s, "#{script_dir}", :preserve => true) end end - + return copied end @@ -162,7 +170,7 @@ end f.close end - + def load_copy_log(problem_home) f = File.new(copy_log_filename(problem_home),"r") log = [] diff --git a/lib/runner.rb b/lib/runner.rb --- a/lib/runner.rb +++ b/lib/runner.rb @@ -24,6 +24,9 @@ return task end + # grade a specified problem for the latest submission of each user + # optionally, on all submission when options[:all_sub] is set + # optionally, only submission that has error (use when the problem itself has some problem) def grade_problem(problem, options={}) user_index = 0 user_count = User.count diff --git a/lib/submission_helper.rb b/lib/submission_helper.rb --- a/lib/submission_helper.rb +++ b/lib/submission_helper.rb @@ -4,17 +4,17 @@ def initialize @config = Grader::Configuration.get_instance end - + def produce_grading_room(submission) user = submission.user problem = submission.problem grading_room = "#{@config.user_result_dir}/" + "#{user.login}/#{problem.name}/#{submission.id}" - + FileUtils.mkdir_p(grading_room) grading_room end - + def find_problem_home(submission) problem = submission.problem "#{@config.problems_dir}/#{problem.name}" @@ -30,7 +30,7 @@ def clean_up(submission) end end - + class SubmissionReporter def initialize(options={}) options = {:dry_run => false, :result_collector => nil}.merge(options) @@ -38,7 +38,7 @@ @dry_run = options[:dry_run] @result_collector = options[:result_collector] end - + def report(sub,test_result_dir) result = read_result(test_result_dir) if @result_collector @@ -47,7 +47,7 @@ end save_result(sub,result) end - + def report_error(sub,msg) save_result(sub,{:points => 0, :comment => "Grading error: #{msg}" }) @@ -63,7 +63,7 @@ else cmp_msg = "" end - + result_fname = "#{test_result_dir}/result" comment_fname = "#{test_result_dir}/comment" runstat_fname = "#{test_result_dir}/run_stat" @@ -77,7 +77,7 @@ result = 0 comment = "error reading result file." end - + begin comment_file = File.open(comment_fname) comment += comment_file.readline.chomp @@ -114,7 +114,7 @@ end end end - + def save_result(submission,result) problem = submission.problem submission.graded_at = Time.now.gmtime @@ -140,7 +140,7 @@ #submission.grader_comment = 'FAILED: ' + comment submission.grader_comment = comment end - + #very lazy trim the string submission.compiler_message = result[:cmp_msg][0..60000] or '' @@ -148,7 +148,7 @@ submission.save end end - + end - + end