Description:
rename_problem fix
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r234:45474cc69e4c - - 1 file changed: 2 inserted, 2 deleted
@@ -1,23 +1,23 | |||||
|
1 | #!/usr/bin/env ruby |
|
1 | #!/usr/bin/env ruby |
|
2 |
|
2 | ||
|
3 | ENVIRONMENT_DIRS = ['ev', 'ev-exam'] |
|
3 | ENVIRONMENT_DIRS = ['ev', 'ev-exam'] |
|
4 |
|
4 | ||
|
5 | def config |
|
5 | def config |
|
6 | Grader::Configuration.get_instance |
|
6 | Grader::Configuration.get_instance |
|
7 | end |
|
7 | end |
|
8 |
|
8 | ||
|
9 | def rename_problem(old_problem_name, new_problem_name) |
|
9 | def rename_problem(old_problem_name, new_problem_name) |
|
10 |
|
10 | ||
|
11 |
- |
|
11 | + unless valid_problem_name(new_problem_name) |
|
12 | puts "Bad new problem name: #{new_problem_name}" |
|
12 | puts "Bad new problem name: #{new_problem_name}" |
|
13 | return |
|
13 | return |
|
14 | end |
|
14 | end |
|
15 |
|
15 | ||
|
16 | problem = Problem.find_by_name(old_problem_name) |
|
16 | problem = Problem.find_by_name(old_problem_name) |
|
17 | if problem==nil |
|
17 | if problem==nil |
|
18 | puts "Problem #{old_problem_name} does not exist." |
|
18 | puts "Problem #{old_problem_name} does not exist." |
|
19 | return |
|
19 | return |
|
20 | end |
|
20 | end |
|
21 |
|
21 | ||
|
22 | puts "Problem: #{old_problem_name} -> #{new_problem_name}" |
|
22 | puts "Problem: #{old_problem_name} -> #{new_problem_name}" |
|
23 |
|
23 | ||
@@ -51,25 +51,25 | |||||
|
51 | When using with -f, that file should contain, for each line, the old |
|
51 | When using with -f, that file should contain, for each line, the old |
|
52 | problem name and its new name. |
|
52 | problem name and its new name. |
|
53 |
|
53 | ||
|
54 | This script should be called at the judge root dir where dirs 'ev' and |
|
54 | This script should be called at the judge root dir where dirs 'ev' and |
|
55 | 'ev-exam' are. |
|
55 | 'ev-exam' are. |
|
56 | USAGE |
|
56 | USAGE |
|
57 | end |
|
57 | end |
|
58 |
|
58 | ||
|
59 | def valid_problem_name(name) |
|
59 | def valid_problem_name(name) |
|
60 | if name.length==0: |
|
60 | if name.length==0: |
|
61 | return false |
|
61 | return false |
|
62 | else |
|
62 | else |
|
63 |
- return |
|
63 | + return (/^[a-zA-Z0-9_\-]+$/ === name) |
|
64 | end |
|
64 | end |
|
65 | end |
|
65 | end |
|
66 |
|
66 | ||
|
67 | if (ARGV.length!=2) |
|
67 | if (ARGV.length!=2) |
|
68 | usage |
|
68 | usage |
|
69 | exit(0) |
|
69 | exit(0) |
|
70 | end |
|
70 | end |
|
71 |
|
71 | ||
|
72 | if ARGV[0]=='-f' and !FileTest.exists?(ARGV[1]) |
|
72 | if ARGV[0]=='-f' and !FileTest.exists?(ARGV[1]) |
|
73 | puts "File #{ARGV[1]} does not exist." |
|
73 | puts "File #{ARGV[1]} does not exist." |
|
74 | usage |
|
74 | usage |
|
75 | exit(0) |
|
75 | exit(0) |
You need to be logged in to leave comments.
Login now