From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 32367138AD7 for ; Tue, 24 Feb 2015 02:17:08 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id B5D80E08CA; Tue, 24 Feb 2015 02:17:06 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 414A8E0885 for ; Tue, 24 Feb 2015 02:17:06 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 0B2C5340910 for ; Tue, 24 Feb 2015 02:17:05 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 09DFB126B9 for ; Tue, 24 Feb 2015 02:17:02 +0000 (UTC) From: "Robin H. Johnson" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Robin H. Johnson" Message-ID: <1424744215.ef43e934de266b49dec9373cb6c281c0ee7c67dc.robbat2@gentoo> Subject: [gentoo-commits] proj/ag:master commit in: /, lib/ X-VCS-Repository: proj/ag X-VCS-Files: ag lib/storage.rb lib/utils.rb X-VCS-Directories: / lib/ X-VCS-Committer: robbat2 X-VCS-Committer-Name: Robin H. Johnson X-VCS-Revision: ef43e934de266b49dec9373cb6c281c0ee7c67dc X-VCS-Branch: master Date: Tue, 24 Feb 2015 02:17:02 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: f3125038-7d67-46ef-b32b-65a2d601800d X-Archives-Hash: 426984efc5fc79dbb0baae5b59a579f0 commit: ef43e934de266b49dec9373cb6c281c0ee7c67dc Author: Robin H. Johnson gentoo org> AuthorDate: Tue Feb 24 02:16:55 2015 +0000 Commit: Robin H. Johnson gentoo org> CommitDate: Tue Feb 24 02:16:55 2015 +0000 URL: http://sources.gentoo.org/gitweb/?p=proj/ag.git;a=commit;h=ef43e934 Improve delete code paths. Signed-off-by: Robin H. Johnson gentoo.org> --- ag | 37 +++++++++++++++++++++++-------------- lib/storage.rb | 4 ++++ lib/utils.rb | 6 ++++++ 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/ag b/ag index 57dc0a4..ffe714b 100755 --- a/ag +++ b/ag @@ -26,41 +26,46 @@ $options.debug = false $options.readonly = false $options.jobs = false $options.progress = true +$options.need_argument = true +$options.argmode = nil op = OptionParser.new do |opts| opts.banner = "Usage: ag <<--index-full|--index-new|--delete-msg|--delete-index|--reindex|--info> <--list listname>> <[--file|--msgid|--hash] > [options]" - opts.on('--index-full', 'Read the full past archive from the .cur Maildir') do + opts.on('--index-full', 'Read the full past archive from Maildir/cur. Needs --list and a Maildir') do abort 'Can only select one action' if $options.action != nil $options.action = :do_full + $options.argmode = :dir end - opts.on('--index-new', 'Read new messages from .new and move them to .cur') do + opts.on('--index-new', 'Read new messages from Maildir/new and move them to Maildir/cur. Needs --list and a Maildir') do abort 'Can only select one action' if $options.action != nil $options.action = :do_incremental + $options.argmode = :dir end - opts.on('--delete-msg', 'Delete message. Needs --file, --msgid, or --hash') do + opts.on('--delete-msg', 'Delete message. Needs --list and one of --file, --msgid, or --hash') do abort 'Can only select one action' if $options.action != nil $options.action = :do_delete_msg end - - opts.on('--delete-Index', 'Delete index. Needs --list') do + + opts.on('--delete-index', 'Delete index. Needs --list') do abort 'Can only select one action' if $options.action != nil $options.action = :do_index + $options.need_argument = false end - opts.on('--info', 'Display message details. Needs --file, --msgid, or --hash') do + opts.on('--info', 'Display message details. Needs --list and one of --file, --msgid, or --hash') do abort 'Can only select one action' if $options.action != nil $options.action = :do_info end - opts.on('--reindex', 'Reindex message. Needs --file') do + opts.on('--reindex', 'Reindex message. Needs --list and --file') do abort 'Can only select one action' if $options.action != nil $options.action = :do_reindex @@ -105,7 +110,7 @@ op = OptionParser.new do |opts| opts.on('--jobs JOBS', 'Number of parallel jobs to run (defaults to 75% of core count)') do |jobs| $options.jobs = jobs.to_i end - + opts.on('--progress', 'Display the progress bar') do $options.progress = true end @@ -117,11 +122,13 @@ op.parse! abort op.help unless $options.action abort 'List name required' unless $options.name -$options.dir = ARGV[0] or abort 'Need a Maildir/File/Hash/Message-Id to work with' +$options.dir = ARGV[0] or abort 'Need a Maildir/File/Hash/Message-Id to work with' if $options.need_argument -# Open maildir and set serializer -$maildir = Maildir.new(File.join($options.dir), false) -$maildir.serializer = Maildir::Serializer::Mail.new +if($options.argmode == :dir) + # Open maildir and set serializer + $maildir = Maildir.new(File.join($options.dir), false) + $maildir.serializer = Maildir::Serializer::Mail.new +end # Connect to Elasticsearch $es = Elasticsearch::Client.new(log: false) @@ -132,12 +139,13 @@ Ag::Utils.proc_count = $options.jobs ############################################################################### def do_full + abort "Wrong argument type: #{$options.argmode.to_s}" unless $options.argmode == :dir Ag::Storage.create_index($options.name) messages = $maildir.list(:cur) opts = { - :in_processes => Ag::Utils.proc_count, + :in_processes => Ag::Utils.proc_count, } opts[:progress] = "Importing #{$options.name}" if $options.progress Parallel.each(messages, opts) do |maildir_message| @@ -155,10 +163,11 @@ def do_full end def do_incremental + abort "Wrong argument type: #{$options.argmode.to_s}" unless $options.argmode == :dir messages = $maildir.list(:cur) opts = { - :in_processes => Ag::Utils.proc_count, + :in_processes => Ag::Utils.proc_count, } opts[:progress] = "Importing #{$options.name}" if $options.progress Parallel.each(messages, opts) do |maildir_message| diff --git a/lib/storage.rb b/lib/storage.rb index 8ab2d4e..68de268 100644 --- a/lib/storage.rb +++ b/lib/storage.rb @@ -141,6 +141,10 @@ module Ag::Storage resolve_by_field(list, :raw_filename, filename) end + def resolve_hash(list, hash = nil) + resolve_by_field(list, :_id, hash) + end + def store(list, message, filename) content = get_content(message, filename) diff --git a/lib/utils.rb b/lib/utils.rb index 38349e0..b9156cd 100644 --- a/lib/utils.rb +++ b/lib/utils.rb @@ -33,6 +33,12 @@ module Ag id = Ag::Storage.resolve_message_id($options.name, $options.dir) when :file id = Ag::Storage.resolve_filename($options.name, $options.dir) + when :hash + id = Ag::Storage.resolve_hash($options.name, $options.dir) + when :dir + abort 'Cannot perform resolve a directory to a message id' + when nil + abort 'Cannot resolve a nil id' end id