[Groonga-commit] groonga/groonga-query-log [master] extractor: use Extractor#run in the executable script

Back to archive index

Haruka Yoshihara null+****@clear*****
Mon Dec 17 15:24:06 JST 2012


Haruka Yoshihara	2012-12-17 15:24:06 +0900 (Mon, 17 Dec 2012)

  New Revision: 8843bc16d5cbda4459fd1215c5eea0bb270f53eb
  https://github.com/groonga/groonga-query-log/commit/8843bc16d5cbda4459fd1215c5eea0bb270f53eb

  Log:
    extractor: use Extractor#run in the executable script

  Modified files:
    bin/groonga-query-log-extract

  Modified: bin/groonga-query-log-extract (+6 -96)
===================================================================
--- bin/groonga-query-log-extract    2012-12-17 15:15:07 +0900 (ab247da)
+++ bin/groonga-query-log-extract    2012-12-17 15:24:06 +0900 (308a3f3)
@@ -17,102 +17,12 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-require "ostruct"
-require "optparse"
-require "pathname"
+require "groonga/query-log/extractor"
 
-require "groonga/query-log"
-
-options = OpenStruct.new
-options.unify_format = nil
-options.commands = []
-options.exclude_commands = []
-options.output_path = nil
-option_parser = OptionParser.new do |parser|
-  parser.banner += " QUERY_LOG1 ..."
-
-  available_formats = ["uri", "command"]
-  parser.on("--unify-format=FORMAT",
-            available_formats,
-            "Unify command format to FORMAT.",
-            "(#{available_formats.join(', ')})",
-            "[not unify]") do |format|
-    options.unify_format = format
-  end
-
-  parser.on("--command=COMMAND",
-            "Extract only COMMAND.",
-            "To extract one or more commands,",
-            "specify this command a number of times.",
-            "Use /.../ as COMMAND to match command with regular expression.",
-            "[all commands]") do |command|
-    case command
-    when /\A\/(.*)\/(i)?\z/
-      options.commands << Regexp.new($1, $2 == "i")
-    when
-      options.commands << command
-    end
-  end
-
-  parser.on("--exclude-command=COMMAND",
-            "Don't extract COMMAND.",
-            "To ignore one or more commands,",
-            "specify this command a number of times.",
-            "Use /.../ as COMMAND to match command with regular expression.",
-            "[no commands]") do |command|
-    case command
-    when /\A\/(.*)\/(i)?\z/
-      options.exclude_commands << Regexp.new($1, $2 == "i")
-    when
-      options.exclude_commands << command
-    end
-  end
-
-  parser.on("--output=PATH",
-            "Output to PATH.",
-            "[standard output]") do |path|
-    options.output_path = path
-  end
-end
-args = option_parser.parse!(ARGV)
-
-if args.empty?
-  puts(option_parser)
+extracter = Groonga::QueryLog::Extractor.new
+begin
+  extracter.run(*ARGV)
+rescue Groonga::QueryLog::Extractor::Error
+  $stderr.puts($!.message)
   exit(false)
 end
-
-def target?(command, options)
-  name = command.name
-  if options.commands.any? {|target_command| target_command === name}
-    true
-  elsif options.exclude_commands.any? {|exclude_command| exclude_command == name}
-    false
-  else
-    true
-  end
-end
-
-def extract(output, options)
-  parser = Groonga::QueryLog::Parser.new
-  parser.parse(ARGF) do |statistic|
-    command = statistic.command
-    next unless target?(command, options)
-    command_text = nil
-    case options.unify_format
-    when "uri"
-      command_text = command.to_uri_format unless command.uri_format?
-    when "command"
-      command_text = command.to_command_format unless command.command_format?
-    end
-    command_text ||= statistic.raw_command
-    output.puts(command_text)
-  end
-end
-
-if options.output_path
-  File.open(options.output_path, "w") do |output|
-    extract(output, options)
-  end
-else
-  extract($stdout, options)
-end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index