示例#1
0
def ngamsRegisterGenericPlugIn(server_object, request_object, param_dict):
    """
    Generic registration plug-in to handle registration of files

    :param server_object: Reference to NG/AMS Server Object (ngamsServer)
    :param request_object: NG/AMS request properties object (ngamsReqProps)
    :param param_dict: Parameter dictionary
    :return: Standard NG/AMS Data Archiving Plug-In Status as generated by  ngamsPlugInApi.genDapiSuccessStat()
    (ngamsDapiStatus)
    """
    logger.info("Register generic plug-in registering file with URI: %s", request_object.getFileUri())
    disk_info = request_object.getTargDiskInfo()
    mime_type = request_object.getMimeType()
    stage_file = request_object.getStagingFilename()
    file_id = os.path.basename(request_object.getFileUri())

    if mime_type == ngamsCore.NGAMS_UNKNOWN_MT:
        error_message = ngamsCore.genLog("NGAMS_ER_UNKNOWN_MIME_TYPE1", [file_id])
        raise Exception(error_message)

    file_size = ngamsPlugInApi.getFileSize(stage_file)
    compression = ""
    uncompressed_size = file_size

    # Get various information about the file being handled
    file_version, relative_path, relative_filename, complete_filename, file_exists = \
        ngamsPlugInApi.genFileInfoReg(server_object.getDb(), server_object.getCfg(), request_object, disk_info,
                                      stage_file, file_id)

    logger.info("Register generic plug-in finished processing file with URI %s: file_id=%s, file_version=%s, format=%s, file_size=%s",
                request_object.getFileUri(), file_id, file_version, mime_type, file_size)

    return ngamsPlugInApi.genRegPiSuccessStat(disk_info.getDiskId(), relative_filename, file_id, file_version,
                                              mime_type, file_size, uncompressed_size, compression, relative_path,
                                              disk_info.getSlotId(), file_exists, complete_filename)
def generic_register_plugin(srv, req, _params):
    '''A simple, generic register plug-in entry point used by one of our tests'''
    diskInfo = req.getTargDiskInfo()
    stageFile = req.getStagingFilename()
    mime_type = req.getMimeType()
    file_id = os.path.basename(req.getFileUri())
    compresion = ""
    fileVersion, relPath, relFilename, complFilename, fileExists = \
        ngamsPlugInApi.genFileInfoReg(srv.db, srv.cfg, req, diskInfo,
                                      stageFile, file_id)
    uncomprSize = ngamsPlugInApi.getFileSize(stageFile)
    return ngamsPlugInApi.genRegPiSuccessStat(
        diskInfo.getDiskId(), relFilename, file_id, fileVersion,
        mime_type, uncomprSize, uncomprSize, compresion, relPath,
        diskInfo.getSlotId(), fileExists, complFilename)
示例#3
0
def ngamsFitsRegPlugIn(srvObj, reqPropsObj, parDic):
    """
    Data Registration Plug-In to handle registration of FITS files.

    srvObj:       Reference to NG/AMS Server Object (ngamsServer).

    reqPropsObj:  NG/AMS request properties object (ngamsReqProps).

    Returns:      Standard NG/AMS Data Archiving Plug-In Status as generated
                  by: ngamsPlugInApi.genDapiSuccessStat() (ngamsDapiStatus).
    """
    logger.info("Plug-In registering file with URI: %s", reqPropsObj.getFileUri())
    diskInfo = reqPropsObj.getTargDiskInfo()
    stageFile = reqPropsObj.getStagingFilename()

    # If the file is already compressed, we have to decompress it.
    procDir = ""
    if ((stageFile.find(".Z") != -1) or (stageFile.find(".gz") != -1)):
        workingFile, procDir = ngamsPlugInApi.prepProcFile(srvObj.getCfg(),
                                                           stageFile)
        ngamsPlugInApi.execCmd("gunzip " + workingFile)
        if (workingFile.find(".Z") != -1):
            workingFile = workingFile[:-2]
        else:
            workingFile = workingFile[:-3]
    else:
        workingFile = stageFile

    # Check file (size + checksum).
    ngamsFitsPlugIn.checkFitsFileSize(workingFile)
    #ngamsFitsPlugIn.c_heckChecksum(parDic, workingFile)
    if 'skip_checksum' not in parDic:
        ngamsFitsPlugIn.checkFitsChecksum(reqPropsObj, workingFile)

    # Get various information about the file being handled.
    arcFile, dpId, dateDirName = ngamsFitsPlugIn.getDpIdInfo(workingFile)
    fileVersion, relPath, relFilename,\
                 complFilename, fileExists =\
                 ngamsPlugInApi.genFileInfoReg(srvObj.getDb(), srvObj.getCfg(),
                                               reqPropsObj, diskInfo,
                                               stageFile, dpId)

    # Generate status.
    logger.debug("Generating status ...")
    fileSize = ngamsPlugInApi.getFileSize(stageFile)
    if (stageFile.find(".Z") != -1):
        format = "application/x-cfits"
        compresion = "compress"
    elif (stageFile.find(".gz") != -1):
        format = "application/x-gfits"
        compresion = "gzip"
    else:
        format = "image/x-fits"
        compresion = ""
    uncomprSize = ngamsPlugInApi.getFileSize(workingFile)

    # Delete the processing directory (would be done later by the
    # Janitor Thread, but it is better to clean up explicitly).
    if (procDir): rmFile(procDir)

    logger.debug("Register Plug-In finished processing of file")
    return ngamsPlugInApi.genRegPiSuccessStat(diskInfo.getDiskId(),relFilename,
                                              dpId, fileVersion, format,
                                              fileSize, uncomprSize,compresion,
                                              relPath, diskInfo.getSlotId(),
                                              fileExists, complFilename)