shogi-server source
Révision | 86b89d77b8d33397df8a248a564eb0a75f79136d (tree) |
---|---|
l'heure | 2016-12-09 21:15:41 |
Auteur | Daigo Moriwaki <beatles@user...> |
Commiter | Daigo Moriwaki |
Fix #36855: Allow util/statistics.rb to set a filtering condition of found files
Regarding util/statistics.rb, add a new command line option,
--filter regexp, to process files that are matched with a regexp.
It would make it easier to calculate statistics of certain games.
@@ -1,3 +1,11 @@ | ||
1 | +2016-12-09 Daigo Moriwaki <daigo at debian dot org> | |
2 | + | |
3 | + * Allow util/statistics.rb to set a filtering condition of found files | |
4 | + Regarding util/statistics.rb, add a new command line option, | |
5 | + --filter regexp, to process files that are matched with a regexp. | |
6 | + It would make it easier to calculate statistics of certain games. | |
7 | + (Closes #36855) | |
8 | + | |
1 | 9 | 2016-11-26 Daigo Moriwaki <daigo at debian dot org> |
2 | 10 | |
3 | 11 | * [shogi-server] Allow to customize maximum lenght of a login indentifier |
@@ -139,15 +139,30 @@ end | ||
139 | 139 | |
140 | 140 | if $0 == __FILE__ |
141 | 141 | def usage |
142 | - puts "Usage: #{$0} [OPTIONS] dir [...]" | |
143 | - puts "Options:" | |
142 | +puts <<-EOF | |
143 | +SYNOPSIS: | |
144 | + #{$0} [OPTION]... file or dir [...] | |
145 | + | |
146 | +DESCRIPTION: | |
147 | + It calculates game statistics, reading CSA record files. | |
148 | + If an argument is a directory, it attempts to find files in its | |
149 | + subdirectories recursively. | |
150 | + | |
151 | + --filter regexp | |
152 | + only files that are matched with a regexp are processed (default: no filter) | |
153 | + | |
154 | + --repeat n | |
155 | + at most n files are processed (default: unlimitted) | |
156 | +EOF | |
144 | 157 | exit 1 |
145 | 158 | end |
146 | 159 | |
147 | 160 | usage if ARGV.empty? |
148 | 161 | |
149 | 162 | parser = GetoptLong.new( |
150 | - ['--repeat', '-n', GetoptLong::REQUIRED_ARGUMENT] | |
163 | + ['--repeat', '-n', GetoptLong::REQUIRED_ARGUMENT], | |
164 | + ['--filter', GetoptLong::REQUIRED_ARGUMENT], | |
165 | + ['--h', '-h', GetoptLong::NO_ARGUMENT] | |
151 | 166 | ) |
152 | 167 | begin |
153 | 168 | parser.each_option do |name, arg| |
@@ -157,6 +172,10 @@ if $0 == __FILE__ | ||
157 | 172 | usage |
158 | 173 | end |
159 | 174 | |
175 | + if $OPT_H | |
176 | + usage | |
177 | + end | |
178 | + | |
160 | 179 | $OPT_REPEAT = $OPT_REPEAT.to_i |
161 | 180 | if $OPT_REPEAT == 0 |
162 | 181 | $OPT_REPEAT = -1 |
@@ -167,11 +186,15 @@ if $0 == __FILE__ | ||
167 | 186 | if FileTest.directory?(cmd) |
168 | 187 | Dir.glob(File.join(cmd, "**", "*.csa")).each do |file| |
169 | 188 | break if $OPT_REPEAT == 0 |
170 | - do_file(file) | |
189 | + if $OPT_FILTER.nil? || /#{$OPT_FILTER}/ =~ file | |
190 | + do_file(file) | |
191 | + end | |
171 | 192 | end |
172 | 193 | elsif FileTest.file?(cmd) |
173 | 194 | break if $OPT_REPEAT == 0 |
174 | - do_file(cmd) | |
195 | + if $OPT_FILTER.nil? || /#{$OPT_FILTER}/ =~ cmd | |
196 | + do_file(cmd) | |
197 | + end | |
175 | 198 | else |
176 | 199 | throw "Unknown file or directory: #{cmd}" |
177 | 200 | end |