+2016-12-09 Daigo Moriwaki <daigo at debian dot org>
+
+ * 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.
+ (Closes #36855)
+
2016-11-26 Daigo Moriwaki <daigo at debian dot org>
* [shogi-server] Allow to customize maximum lenght of a login indentifier
if $0 == __FILE__
def usage
- puts "Usage: #{$0} [OPTIONS] dir [...]"
- puts "Options:"
+puts <<-EOF
+SYNOPSIS:
+ #{$0} [OPTION]... file or dir [...]
+
+DESCRIPTION:
+ It calculates game statistics, reading CSA record files.
+ If an argument is a directory, it attempts to find files in its
+ subdirectories recursively.
+
+ --filter regexp
+ only files that are matched with a regexp are processed (default: no filter)
+
+ --repeat n
+ at most n files are processed (default: unlimitted)
+EOF
exit 1
end
usage if ARGV.empty?
parser = GetoptLong.new(
- ['--repeat', '-n', GetoptLong::REQUIRED_ARGUMENT]
+ ['--repeat', '-n', GetoptLong::REQUIRED_ARGUMENT],
+ ['--filter', GetoptLong::REQUIRED_ARGUMENT],
+ ['--h', '-h', GetoptLong::NO_ARGUMENT]
)
begin
parser.each_option do |name, arg|
usage
end
+ if $OPT_H
+ usage
+ end
+
$OPT_REPEAT = $OPT_REPEAT.to_i
if $OPT_REPEAT == 0
$OPT_REPEAT = -1
if FileTest.directory?(cmd)
Dir.glob(File.join(cmd, "**", "*.csa")).each do |file|
break if $OPT_REPEAT == 0
- do_file(file)
+ if $OPT_FILTER.nil? || /#{$OPT_FILTER}/ =~ file
+ do_file(file)
+ end
end
elsif FileTest.file?(cmd)
break if $OPT_REPEAT == 0
- do_file(cmd)
+ if $OPT_FILTER.nil? || /#{$OPT_FILTER}/ =~ cmd
+ do_file(cmd)
+ end
else
throw "Unknown file or directory: #{cmd}"
end