def get_records_for_display(full_name):
    """ Get records descriptions

    full_name -- fully qualified name, in form db.coll
    """
    try:
        inv.setup_internal_client()
        db = inv.int_client[inv.ALL_STRUC.name]
    except Exception as e:
        raise ih.ConnectOrAuthFail("")
        return None

    try:
        parts = ih.get_description_key_parts(full_name)
        records = retrieve_records(db, parts[0], parts[1])
    except Exception as e:
        inv.log_dest.error("Unable to get requested inventory " + str(e))
        return {'data': None, 'scrape_date': None}

    try:
        return {
            'data': ih.diff_records(records['data']),
            'scrape_date': records['scrape_date']
        }
    except Exception as e:
        inv.log_dest.error("Error decoding inventory object " + str(e))
        return {'data': None, 'scrape_date': None}
def retrieve_db_listing(db_name=None):
    """Retrieve listing for all or given database."""

    inv.setup_internal_client()
    try:
        db = inv.int_client[inv.ALL_STRUC.name]
    except Exception:
        raise ih.ConnectOrAuthFail("")
        return None

    return gen_retrieve_db_listing(db, db_name)
def collate_collection_info(db_name):
    """Fetches and collates viewable info for collections in named db
    """
    try:
        inv.setup_internal_client()
        db = inv.int_client[inv.ALL_STRUC.name]
    except Exception:
        raise ih.ConnectOrAuthFail("")
        return None

    db_info = idc.get_db(db, db_name)
    if not db_info['exist']:
        return
    colls_info = idc.get_all_colls(db, db_info['id'])

    for coll in colls_info:
        rec_info = idc.count_records_and_types(db, coll['_id'])
        coll['records'] = comma(rec_info)

    return colls_info
Exemple #4
0
def check_locks(resp):
    """Check if request pertains to locked coll
    or editing is locked globally
    """
    inv.setup_internal_client()
    try:
        db = inv.int_client[inv.ALL_STRUC.name]
    except Exception:
        raise ih.ConnectOrAuthFail("")
    if get_lockout_state():
        raise EditLockError('Global Edit Lock')
    try:
        db_name = resp['db']
        coll_name = resp['collection']
        db_id = idc.get_db_id(db, db_name)
        coll_id = idc.get_coll_id(db, db_id['id'], coll_name)
        if check_locked(db, coll_id['id']):
            raise EditLockError('Collection locked')
    except Exception as e:
        inv.log_dest.error("Error in locking " + str(e))
        raise e
Exemple #5
0
def is_valid_db_collection(db_name, collection_name):
    """Check if db and collection name (if not None) exist"""
    try:
        inv.setup_internal_client()
        db = inv.int_client[inv.ALL_STRUC.name]
    except Exception as e:
        raise ih.ConnectOrAuthFail("")
        return False
    try:
        db_id = idc.get_db_id(db, db_name)
        if not db_id['exist']:
            return False
        if collection_name:
            coll_id = idc.get_coll_id(db, db_id['id'], collection_name)
            if not coll_id['exist']:
                return False
    except Exception as e:
        inv.log_dest.error('Failed checking existence of ' + db_name + ' ' +
                           collection_name + ' ' + str(e))
        return False
    return True
def get_nicename(db_name, collection_name):
    """Return the nice_name string for given db/coll pair"""

    try:
        inv.setup_internal_client()
        db = inv.int_client[inv.ALL_STRUC.name]
    except Exception as e:
        raise ih.ConnectOrAuthFail("")
        return None
    try:
        if collection_name:
            db_id = idc.get_db_id(db, db_name)
            coll_rec = idc.get_coll(db, db_id['id'], collection_name)
            nice_name = coll_rec['data']['nice_name']
        else:
            db_rec = idc.get_db(db, db_name)
            print db_rec
            nice_name = db_rec['data']['nice_name']
        return nice_name
    except Exception as e:
        inv.log_dest.error('Failed to get nice name for ' + db_name + ' ' +
                           collection_name + ' ' + str(e))
        #Can't return nice name so return None
        return None