Description:
add more description to new_problem
git-svn-id: http://theory.cpe.ku.ac.th/grader/cli/trunk/scripts@53 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
r19:5d5b7e4073f5 - - 1 file changed: 7 inserted, 1 deleted
@@ -1,62 +1,68 | |||||
|
1 | #!/usr/bin/ruby |
|
1 | #!/usr/bin/ruby |
|
2 |
|
2 | ||
|
3 | # new_problem: |
|
3 | # new_problem: |
|
4 | # * creates a directory for a problem in the current directory, |
|
4 | # * creates a directory for a problem in the current directory, |
|
5 | # * create standard testcase config file |
|
5 | # * create standard testcase config file |
|
6 |
|
6 | ||
|
7 | require 'erb' |
|
7 | require 'erb' |
|
8 |
|
8 | ||
|
9 | def process_options(options) |
|
9 | def process_options(options) |
|
10 | i = 2 |
|
10 | i = 2 |
|
11 | while i<ARGV.length |
|
11 | while i<ARGV.length |
|
12 | if ARGV[i]=='-t' |
|
12 | if ARGV[i]=='-t' |
|
13 | options[:time_limit] = ARGV[i+1].to_i if ARGV.length>i+1 |
|
13 | options[:time_limit] = ARGV[i+1].to_i if ARGV.length>i+1 |
|
14 | i += 1 |
|
14 | i += 1 |
|
15 | end |
|
15 | end |
|
16 | if ARGV[i]=='-m' |
|
16 | if ARGV[i]=='-m' |
|
17 | options[:mem_limit] = ARGV[i+1].to_i if ARGV.length>i+1 |
|
17 | options[:mem_limit] = ARGV[i+1].to_i if ARGV.length>i+1 |
|
18 | i += 1 |
|
18 | i += 1 |
|
19 | end |
|
19 | end |
|
20 | i += 1 |
|
20 | i += 1 |
|
21 | end |
|
21 | end |
|
22 | end |
|
22 | end |
|
23 |
|
23 | ||
|
24 | GRADER_DIR = File.dirname(__FILE__) |
|
24 | GRADER_DIR = File.dirname(__FILE__) |
|
25 |
|
25 | ||
|
26 | # print usage |
|
26 | # print usage |
|
27 | if ARGV.length < 2 |
|
27 | if ARGV.length < 2 |
|
28 | - puts "using: new_problem problem number_of_testcase [options]" |
|
28 | + puts <<USAGE |
|
|
29 | + using: new_problem problem number_of_testcase [options] | ||
|
|
30 | + * creates a directory for a problem in the current directory, | ||
|
|
31 | + * create standard testcase config file | ||
|
|
32 | + * options: -t time-limit (in seconds) | ||
|
|
33 | + -m mem-limit (in MB) | ||
|
|
34 | + USAGE | ||
|
29 | exit(127) |
|
35 | exit(127) |
|
30 | end |
|
36 | end |
|
31 |
|
37 | ||
|
32 | # processing arguments |
|
38 | # processing arguments |
|
33 | problem = ARGV[0] |
|
39 | problem = ARGV[0] |
|
34 | num_testcases = ARGV[1].to_i |
|
40 | num_testcases = ARGV[1].to_i |
|
35 |
|
41 | ||
|
36 | options = {:time_limit => 1, :mem_limit => 16} |
|
42 | options = {:time_limit => 1, :mem_limit => 16} |
|
37 | process_options(options) |
|
43 | process_options(options) |
|
38 |
|
44 | ||
|
39 | # start working |
|
45 | # start working |
|
40 | puts "creating directories" |
|
46 | puts "creating directories" |
|
41 |
|
47 | ||
|
42 | system("mkdir #{problem}") |
|
48 | system("mkdir #{problem}") |
|
43 | system("mkdir #{problem}/script") |
|
49 | system("mkdir #{problem}/script") |
|
44 | system("mkdir #{problem}/test_cases") |
|
50 | system("mkdir #{problem}/test_cases") |
|
45 |
|
51 | ||
|
46 | puts "creating testcases directories" |
|
52 | puts "creating testcases directories" |
|
47 |
|
53 | ||
|
48 | 1.upto(num_testcases) do |i| |
|
54 | 1.upto(num_testcases) do |i| |
|
49 | system("mkdir #{problem}/test_cases/#{i}") |
|
55 | system("mkdir #{problem}/test_cases/#{i}") |
|
50 | end |
|
56 | end |
|
51 |
|
57 | ||
|
52 | # generating all_tests.cfg |
|
58 | # generating all_tests.cfg |
|
53 | puts "generating testcase config file" |
|
59 | puts "generating testcase config file" |
|
54 |
|
60 | ||
|
55 | template = File.open(File.dirname(__FILE__) + "/all_tests.cfg.erb").read |
|
61 | template = File.open(File.dirname(__FILE__) + "/all_tests.cfg.erb").read |
|
56 | all_test_cfg = ERB.new(template) |
|
62 | all_test_cfg = ERB.new(template) |
|
57 |
|
63 | ||
|
58 | cfg_file = File.open("#{problem}/test_cases/all_tests.cfg","w") |
|
64 | cfg_file = File.open("#{problem}/test_cases/all_tests.cfg","w") |
|
59 | cfg_file.puts all_test_cfg.result |
|
65 | cfg_file.puts all_test_cfg.result |
|
60 | cfg_file.close |
|
66 | cfg_file.close |
|
61 |
|
67 | ||
|
62 | puts "done" |
|
68 | puts "done" |
You need to be logged in to leave comments.
Login now