Ejemplo n.º 1
0
def import_file(file_location):
    fd = sys_utils.import_file(file_location, config.file_max)
    if not fd:
        return None, False

    oid = get_oid_from_data(fd["data"])
    if not oid:
        logger.error("Not able to get and oid for %s", file_location)
        return None, False
    
    opts_file = { "file_contents":fd["data"]}   
    opts_meta = { "file_location":file_location, "stat":fd["file_stat"]}   

    if not exists("files", oid, opts_file): 
        new_file = True
        if not process("files", oid, opts_file):
            logger.error("Not able to process file data %s",file_location)
            return None, False
    else:
        new_file = False
    if not process("file_meta", oid, opts_meta, force=True):
        logger.error("Not able to process file metadata %s",file_location)
        return None, False

    logger.debug("%s file import complete.", file_location)
    return oid, new_file
Ejemplo n.º 2
0
    def import_file(self, file_location):
        """ Process the file locally - only transmit if it does not exist remotely
            1. Get the oid and metadata
            2. Check if the file exist remotely: 
               a. If the file does not exist remotely - transmit the file
               b. If the file does exist remotely - don't transmit the file
        """
        new_file = False
        fd = sys_utils.import_file(file_location, config.file_max)
        if not fd:
            return None, False
        oid = loc_oxide.get_oid_from_data(fd["data"])
        if not oid:
            logger.error("Not able to get and oid for %s", file_location)
            return None, False 
        
        opts_file = { "file_contents":fd["data"]}   
        opts_meta = { "file_location":file_location, "stat":fd["file_stat"]}   
        
        if not self.oxide.exists("files", oid, {}):
            new_file = True
            if not self.oxide.process("files", oid, opts_file):
                logger.error("Not able to process file data %s",file_location)
                return None, False
        
        if not self.oxide.process("file_meta", oid, opts_meta, True):
            logger.error("Not able to process file metadata %s",file_location)
            return None, False

        logger.debug("%s file import complete.", file_location)
        return oid, new_file