Description:
rename_problem fix
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r234:45474cc69e4c - - 1 file changed: 2 inserted, 2 deleted

@@ -1,35 +1,35
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 - if valid_problem_name(new_problem_name)
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
24 ENVIRONMENT_DIRS.each do |dir|
24 ENVIRONMENT_DIRS.each do |dir|
25 problem_dir = File.join(GRADER_ROOT,'..',dir,old_problem_name)
25 problem_dir = File.join(GRADER_ROOT,'..',dir,old_problem_name)
26 new_problem_dir = File.join(GRADER_ROOT,'..',dir,new_problem_name)
26 new_problem_dir = File.join(GRADER_ROOT,'..',dir,new_problem_name)
27
27
28 if FileTest.exists? problem_dir
28 if FileTest.exists? problem_dir
29 puts "Moving #{problem_dir} to #{new_problem_dir}."
29 puts "Moving #{problem_dir} to #{new_problem_dir}."
30 File.rename(problem_dir, new_problem_dir)
30 File.rename(problem_dir, new_problem_dir)
31
31
32 tr_problem_dir = File.join(GRADER_ROOT,'..',dir,
32 tr_problem_dir = File.join(GRADER_ROOT,'..',dir,
33 'test_request',old_problem_name)
33 'test_request',old_problem_name)
34 new_tr_problem_dir = File.join(GRADER_ROOT,'..',dir,
34 new_tr_problem_dir = File.join(GRADER_ROOT,'..',dir,
35 'test_request',new_problem_name)
35 'test_request',new_problem_name)
@@ -39,49 +39,49
39
39
40 problem.name = new_problem_name
40 problem.name = new_problem_name
41 problem.save
41 problem.save
42 end
42 end
43
43
44 def usage
44 def usage
45 puts <<USAGE
45 puts <<USAGE
46 Usage:
46 Usage:
47 rename_problem [old_name] [new_name]
47 rename_problem [old_name] [new_name]
48 or
48 or
49 rename_problem -f [filename]
49 rename_problem -f [filename]
50
50
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 !(/^[a-zA-Z0-9_\-]+$/ === name)
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)
76 end
76 end
77
77
78 # load grader environment
78 # load grader environment
79 GRADER_ENV = 'grading'
79 GRADER_ENV = 'grading'
80 require File.join(File.dirname(__FILE__),'config/environment')
80 require File.join(File.dirname(__FILE__),'config/environment')
81
81
82 # boot rails, to be able to rename the problem
82 # boot rails, to be able to rename the problem
83 RAILS_ENV = config.rails_env
83 RAILS_ENV = config.rails_env
84 require RAILS_ROOT + '/config/environment'
84 require RAILS_ROOT + '/config/environment'
85
85
86 if ARGV[0]!='-f'
86 if ARGV[0]!='-f'
87 old_problem_name = ARGV[0]
87 old_problem_name = ARGV[0]
You need to be logged in to leave comments. Login now