Beispiel #1
0
def add_data_and_doc(data,
                     _dbname,
                     _colname,
                     url=cc.URL_KRB,
                     krbheaders=cc.KRBHEADERS,
                     **kwargs):
    """Adds data and document to the db
    """
    logger.debug('add_data_and_doc kwargs: %s' % str(kwargs))

    # check permission
    t0_sec = time()
    if not valid_post_privilege(_dbname, url_krb=url): return None

    id_data = add_data(_dbname, data, url, krbheaders)
    if id_data is None: return None
    doc = mu.docdic(data, id_data, **kwargs)  # ObjectId(id_data)???
    logger.debug(mu.doc_info(doc, fmt='  %s:%s'))  #sep='\n  %16s : %s'

    id_doc = add_document(_dbname, _colname, doc, url, krbheaders)
    if id_doc is None: return None

    msg = 'Add data and doc time %.6f sec' % (time()-t0_sec)\
        + '\n  - data in %s/gridfs id: %s and doc in collection %s id: %s' % (_dbname, id_data, _colname, id_doc)
    logger.debug(msg)

    return id_data, id_doc
Beispiel #2
0
def add_data_and_two_docs(data, exp, det, url=cc.URL_KRB, krbheaders=cc.KRBHEADERS, **kwargs):
    """ Adds data and document to experiment and detector data bases.
    """
    t0_sec = time()

    detname = pro_detector_name(det)
    colname = detname
    dbname_exp = mu.db_prefixed_name(exp)
    dbname_det = mu.db_prefixed_name(detname)

    id_data_exp = add_data(dbname_exp, data, url, krbheaders)
    id_data_det = add_data(dbname_det, data, url, krbheaders)
    if None in (id_data_exp, id_data_det): return None

    doc = mu.docdic(data, id_data_exp, **kwargs)
    logger.debug(mu.doc_info(doc, fmt='  %s:%s')) #sep='\n  %16s : %s'

    id_doc_exp = add_document(dbname_exp, colname, doc, url, krbheaders)
    doc['id_data'] = id_data_det # override
    doc['id_exp']  = id_doc_exp  # add
    id_doc_det = add_document(dbname_det, colname, doc, url, krbheaders)
    if None in (id_doc_exp, id_doc_det): return None

    msg = 'Add 2 data and docs time %.6f sec' % (time()-t0_sec)\
        + '\n  - data in %s/gridfs id: %s and doc in collection %s id: %s' % (dbname_exp, id_data_exp, colname, id_doc_exp)\
        + '\n  - data in %s/gridfs id: %s and doc in collection %s id: %s' % (dbname_det, id_data_det, colname, id_doc_det)
    logger.debug(msg)

    return id_data_exp, id_data_det, id_doc_exp, id_doc_det