예제 #1
0
def dbBrowseImages():
    """ This routine is called at initialization, soon after the tables are created.
        It goes through the disk images in image_dir and builds the db tables
        for both image_db and dfxml_db, if they don't already exist.
    """
    global image_dir
    image_index = 0

    # Since image_list is declared globally, empty it before populating
    global image_list
    del image_list[:]

    for img in os.listdir(image_dir):
        if image_browse.bcaw_is_imgtype_supported(img):
            ## global image_list
            image_list.append(img)

            # Check if table entry already exists for this image:
            if dbu_does_table_exist_for_img(img, 'bcaw_images'):
                logging.debug('Image %s already in bcaw_images table', img)
                continue
            logging.debug('Adding image %s to bcaw_images table.', img)

            # FIXME: Partition info will be added to the metadata info
            # Till then the following three lines are not necessary.
            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')
                # We will just log the message that there is no xmlfile for
                # this image and proceed, as it might be a raw image.
            logging.debug('XML file %s generated for image %s', xmlfile, img)

            dfxmlfile = dm.dbGetInfoFromDfxml(image_path)
            if (dfxmlfile == None):
                logging.debug('No DFXML file generated for image info. Returning')
                continue
            logging.debug('DFXML File %s generated for image', dfxmlfile)

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

            dbrec['image_name'] = img
            dbrec['indexed'] = 0

            # Populate the db: FIXME: See if we need to check if it already exists,
            # or the check for image DB above will suffice as the existance of the
            # image_db is prerequisite for the dfxml db.
            # Add the created record/session to the DB
            bcawDbSessionAdd(dbrec)
            image_index +=1
        else:
            continue

    logging.debug('Image_list %s', image_list)
예제 #2
0
def dbBuildDb(self, task_id, bld_imgdb = False, bld_dfxmldb = False):
    """ Depending on the arguments set, this functioon generates the table
        contents for the given table, for each image in the disk-images
        directory.
    """
    global image_dir
    image_index = 0
    return_msg = None

    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");

    for img in os.listdir(image_dir):
        if image_browse.bcaw_is_imgtype_supported(img):
            logging.debug('Generating table contents for image: %s', img)
            retval, return_msg = dbBuildTableForImage(img, bld_imgdb, bld_dfxmldb)
            if retval < 0:
                logging.debug('Table NOT generated for image, Reason: %s ', return_msg)
                continue
            else:
                image_index += 1

            message = "Table Build in Progress"

            if task_id != None:
                # Send a status update as this is a celery task.
                self.update_state(state='PROGRESS', \
                              task_id=task_id, \
                              meta={'current': image_index, 'status':message})

        else:
            continue

    return(0, return_msg)
예제 #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)