Description:
changed test request uploaded dir to data/test_request/input
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@86 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
r38:d108852b6289 - - 2 files changed: 4 inserted, 2 deleted
@@ -1,64 +1,65 | |||||
|
1 | require 'fileutils' |
|
1 | require 'fileutils' |
|
2 |
|
2 | ||
|
3 | class TestRequest < Task |
|
3 | class TestRequest < Task |
|
4 |
|
4 | ||
|
5 | set_table_name "test_requests" |
|
5 | set_table_name "test_requests" |
|
6 |
|
6 | ||
|
7 | belongs_to :user |
|
7 | belongs_to :user |
|
8 | belongs_to :problem |
|
8 | belongs_to :problem |
|
9 | belongs_to :submission |
|
9 | belongs_to :submission |
|
10 |
|
10 | ||
|
11 | def self.get_inqueue_and_change_status(status) |
|
11 | def self.get_inqueue_and_change_status(status) |
|
12 | # since there will be only one grader grading TestRequest |
|
12 | # since there will be only one grader grading TestRequest |
|
13 | # we do not need locking (hopefully) |
|
13 | # we do not need locking (hopefully) |
|
14 |
|
14 | ||
|
15 | task = Task.find(:first, |
|
15 | task = Task.find(:first, |
|
16 | :order => "created_at", |
|
16 | :order => "created_at", |
|
17 | :conditions => {:status=> Task::STATUS_INQUEUE}) |
|
17 | :conditions => {:status=> Task::STATUS_INQUEUE}) |
|
18 | if task!=nil |
|
18 | if task!=nil |
|
19 | task.status = status |
|
19 | task.status = status |
|
20 | task.save! |
|
20 | task.save! |
|
21 | end |
|
21 | end |
|
22 |
|
22 | ||
|
23 | task |
|
23 | task |
|
24 | end |
|
24 | end |
|
25 |
|
25 | ||
|
26 | # interfacing with form |
|
26 | # interfacing with form |
|
27 | def self.new_from_form_params(user,params) |
|
27 | def self.new_from_form_params(user,params) |
|
28 | test_request = TestRequest.new |
|
28 | test_request = TestRequest.new |
|
29 | test_request.user = user |
|
29 | test_request.user = user |
|
30 | problem = Problem.find(params[:problem_id]) |
|
30 | problem = Problem.find(params[:problem_id]) |
|
31 | test_request.problem = problem |
|
31 | test_request.problem = problem |
|
32 | test_request.submission = |
|
32 | test_request.submission = |
|
33 | Submission.find_by_user_problem_number(user.id, |
|
33 | Submission.find_by_user_problem_number(user.id, |
|
34 | problem.id, |
|
34 | problem.id, |
|
35 | params[:submission_number]) |
|
35 | params[:submission_number]) |
|
36 | test_request.input_file_name = save_input_file(params[:input_file], user, problem) |
|
36 | test_request.input_file_name = save_input_file(params[:input_file], user, problem) |
|
37 | test_request.submitted_at = Time.new |
|
37 | test_request.submitted_at = Time.new |
|
38 | test_request.status_inqueue |
|
38 | test_request.status_inqueue |
|
39 | test_request |
|
39 | test_request |
|
40 | end |
|
40 | end |
|
41 |
|
41 | ||
|
42 | protected |
|
42 | protected |
|
43 | def self.input_file_name(user,problem) |
|
43 | def self.input_file_name(user,problem) |
|
|
44 | + problem_name = (problem!=nil) ? problem.name : "" | ||
|
44 | begin |
|
45 | begin |
|
45 |
- tmpname = |
|
46 | + tmpname = TEST_REQUEST_INPUT_FILE_DIR + "/#{user.login}/#{problem_name}/#{rand(10000)}" |
|
46 | end while File.exists?(tmpname) |
|
47 | end while File.exists?(tmpname) |
|
47 | tmpname |
|
48 | tmpname |
|
48 | end |
|
49 | end |
|
49 |
|
50 | ||
|
50 | def self.save_input_file(tempfile, user, problem) |
|
51 | def self.save_input_file(tempfile, user, problem) |
|
51 | new_file_name = input_file_name(user,problem) |
|
52 | new_file_name = input_file_name(user,problem) |
|
52 | dirname = File.dirname(new_file_name) |
|
53 | dirname = File.dirname(new_file_name) |
|
53 | FileUtils.mkdir_p(File.dirname(new_file_name)) if !File.exists?(dirname) |
|
54 | FileUtils.mkdir_p(File.dirname(new_file_name)) if !File.exists?(dirname) |
|
54 | if tempfile.instance_of?(Tempfile) |
|
55 | if tempfile.instance_of?(Tempfile) |
|
55 | tempfile.close |
|
56 | tempfile.close |
|
56 | FileUtils.move(tempfile.path,new_file_name) |
|
57 | FileUtils.move(tempfile.path,new_file_name) |
|
57 | else |
|
58 | else |
|
58 | File.open(new_file_name, "wb") do |f| |
|
59 | File.open(new_file_name, "wb") do |f| |
|
59 | f.write(tempfile.read) |
|
60 | f.write(tempfile.read) |
|
60 | end |
|
61 | end |
|
61 | end |
|
62 | end |
|
62 | new_file_name |
|
63 | new_file_name |
|
63 | end |
|
64 | end |
|
64 | end |
|
65 | end |
@@ -1,62 +1,63 | |||||
|
1 | # Be sure to restart your web server when you modify this file. |
|
1 | # Be sure to restart your web server when you modify this file. |
|
2 |
|
2 | ||
|
3 | # Uncomment below to force Rails into production mode when |
|
3 | # Uncomment below to force Rails into production mode when |
|
4 | # you don't control web/app server and can't set it the proper way |
|
4 | # you don't control web/app server and can't set it the proper way |
|
5 | # ENV['RAILS_ENV'] ||= 'production' |
|
5 | # ENV['RAILS_ENV'] ||= 'production' |
|
6 |
|
6 | ||
|
7 | # Specifies gem version of Rails to use when vendor/rails is not present |
|
7 | # Specifies gem version of Rails to use when vendor/rails is not present |
|
8 | RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION |
|
8 | RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION |
|
9 |
|
9 | ||
|
10 | # Bootstrap the Rails environment, frameworks, and default configuration |
|
10 | # Bootstrap the Rails environment, frameworks, and default configuration |
|
11 | require File.join(File.dirname(__FILE__), 'boot') |
|
11 | require File.join(File.dirname(__FILE__), 'boot') |
|
12 |
|
12 | ||
|
13 | Rails::Initializer.run do |config| |
|
13 | Rails::Initializer.run do |config| |
|
14 | # Settings in config/environments/* take precedence over those specified here |
|
14 | # Settings in config/environments/* take precedence over those specified here |
|
15 |
|
15 | ||
|
16 | # Skip frameworks you're not going to use (only works if using vendor/rails) |
|
16 | # Skip frameworks you're not going to use (only works if using vendor/rails) |
|
17 | # config.frameworks -= [ :action_web_service, :action_mailer ] |
|
17 | # config.frameworks -= [ :action_web_service, :action_mailer ] |
|
18 |
|
18 | ||
|
19 | # Only load the plugins named here, by default all plugins in vendor/plugins are loaded |
|
19 | # Only load the plugins named here, by default all plugins in vendor/plugins are loaded |
|
20 | # config.plugins = %W( exception_notification ssl_requirement ) |
|
20 | # config.plugins = %W( exception_notification ssl_requirement ) |
|
21 |
|
21 | ||
|
22 | # Add additional load paths for your own custom dirs |
|
22 | # Add additional load paths for your own custom dirs |
|
23 | # config.load_paths += %W( #{RAILS_ROOT}/extras ) |
|
23 | # config.load_paths += %W( #{RAILS_ROOT}/extras ) |
|
24 |
|
24 | ||
|
25 | # Force all environments to use the same logger level |
|
25 | # Force all environments to use the same logger level |
|
26 | # (by default production uses :info, the others :debug) |
|
26 | # (by default production uses :info, the others :debug) |
|
27 | # config.log_level = :debug |
|
27 | # config.log_level = :debug |
|
28 |
|
28 | ||
|
29 | # Use the database for sessions instead of the file system |
|
29 | # Use the database for sessions instead of the file system |
|
30 | # (create the session table with 'rake db:sessions:create') |
|
30 | # (create the session table with 'rake db:sessions:create') |
|
31 | config.action_controller.session_store = :active_record_store |
|
31 | config.action_controller.session_store = :active_record_store |
|
32 |
|
32 | ||
|
33 | # Use SQL instead of Active Record's schema dumper when creating the test database. |
|
33 | # Use SQL instead of Active Record's schema dumper when creating the test database. |
|
34 | # This is necessary if your schema can't be completely dumped by the schema dumper, |
|
34 | # This is necessary if your schema can't be completely dumped by the schema dumper, |
|
35 | # like if you have constraints or database-specific column types |
|
35 | # like if you have constraints or database-specific column types |
|
36 | # config.active_record.schema_format = :sql |
|
36 | # config.active_record.schema_format = :sql |
|
37 |
|
37 | ||
|
38 | # Activate observers that should always be running |
|
38 | # Activate observers that should always be running |
|
39 | # config.active_record.observers = :cacher, :garbage_collector |
|
39 | # config.active_record.observers = :cacher, :garbage_collector |
|
40 |
|
40 | ||
|
41 | # Make Active Record use UTC-base instead of local time |
|
41 | # Make Active Record use UTC-base instead of local time |
|
42 | config.active_record.default_timezone = :utc |
|
42 | config.active_record.default_timezone = :utc |
|
43 |
|
43 | ||
|
44 | # See Rails::Configuration for more options |
|
44 | # See Rails::Configuration for more options |
|
45 | end |
|
45 | end |
|
46 |
|
46 | ||
|
47 | # Add new inflection rules using the following format |
|
47 | # Add new inflection rules using the following format |
|
48 | # (all these examples are active by default): |
|
48 | # (all these examples are active by default): |
|
49 | # Inflector.inflections do |inflect| |
|
49 | # Inflector.inflections do |inflect| |
|
50 | # inflect.plural /^(ox)$/i, '\1en' |
|
50 | # inflect.plural /^(ox)$/i, '\1en' |
|
51 | # inflect.singular /^(ox)en/i, '\1' |
|
51 | # inflect.singular /^(ox)en/i, '\1' |
|
52 | # inflect.irregular 'person', 'people' |
|
52 | # inflect.irregular 'person', 'people' |
|
53 | # inflect.uncountable %w( fish sheep ) |
|
53 | # inflect.uncountable %w( fish sheep ) |
|
54 | # end |
|
54 | # end |
|
55 |
|
55 | ||
|
56 | # Add new mime types for use in respond_to blocks: |
|
56 | # Add new mime types for use in respond_to blocks: |
|
57 | # Mime::Type.register "text/richtext", :rtf |
|
57 | # Mime::Type.register "text/richtext", :rtf |
|
58 | # Mime::Type.register "application/x-mobile", :mobile |
|
58 | # Mime::Type.register "application/x-mobile", :mobile |
|
59 |
|
59 | ||
|
60 | # Include your application configuration below |
|
60 | # Include your application configuration below |
|
61 |
|
61 | ||
|
62 |
- |
|
62 | + TEST_REQUEST_INPUT_FILE_DIR = RAILS_ROOT + '/data/test_request/input' |
|
|
63 | + TEST_REQUEST_OUTPUT_FILE_DIR = RAILS_ROOT + '/data/test_request/output' |
You need to be logged in to leave comments.
Login now