# Path: dlstats/constants.py
# CACHE_URL = os.environ.get('WIDUKIND_CACHE_URL', 'simple') #redis://localhost:6379/0
# SCHEMAS_VALIDATION_DISABLE = os.environ.get('WIDUKIND_SCHEMAS_VALIDATION_DISABLE', 'false')
# 
# Path: dlstats/client.py
# DLSTATS_SETTINGS = dict(auto_envvar_prefix='DLSTATS')
# DEFAULT_PATH_REQUESTS_CACHE = os.path.abspath(os.path.join(tempfile.gettempdir(), "dlstats"))
# class Context(object):
# class ComplexCLI(click.MultiCommand):
#     def __init__(self, mongo_url=None, verbose=False,
#                  log_level='ERROR', log_config=None, log_file=None,
#                  trace=False,
#                  cache_enable=False,  
#                  requests_cache_enable=None, requests_cache_path=None, 
#                  requests_cache_expire=None,               
#                  debug=False, silent=False, pretty=False, quiet=False):
#     def _set_log_file(self):
#     def _set_cache(self):
#     def _set_requests_cache(self):
#     def log(self, msg, *args):
#     def log_error(self, msg, *args):
#     def log_ok(self, msg, *args):
#     def log_warn(self, msg, *args):
#     def pretty_print(self, obj):
#     def mongo_client(self):
#     def lock(self, key, owner, timeout=None, expire=None):
#     def mongo_database(self):
#     def mongo_fs(self):
#     def list_commands(self, ctx):
#     def get_command(self, ctx, name):
# def cli():
# def main():
# 
# Path: dlstats/fetchers/schemas.py
# def date_validator(value):
# def typecheck(_type, msg=None):
#     def validator(value):


import time
import click
        import pymongo
from pprint import pprint
from widukind_common.utils import create_or_update_indexes
from widukind_common import tests_tools as utils
from dlstats import constants
from dlstats import client
from dlstats.fetchers import schemas
        from pymongo import ReadPreference
@client.opt_silent
@client.opt_debug
@client.opt_mongo_url
@click.option('--drop-before', is_flag=True, help="Drop index before")
def cmd_reindex(drop_before=False, **kwargs):
    """Reindex collections"""

    ctx = client.Context(**kwargs)
    ctx.log_warn("All Writes operations is blocked pending run !")
    
    if ctx.silent or click.confirm('Do you want to continue?', abort=True):
    
        db = ctx.mongo_database()
        
        if drop_before:
            with click.progressbar(constants.COL_ALL ,
                                   length=len(constants.COL_ALL)+1,
                                   label='Drop indexes') as collections:
                for collection in collections:
                    ctx.log_ok(" [%s]" % collection)
                    try:
                        db[collection].drop_indexes()
                    except Exception as err:
                        ctx.log_warn(str(err))

        ctx.log("Create or update all indexes !")
        create_or_update_indexes(db)
        
        if not drop_before:
            with click.progressbar(constants.COL_ALL,

# Path: dlstats/constants.py
# CACHE_URL = os.environ.get('WIDUKIND_CACHE_URL', 'simple') #redis://localhost:6379/0
# SCHEMAS_VALIDATION_DISABLE = os.environ.get('WIDUKIND_SCHEMAS_VALIDATION_DISABLE', 'false')
# 
# Path: dlstats/client.py
# DLSTATS_SETTINGS = dict(auto_envvar_prefix='DLSTATS')
# DEFAULT_PATH_REQUESTS_CACHE = os.path.abspath(os.path.join(tempfile.gettempdir(), "dlstats"))
# class Context(object):
# class ComplexCLI(click.MultiCommand):
#     def __init__(self, mongo_url=None, verbose=False,
#                  log_level='ERROR', log_config=None, log_file=None,
#                  trace=False,
#                  cache_enable=False,  
#                  requests_cache_enable=None, requests_cache_path=None, 
#                  requests_cache_expire=None,               
#                  debug=False, silent=False, pretty=False, quiet=False):
#     def _set_log_file(self):
#     def _set_cache(self):
#     def _set_requests_cache(self):
#     def log(self, msg, *args):
#     def log_error(self, msg, *args):
#     def log_ok(self, msg, *args):
#     def log_warn(self, msg, *args):
#     def pretty_print(self, obj):
#     def mongo_client(self):
#     def lock(self, key, owner, timeout=None, expire=None):
#     def mongo_database(self):
#     def mongo_fs(self):
#     def list_commands(self, ctx):
#     def get_command(self, ctx, name):
# def cli():
# def main():
# 
# Path: dlstats/fetchers/schemas.py
# def date_validator(value):
# def typecheck(_type, msg=None):
#     def validator(value):


# Path: dlstats/commands/cmd_mongo.py
import time
import click
        import pymongo
from pprint import pprint
from widukind_common.utils import create_or_update_indexes
from widukind_common import tests_tools as utils
from dlstats import constants
from dlstats import client
from dlstats.fetchers import schemas
        from pymongo import ReadPreference

@client.opt_silent
@client.opt_debug
@client.opt_mongo_url
@click.option('--drop-before', is_flag=True, help="Drop index before")
def cmd_reindex(drop_before=False, **kwargs):
    """Reindex collections"""

    ctx = client.Context(**kwargs)
    ctx.log_warn("All Writes operations is blocked pending run !")
    
    if ctx.silent or click.confirm('Do you want to continue?', abort=True):
    
        db = ctx.mongo_database()
        
        if drop_before:
            with click.progressbar(constants.COL_ALL ,
                                   length=len(constants.COL_ALL)+1,
                                   label='Drop indexes') as collections:
                for collection in collections:
                    ctx.log_ok(" [%s]" % collection)
                    try:
                        db[collection].drop_indexes()
                    except Exception as err:
                        ctx.log_warn(str(err))

        ctx.log("Create or update all indexes !")
        create_or_update_indexes(db)
        
        if not drop_before:
            with click.progressbar(constants.COL_ALL,

                                   length=len(constants.COL_ALL)+1,