Esempio n. 1
0
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,
                                   label='Reindex collections') as collections:
                for collection in collections:
                    ctx.log_ok(" [%s]" % collection)
                    try:
                        db[collection].reindex()
                    except Exception as err:
                        ctx.log_warn(str(err))
Esempio n. 2
0
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,
                                   label='Reindex collections') as collections:
                for collection in collections:
                    ctx.log_ok(" [%s]" % collection)
                    try:
                        db[collection].reindex()
                    except Exception as err:
                        ctx.log_warn(str(err))
Esempio n. 3
0
    def setUp(self):
        BaseTestCase.setUp(self)
        
        db = get_mongo_db()
        self.db = db.client["widukind_test"] 
        
        self.assertEqual(self.db.name, "widukind_test")

        utils.clean_mongodb(self.db)
                
        create_or_update_indexes(self.db, force_mode=True)
Esempio n. 4
0
    def setUp(self):
        BaseTestCase.setUp(self)

        from widukind_common.utils import get_mongo_db, create_or_update_indexes
        from widukind_common import tests_tools as utils
        
        db = get_mongo_db()
        self.db = db.client["widukind_test"] 
        
        self.assertEqual(self.db.name, "widukind_test")

        utils.clean_mongodb(self.db)
                
        create_or_update_indexes(self.db, force_mode=True)

        self._collections_is_empty()
Esempio n. 5
0
    def __init__(self, 
                 provider_name=None, 
                 db=None, 
                 is_indexes=True,
                 version=0,
                 max_errors=5,
                 use_existing_file=False,
                 not_remove_files=False,
                 **kwargs):
        """
        :param str provider_name: Provider Name
        :param pymongo.database.Database db: MongoDB Database instance        
        :param bool is_indexes: Bypass create_or_update_indexes() if False 

        :raises ValueError: if provider_name is None
        """        
        if not provider_name:
            raise ValueError("provider_name is required")

        self.provider_name = provider_name
        self.db = db or get_mongo_db()
        self.version = version
        self.max_errors = max_errors
        self.use_existing_file = use_existing_file
        self.not_remove_files = not_remove_files
        
        self.provider = None
        
        self.errors = 0

        self.categories_filter = [] #[category_code]
        self.datasets_filter = []   #[dataset_code]
        
        self.selected_datasets = {}
        
        self.store_path = os.path.abspath(os.path.join(tempfile.gettempdir(), 
                                                       self.provider_name))
        self.for_delete = []
        
        if is_indexes:
            create_or_update_indexes(self.db)
            
        if IS_SCHEMAS_VALIDATION_DISABLE:
            logger.warning("schemas validation is disable")
Esempio n. 6
0
def cmd_reindex(**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()
        
        create_or_update_indexes(db)
        
        with click.progressbar(constants.COL_ALL,
                               length=len(constants.COL_ALL),
                               label='Reindex collections') as collections:
            for collection in collections:
                print(" [%s]" % collection)
                _col = db[collection]
                _col.reindex()
Esempio n. 7
0
    def __init__(self, 
                 provider_name=None, 
                 db=None, 
                 is_indexes=True):
        """
        :param str provider_name: Provider Name
        :param pymongo.database.Database db: MongoDB Database instance        
        :param bool is_indexes: Bypass create_or_update_indexes() if False 

        :raises ValueError: if provider_name is None
        """        
        if not provider_name:
            raise ValueError("provider_name is required")

        self.provider_name = provider_name
        self.db = db or get_mongo_db()
        self.provider = self.load_provider_from_db()
        
        if is_indexes:
            create_or_update_indexes(self.db)
Esempio n. 8
0
 def setUp(self):
     super().setUp()
     self.db = self.app.widukind_db
     self.assertEqual(self.db.name, "widukind_test")
     utils.clean_mongodb(self.db)
     create_or_update_indexes(self.db, force_mode=True)
Esempio n. 9
0
 def setUp(self):
     super().setUp()
     self.db = self.app.widukind_db
     self.assertEqual(self.db.name, "widukind_test")
     utils.clean_mongodb(self.db)
     create_or_update_indexes(self.db, force_mode=True)
Esempio n. 10
0
 def set_indexes(self):
     create_or_update_indexes(self.db, force_mode=True, background=False)