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 0B873138A87 for ; Tue, 24 Feb 2015 02:00:18 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 3DEA5E083B; Tue, 24 Feb 2015 02:00:16 +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 B955FE083B for ; Tue, 24 Feb 2015 02:00:15 +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 4E98C340863 for ; Tue, 24 Feb 2015 02:00:14 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 6AD2D126B3 for ; Tue, 24 Feb 2015 02:00:12 +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: <1424742547.149ce341820a66010e8592975d86e5d6dd0c6b7e.robbat2@gentoo> Subject: [gentoo-commits] proj/ag:master commit in: /, lib/ X-VCS-Repository: proj/ag X-VCS-Files: ag lib/storage.rb X-VCS-Directories: lib/ / X-VCS-Committer: robbat2 X-VCS-Committer-Name: Robin H. Johnson X-VCS-Revision: 149ce341820a66010e8592975d86e5d6dd0c6b7e X-VCS-Branch: master Date: Tue, 24 Feb 2015 02:00:12 +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: 5b2bd889-5538-4a67-a7f6-bdc5e9072c14 X-Archives-Hash: 4e1fc82c1de1015d9f296a0c1f8b423b commit: 149ce341820a66010e8592975d86e5d6dd0c6b7e Author: Robin H. Johnson gentoo org> AuthorDate: Tue Feb 24 01:47:30 2015 +0000 Commit: Robin H. Johnson gentoo org> CommitDate: Tue Feb 24 01:49:07 2015 +0000 URL: http://sources.gentoo.org/gitweb/?p=proj/ag.git;a=commit;h=149ce341 Expose delete index. Signed-off-by: Robin H. Johnson gentoo.org> --- ag | 23 +++++++++++++++++++---- lib/storage.rb | 11 +++++++++-- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/ag b/ag index c5056ff..4636675 100755 --- a/ag +++ b/ag @@ -27,7 +27,7 @@ $options.readonly = false $options.jobs = false op = OptionParser.new do |opts| - opts.banner = "Usage: ag <<--index-full|--index-new|--delete|--reindex|--info> <--list listname>> <[--file|--msgid|--hash] > [options]" + 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 abort 'Can only select one action' if $options.action != nil @@ -41,10 +41,16 @@ op = OptionParser.new do |opts| $options.action = :do_incremental end - opts.on('--delete', 'Delete message. Needs --file, --msgid, or --hash') do + opts.on('--delete-msg', 'Delete message. Needs --file, --msgid, or --hash') do abort 'Can only select one action' if $options.action != nil - $options.action = :do_delete + $options.action = :do_delete_msg + end + + opts.on('--delete-Index', 'Delete index. Needs --list') do + abort 'Can only select one action' if $options.action != nil + + $options.action = :do_index end opts.on('--info', 'Display message details. Needs --file, --msgid, or --hash') do @@ -156,7 +162,7 @@ def do_incremental Ag::Threading.calc($options.name) unless $options.no_threading end -def do_delete +def do_delete_msg id = Ag::Utils.resolve_id begin @@ -166,6 +172,15 @@ def do_delete end end +def do_delete_index + begin + Ag::Storage.delete_index($options.name) + rescue Elasticsearch::Transport::Transport::Errors::NotFound => e + rescue => e + $stderr.puts "Cannot delete index: #{e}" + end +end + def do_reindex abort 'Come back later.' end diff --git a/lib/storage.rb b/lib/storage.rb index 5b360f5..656a6bf 100644 --- a/lib/storage.rb +++ b/lib/storage.rb @@ -3,9 +3,16 @@ require 'date' module Ag::Storage module_function + + # Throws Elasticsearch::Transport::Transport::Errors::NotFound + # if the list does not exist + def delete_index(list) + $es.indices.delete index: 'ml-' + list + end + def create_index(list) begin - $es.indices.delete index: 'ml-' + list + delete_index(ist) rescue Elasticsearch::Transport::Transport::Errors::NotFound => e $stderr.puts "Index did not exist yet. Creating." if $options.debug end @@ -267,4 +274,4 @@ module Ag::Storage return nil if result['hits']['total'] == 0 result['hits']['hits'].first end -end \ No newline at end of file +end