def ngamsEsoArchDppi(srvObj, reqPropsObj, filename): """ This DPPI performs the processing neccessary for the files requested from the ESO Archive (by the Data Requestor). srvObj: Reference to instance of the NG/AMS Server class (ngamsServer). reqPropsObj: NG/AMS request properties object (ngamsReqProps). filename: Name of file to process (string). Returns: DPPI return status object (ngamsDppiStatus). """ statusObj = ngamsDppiStatus.ngamsDppiStatus() # Decompress the file if the last extension is "Z". if (filename.split(".")[-1] == "Z"): procFilename, procDir = ngamsPlugInApi.prepProcFile(srvObj.getCfg(), filename) exitCode, stdOut, stdErr = ngamsPlugInApi.\ execCmd("uncompress " + procFilename) if (exitCode != 0): errMsg = "ngamsEsoArchDppi: Problems during archiving! " +\ "Decompressing the file: " + filename + " failed. " +\ "Error message: " + str(stdErr) raise Exception(errMsg) resFilename = procFilename[0:-2] else: resFilename = filename procDir = "" mimeType = ngamsPlugInApi.determineMimeType(srvObj.getCfg(), resFilename) resObj = ngamsDppiStatus.ngamsDppiResult(NGAMS_PROC_FILE, mimeType, resFilename, resFilename, procDir) statusObj.addResult(resObj) return statusObj
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)
def ngamsTestDppi1(srvObj, reqPropsObj, filename): """ This test DPPI extracts the main header from a FITS file requested from the ESO Archive. Depending on the the DPPI Plug-In Parameters it stores the result in a file or in a buffer in memory. This is made to work on small FITS files. srvObj: Reference to instance of the NG/AMS Server class (ngamsServer). reqPropsObj: NG/AMS request properties object (ngamsReqProps). filename: Name of file to process (string). Returns: DPPI return status object (ngamsDppiStatus). """ statusObj = ngamsDppiStatus.ngamsDppiStatus() # Uncompress the file. procFile, procDir = ngamsPlugInApi.prepProcFile(srvObj.getCfg(), filename) subprocess.check_call(['gunzip', procFile]) procFile = procFile[0:procFile.rfind(".")] # dpallot: fold fails miserably on Mac when dealing with binary files # # Process the output file. #stat, out = commands.getstatusoutput("fold %s" % procFile) #if stat: # raise Exception('Problem while folding %s: %s' % (procFile, out)) head = [] with open(procFile, 'rb') as f: while True: line = f.read(80) assert (line and len(line) == 80) head.append(line) head.append(b'\n') if b'END' in line: break mimeType = "TEST-MIME-TYPE" rawPiPars = srvObj.getCfg().dppi_plugins["ngamsTest.ngamsTestDppi1"].pars cfgParDic = ngamsPlugInApi.parseRawPlugInPars(rawPiPars) head.append(b"\n\nConfiguration Parameters:\n") parList = list(cfgParDic) parList.sort() for par in parList: head.append(six.b("%s=%s\n" % (par, cfgParDic[par]))) head.append(b"\nParameters Transferred:\n") httpParsDic = reqPropsObj.getHttpParsDic() httpPars = list(httpParsDic) httpPars.sort() for httpPar in httpPars: head.append(six.b("%s=%s\n" % (httpPar, httpParsDic[httpPar]))) head.append(b"\nEOF\n") buf = b''.join(head) # Generate status. if (cfgParDic["TARGET"] == "FILE"): outFile = procFile + "_ngamsTestDppi1" with open(outFile, "ab") as fo: fo.write(buf) resObj = ngamsDppiStatus.ngamsDppiResult(NGAMS_PROC_FILE, mimeType, outFile, filename, procDir) else: resObj = ngamsDppiStatus.ngamsDppiResult(NGAMS_PROC_DATA, mimeType, buf, filename) statusObj.addResult(resObj) return statusObj