Description:
update import_problem info, add new_problem git-svn-id: http://theory.cpe.ku.ac.th/grader/cli/trunk/scripts@28 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

r14:3e5f3582d635 - - 2 files changed: 62 inserted, 1 deleted

@@ -0,0 +1,62
1 + #!/usr/bin/ruby
2 +
3 + # new_problem:
4 + # * creates a directory for a problem in the current directory,
5 + # * create standard testcase config file
6 +
7 + require 'erb'
8 +
9 + def process_options(options)
10 + i = 2
11 + while i<ARGV.length
12 + if ARGV[i]=='-t'
13 + options[:time_limit] = ARGV[i+1].to_i if ARGV.length>i+1
14 + i += 1
15 + end
16 + if ARGV[i]=='-m'
17 + options[:mem_limit] = ARGV[i+1].to_i if ARGV.length>i+1
18 + i += 1
19 + end
20 + i += 1
21 + end
22 + end
23 +
24 + GRADER_DIR = File.dirname(__FILE__)
25 +
26 + # print usage
27 + if ARGV.length < 2
28 + puts "using: new_problem problem number_of_testcase [options]"
29 + exit(127)
30 + end
31 +
32 + # processing arguments
33 + problem = ARGV[0]
34 + num_testcases = ARGV[1].to_i
35 +
36 + options = {:time_limit => 1, :mem_limit => 16}
37 + process_options(options)
38 +
39 + # start working
40 + puts "creating directories"
41 +
42 + system("mkdir #{problem}")
43 + system("mkdir #{problem}/script")
44 + system("mkdir #{problem}/test_cases")
45 +
46 + puts "creating testcases directories"
47 +
48 + 1.upto(num_testcases) do |i|
49 + system("mkdir #{problem}/test_cases/#{i}")
50 + end
51 +
52 + # generating all_tests.cfg
53 + puts "generating testcase config file"
54 +
55 + template = File.open(File.dirname(__FILE__) + "/all_tests.cfg.erb").read
56 + all_test_cfg = ERB.new(template)
57 +
58 + cfg_file = File.open("#{problem}/test_cases/all_tests.cfg","w")
59 + cfg_file.puts all_test_cfg.result
60 + cfg_file.close
61 +
62 + puts "done"
@@ -1,29 +1,28
1 1 #!/usr/bin/ruby
2 2
3 3 # import_problem:
4 4 # * creates a directory for a problem in the current directory,
5 - # * copy standard scripts
6 5 # * copy testdata in the old format and create standard testcase config file
7 6
8 7 require 'erb'
9 8
10 9 def input_filename(dir,i)
11 10 "#{dir}/input-#{i}.txt"
12 11 end
13 12
14 13 def answer_filename(dir,i)
15 14 "#{dir}/answer-#{i}.txt"
16 15 end
17 16
18 17 def copy_testcase(importing_test_dir,dir,i)
19 18 system("cp #{importing_test_dir}/#{i}.in #{input_filename(dir,i)}")
20 19 system("cp #{importing_test_dir}/#{i}.sol #{answer_filename(dir,i)}")
21 20 end
22 21
23 22 def process_options(options)
24 23 i = 3
25 24 while i<ARGV.length
26 25 if ARGV[i]=='-t'
27 26 options[:time_limit] = ARGV[i+1].to_i if ARGV.length>i+1
28 27 i += 1
29 28 end
You need to be logged in to leave comments. Login now