Description:
added rename_problem script, fixed require error for dir_init
git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@420 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
r78:3df292e1c18d - - 2 files changed: 101 inserted, 1 deleted
@@ -0,0 +1,100 | |||||
|
|
1 | + #!/usr/bin/env ruby | ||
|
|
2 | + | ||
|
|
3 | + ENVIRONMENT_DIRS = ['ev', 'ev-exam'] | ||
|
|
4 | + | ||
|
|
5 | + def config | ||
|
|
6 | + Grader::Configuration.get_instance | ||
|
|
7 | + end | ||
|
|
8 | + | ||
|
|
9 | + def rename_problem(old_problem_name, new_problem_name) | ||
|
|
10 | + | ||
|
|
11 | + if valid_problem_name(new_problem_name) | ||
|
|
12 | + puts "Bad new problem name: #{new_problem_name}" | ||
|
|
13 | + return | ||
|
|
14 | + end | ||
|
|
15 | + | ||
|
|
16 | + problem = Problem.find_by_name(old_problem_name) | ||
|
|
17 | + if problem==nil | ||
|
|
18 | + puts "Problem #{old_problem_name} does not exist." | ||
|
|
19 | + return | ||
|
|
20 | + end | ||
|
|
21 | + | ||
|
|
22 | + puts "Problem: #{old_problem_name} -> #{new_problem_name}" | ||
|
|
23 | + | ||
|
|
24 | + ENVIRONMENT_DIRS.each do |dir| | ||
|
|
25 | + problem_dir = File.join(GRADER_ROOT,'..',dir,old_problem_name) | ||
|
|
26 | + new_problem_dir = File.join(GRADER_ROOT,'..',dir,new_problem_name) | ||
|
|
27 | + | ||
|
|
28 | + if FileTest.exists? problem_dir | ||
|
|
29 | + puts "Moving #{problem_dir} to #{new_problem_dir}." | ||
|
|
30 | + File.rename(problem_dir, new_problem_dir) | ||
|
|
31 | + | ||
|
|
32 | + tr_problem_dir = File.join(GRADER_ROOT,'..',dir, | ||
|
|
33 | + 'test_request',old_problem_name) | ||
|
|
34 | + new_tr_problem_dir = File.join(GRADER_ROOT,'..',dir, | ||
|
|
35 | + 'test_request',new_problem_name) | ||
|
|
36 | + File.rename(tr_problem_dir, new_tr_problem_dir) | ||
|
|
37 | + end | ||
|
|
38 | + end | ||
|
|
39 | + | ||
|
|
40 | + problem.name = new_problem_name | ||
|
|
41 | + problem.save | ||
|
|
42 | + end | ||
|
|
43 | + | ||
|
|
44 | + def usage | ||
|
|
45 | + puts <<USAGE | ||
|
|
46 | + Usage: | ||
|
|
47 | + rename_problem [old_name] [new_name] | ||
|
|
48 | + or | ||
|
|
49 | + rename_problem -f [filename] | ||
|
|
50 | + | ||
|
|
51 | + When using with -f, that file should contain, for each line, the old | ||
|
|
52 | + problem name and its new name. | ||
|
|
53 | + | ||
|
|
54 | + This script should be called at the judge root dir where dirs 'ev' and | ||
|
|
55 | + 'ev-exam' are. | ||
|
|
56 | + USAGE | ||
|
|
57 | + end | ||
|
|
58 | + | ||
|
|
59 | + def valid_problem_name(name) | ||
|
|
60 | + if name.length==0: | ||
|
|
61 | + return false | ||
|
|
62 | + else | ||
|
|
63 | + return !(/^[a-zA-Z0-9_\-]+$/ === name) | ||
|
|
64 | + end | ||
|
|
65 | + end | ||
|
|
66 | + | ||
|
|
67 | + if (ARGV.length!=2) | ||
|
|
68 | + usage | ||
|
|
69 | + exit(0) | ||
|
|
70 | + end | ||
|
|
71 | + | ||
|
|
72 | + if ARGV[0]=='-f' and !FileTest.exists?(ARGV[1]) | ||
|
|
73 | + puts "File #{ARGV[1]} does not exist." | ||
|
|
74 | + usage | ||
|
|
75 | + exit(0) | ||
|
|
76 | + end | ||
|
|
77 | + | ||
|
|
78 | + # load grader environment | ||
|
|
79 | + GRADER_ENV = 'grading' | ||
|
|
80 | + require File.join(File.dirname(__FILE__),'config/environment') | ||
|
|
81 | + | ||
|
|
82 | + # boot rails, to be able to rename the problem | ||
|
|
83 | + RAILS_ENV = config.rails_env | ||
|
|
84 | + require RAILS_ROOT + '/config/environment' | ||
|
|
85 | + | ||
|
|
86 | + if ARGV[0]!='-f' | ||
|
|
87 | + old_problem_name = ARGV[0] | ||
|
|
88 | + new_problem_name = ARGV[1] | ||
|
|
89 | + | ||
|
|
90 | + rename_problem(old_problem_name, new_problem_name) | ||
|
|
91 | + else | ||
|
|
92 | + lines = IO.readlines(ARGV[1]) | ||
|
|
93 | + lines.each do |line| | ||
|
|
94 | + items = line.split | ||
|
|
95 | + if items.length==2 | ||
|
|
96 | + old_name, new_name = items | ||
|
|
97 | + rename_problem(old_name, new_name) | ||
|
|
98 | + end | ||
|
|
99 | + end | ||
|
|
100 | + end |
@@ -1,9 +1,9 | |||||
|
1 | require 'fileutils' |
|
1 | require 'fileutils' |
|
2 | require 'ftools' |
|
2 | require 'ftools' |
|
3 | - require 'lib/dir_init' |
|
3 | + require File.join(File.dirname(__FILE__),'dir_init') |
|
4 |
|
4 | ||
|
5 | module Grader |
|
5 | module Grader |
|
6 |
|
6 | ||
|
7 | # |
|
7 | # |
|
8 | # A grader engine grades a submission, against anything: a test |
|
8 | # A grader engine grades a submission, against anything: a test |
|
9 | # data, or a user submitted test data. It uses two helpers objects: |
|
9 | # data, or a user submitted test data. It uses two helpers objects: |
You need to be logged in to leave comments.
Login now