示例#1
0
def dbu_create_table_if_doesntexist(table_name):
    conn = dbu_get_conn()
    c = conn.cursor()
    exec_cmd = "SELECT * FROM " + table_name
    try:
        c.execute(exec_cmd)
    except:
        # Table doesn't exist. so create.
        db_login.create_all()
示例#2
0
def dbinit():
    logging.debug("Database initialisation")
    db_login.create_all()
    dbBrowseImages()
示例#3
0
def dbBuildTableForImage(img, bld_imgdb = False, bld_dfxmldb = False):
    """ This routine builds/adds the DFXML table entry to the DB for the
        specified image. This is needed where a user selects an individual
        image in the image matrix and opts to add or delete corresponding table.
    """
    table_added = 0
    if bld_dfxmldb:
        table_name = "bcaw_dfxmlinfo"
    elif bld_imgdb:
        table_name = "bcaw_images"
    else:
        # if bld_imgdb == False and bld_dfxmldb == False:
        return(-1, "No DB Specified")

    if not image_browse.bcaw_is_imgtype_supported(img):
        return(-1, "Wrong Image Type")

    # No need to create table if it already exists
    if dbu_does_table_exist_for_img(img, table_name):
        return(-2, "Table entry exists for the image")
    else:
        db_login.create_all()
        table_added += 1

    if bld_imgdb:
        # By setting image to None, it sets the flags for all images. We don't
        # do individual flag setting for imgdb.
        image_browse.bcawSetFlagInMatrix('img_db_exists', bld_imgdb, None)

    if bld_dfxmldb:
        image_browse.bcawSetFlagInMatrix('dfxml_db_exists', bld_dfxmldb, img)
    # FIXME: Partition info will be added to the metadata info
    # Till then the following three lines are not necessary.
    image_index = image_browse.bcawGetImageIndex(str(img), False)
    dm = bcaw()
    image_path = image_dir+'/'+img
    dm.num_partitions = dm.bcawGetNumPartsForImage(image_path, image_index)
    xmlfile = dm.dbGetImageInfoXml(image_path)
    if (xmlfile == None):
        logging.debug('No XML file generated for image info. Returning')
        # Commented out returning from here since there might be cases (raw images)
        # which don't have an image table, but can have a dfxml table
        ## return (-1, "No Image XML File generated")
    logging.debug('XML File %s generated for image', xmlfile)

    dfxmlfile = dm.dbGetInfoFromDfxml(image_path)
    if (dfxmlfile == None):
        logging.debug('>> No DFXML file generated for image info. Returning')
        return (-1, "No DFXML generated")

    logging.debug('>> DFXML File %s generated for image', dfxmlfile)

    # Read the XML file and populate the record for this image
    if bld_imgdb:
        dbrec = bcawGetXmlInfo(xmlfile)

        # FIXME: Retained temporarily. Probably not needed.
        dbrec['image_name'] = img
        dbrec['indexed'] = 0 # Just initialize to something

        # Populate the db:
        # Add the created record/session to the DB
        bcawDbSessionAdd(dbrec)

    if bld_dfxmldb:
        d_dbrec = bcawGetDfxmlInfo(dfxmlfile, img)
    if table_added > 0:
        return(0, "New tables added to the DB")
    else:
        retstr = "Table entries exist for the image " + img
        return(0, retstr)
示例#4
0
def dbinit(): 
    #db_login.init_app(app)
    db_login.create_all()
    '''
示例#5
0
def dbBuildTableForImage(img, bld_imgdb = False, bld_dfxmldb = False):
    """ This routine builds/adds the DFXML table entry to the DB for the
        specified image. This is needed where a user selects an individual 
        image in the image matrix and opts to add or delete corresponding table.
    """
    table_added = 0
    if bld_imgdb and bld_dfxmldb:
        # table_name set to dfxmlinfo - if it exists, bcaw_images has to be there.
        table_name = "bcaw_dfxmlinfo"
    else:
        if bld_imgdb:
            table_name = "bcaw_images"
        elif bld_dfxmldb:
            table_name = "bcaw_dfxmlinfo"
        else:
            # if bld_imgdb == False and bld_dfxmldb == False:
            return(-1, "No DB Specified")

    if not img.endswith(".E01") or img.endswith(".AFF"):
        logging.debug('>> Not building Table: Wrong image type: %s', img)
        # print ">> Not building Table: Wrong image type: ", img
        return(-1, "Wrong Image Type")

    # No need to create table if it already exists
    if dbu_does_table_exist_for_img(img, table_name):
        logging.debug('>> Table already exists for image %s', img)
        # print ">> Table already exists for image " , img
        return(-2, "Table entry exists for the image")
    else:
        logging.debug('>> Table for image %s does not exist', img)
        # print ">> Table for image {} does not exist: ".format(img)
        db_login.create_all()
        table_added += 1

    if bld_imgdb:
        # update the image_matrix
        logging.debug('D: dbBuildTableForImage: Updating the matrix for img_db_exists')
        # print "D: dbBuildTableForImage: Updating the matrix for img_db_exists "

        # By setting image to None, it sets the flags for all images. We don't 
        # do individual flag setting for imgdb.
        image_browse.bcawSetFlagInMatrix('img_db_exists', bld_imgdb, None)

    if bld_dfxmldb:
        logging.debug('D: dbBuildTableForImage: Updating the matrix for dfxml_db_exists')
        # print "D: dbBuildTableForImage: Updating the matrix for dfxml_db_exists "
        image_browse.bcawSetFlagInMatrix('dfxml_db_exists', bld_dfxmldb, img)
    # FIXME: Partition info will be added to the metadata info
    # Till then the following three lines are not necessary.
    image_index = image_browse.bcawGetImageIndex(str(img), False)
    dm = bcaw_utils.bcaw()
    image_path = image_dir+'/'+img
    dm.num_partitions = dm.bcawGetNumPartsForImage(image_path, image_index)
    xmlfile = dm.dbGetImageInfoXml(image_path)
    if (xmlfile == None):
        logging.debug('No XML file generated for image info. Returning')
        # print("No XML file generated for image info. Returning")
        return (-1, "No Image XML File generated")
    logging.debug('XML File %s generated for image', xmlfile)
    # print("XML File {} generated for image {}".format(xmlfile, img))

    dfxmlfile = dm.dbGetInfoFromDfxml(image_path)
    if (dfxmlfile == None):
        logging.debug('>> No DFXML file generated for image info. Returning')
        # print(">> No DFXML file generated for image info. Returning")
        return (-1, "No DFXML generated")

    logging.debug('>> DFXML File %s generated for image', dfxmlfile)
    # print(">> DFXML File {} generated for image {}".format(dfxmlfile, img))

    # Read the XML file and populate the record for this image
    if bld_imgdb:
        dbrec = bcawGetXmlInfo(xmlfile)

        # FIXME: Retained temporarily. Probably not needed.
        ##dbu_create_table_if_doesntexist("bcaw_images")
        dbrec['image_name'] = img
        dbrec['indexed'] = 0 # Just initialize to something

        # Populate the db:
        # Add the created record/session to the DB
        bcawDbSessionAdd(dbrec)

        ## print("D: Adding dbrec session to the DB: ", dbrec)
    if bld_dfxmldb:
        d_dbrec = bcawGetDfxmlInfo(dfxmlfile, img)
    if table_added > 0:
        return(0, "New tables added to the DB")
    else:
        retstr = "Table entries exist for the image " + img 
        return(0, retstr)