# -*- coding: utf-8 -*-

from __future__ import unicode_literals, print_function, absolute_import

import sys

from needlestack.base import _get_all_indexes, _load_all_indexes
from needlestack.connection import manager
from needlestack.exceptions import (IndexAlreadyExists,
                                    IndexDoesNotExists)

_min_verbosity_level = 1


def sync_indexes(backend="default", verbosity=0):
    """
    Synchronize all registred indexes to backend.
    """

    if verbosity >= _min_verbosity_level:
        print("Syncronizing indexes...", file=sys.stderr)

    _load_all_indexes()
    indexes = _get_all_indexes()

    connection = manager.get_connection(backend)
    for index in indexes:
        try:
            connection.create_index(index)
            if verbosity > 0:
                print("Creating index '{0}'".format(index.get_name()), file=sys.stderr)
        except IndexAlreadyExists:
            if verbosity > 0:
                print("Index '{0}' already exists.".format(index.get_name()), file=sys.stderr)


def drop_indexes(backend="default", verbosity=0):
    """
    Delete all registred indexes from backend.
    """

    if verbosity >= _min_verbosity_level:
        print("Droping all registred indexes from current backend...", file=sys.stderr)

    connection = manager.get_connection(backend)

    _load_all_indexes()
    indexes = _get_all_indexes()

    for index in indexes:
        try:
            connection.drop_index(index)
            if verbosity > 0:
                print("Deleting index '{0}'".format(index.get_name()), file=sys.stderr)
        except IndexDoesNotExists:
            if verbosity > 0:
                print("Index '{0}' does not exist.".format(index.get_name()), file=sys.stderr)

@@ -1078,32 +1078,43 @@
 lt%22, verbosity=0
+, all=False
 ):%0A    %22%22%22%0A    D
@@ -1345,16 +1345,82 @@
 ckend)%0A%0A
+    if all:%0A        connection.delete_all_indexes()%0A    else:%0A    
     _loa
@@ -1427,32 +1427,36 @@
 d_all_indexes()%0A
+    
     indexes = _g
@@ -1473,24 +1473,28 @@
 exes()%0A%0A    
+ 
+   
 for index in
@@ -1503,37 +1503,45 @@
 ndexes:%0A        
+   
+ 
 try:%0A
+    
             conn
@@ -1569,32 +1569,36 @@
 ex)%0A            
+    
 if verbosity %3E 0
@@ -1591,32 +1591,36 @@
  verbosity %3E 0:%0A
+    
                 
@@ -1691,32 +1691,36 @@
 stderr)%0A        
+    
 except IndexDoes
@@ -1734,32 +1734,36 @@
 ts:%0A            
+    
 if verbosity %3E 0
@@ -1756,32 +1756,36 @@
  verbosity %3E 0:%0A
+    
                 

Add all keyword argument to drop_indexes command function.