예제 #1
0
def getDpIdInfo(filename):
    """
    Generate the File ID (here DP ID) for the file.

    filename:   Name of FITS file (string).

    Returns:    Tuple containing the value of ARCFILE, the DP ID
                of the file, and the JD date. The two latter deducted from
                the ARCFILE keyword (tuple).
    """
    try:
        keyDic = getFitsKeys(filename, ["ARCFILE"])
        arcFile = keyDic["ARCFILE"][0]
        els = arcFile.split(".")
        dpId = els[0] + "." + els[1] + "." + els[2]
        date = els[1].split("T")[0]
        # Make sure that the files are stored according to JD
        # (one night is 12am -> 12am).
        isoTime = '.'.join(els[1:])
        ts1 = fromiso8601(isoTime)
        ts2 = tomjd(ts1) - 0.5
        dateDirName = toiso8601(frommjd(ts2), fmt=FMT_DATE_ONLY)

        return [arcFile, dpId, dateDirName]
    except:
        err = "Did not find keyword ARCFILE in FITS file or ARCFILE illegal"
        errMsg = genLog("NGAMS_ER_DAPI_BAD_FILE",
                        [os.path.basename(filename), "ngamsFitsPlugIn", err])
        logger.exception(errMsg)
        raise
예제 #2
0
def ngasTarBallPlugIn(srvObj, reqPropsObj):
    """
    Data Archiving Plug-In to handle archiving of tarballs.

    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).
    """
    stagingFilename = reqPropsObj.getStagingFilename()
    logger.info("Plug-In handling data for file with URI: %s",
                os.path.basename(reqPropsObj.getFileUri()))
    diskInfo = reqPropsObj.getTargDiskInfo()

    # Check file.
    checkTarball(stagingFilename)

    # Get various information about the file being handled.
    fileId = os.path.basename(reqPropsObj.getFileUri())
    timestamp = fileId[fileId.find(".") + 1:]
    obsDay = tomjd(fromiso8601(timestamp)) - 0.5
    dateDirName = toiso8601(obsDay, fmt=FMT_DATE_ONLY)
    baseFilename = fileId[0:-4]
    fileVersion, relPath, relFilename,\
                 complFilename, fileExists =\
                 ngamsPlugInApi.genFileInfo(srvObj.getDb(), srvObj.getCfg(),
                                            reqPropsObj, diskInfo,
                                            stagingFilename, fileId,
                                            baseFilename, [dateDirName], [])

    # Generate status.
    logger.debug("Generating status ...")
    format = "application/x-tar"
    fileSize = ngamsPlugInApi.getFileSize(stagingFilename)
    logger.debug("DAPI finished processing of file")
    return ngamsPlugInApi.genDapiSuccessStat(diskInfo.getDiskId(), relFilename,
                                             fileId, fileVersion, format,
                                             fileSize, fileSize,
                                             "NONE", relPath,
                                             diskInfo.getSlotId(), fileExists,
                                             complFilename)