def web_getPlotImgFromCache(self): """ Get plot image from cache. """ callback = {} if 'file' not in self.request.arguments: callback = { "success": "false", "error": "Maybe you forgot the file?" } self.finish(callback) return plotImageFile = str(self.request.arguments['file'][0]) retVal = extractRequestFromFileId(plotImageFile) if not retVal['OK']: callback = {"success": "false", "error": retVal['Value']} self.finish(callback) return fields = retVal['Value'] if "extraArgs" in fields: # in order to get the plot from the cache we have to clean the extraArgs... plotTitle = "" if 'plotTitle' in fields["extraArgs"]: plotTitle = fields["extraArgs"]["plotTitle"] fields["extraArgs"] = {} fields["extraArgs"]["plotTitle"] = plotTitle else: fields["extraArgs"] = {} retVal = codeRequestInFileId(fields) if not retVal['OK']: callback = {"success": "false", "error": retVal['Value']} self.finish(callback) return plotImageFile = retVal['Value']['plot'] transferClient = TransferClient("Accounting/ReportGenerator") tempFile = tempfile.TemporaryFile() retVal = yield self.threadTask(transferClient.receiveFile, tempFile, plotImageFile) if not retVal['OK']: callback = {"success": "false", "error": retVal['Message']} self.finish(callback) return tempFile.seek(0) data = tempFile.read() self.set_header('Content-type', 'image/png') self.set_header( 'Content-Disposition', 'attachment; filename="%s.png"' % md5(plotImageFile).hexdigest()) self.set_header('Content-Length', len(data)) self.set_header('Content-Transfer-Encoding', 'Binary') self.set_header('Cache-Control', "no-cache, no-store, must-revalidate, max-age=0") self.set_header('Pragma', "no-cache") self.set_header('Expires', ( datetime.datetime.utcnow() - datetime.timedelta(minutes=-10)).strftime("%d %b %Y %H:%M:%S GMT")) self.finish(data)
def __generatePlotFromFileId( self, fileId ): result = extractRequestFromFileId( fileId ) if not result[ 'OK' ]: return result plotRequest = result[ 'Value' ] gLogger.info( "Generating the plots.." ) result = self.export_generatePlot( plotRequest ) if not result[ 'OK' ]: gLogger.error( "Error while generating the plots", result[ 'Message' ] ) return result fileToReturn = 'plot' if 'extraArgs' in plotRequest: extraArgs = plotRequest[ 'extraArgs' ] if 'thumbnail' in extraArgs and extraArgs[ 'thumbnail' ]: fileToReturn = 'thumbnail' gLogger.info( "Returning %s file: %s " % ( fileToReturn, result[ 'Value' ][ fileToReturn ] ) ) return S_OK( result[ 'Value' ][ fileToReturn ] )
def __generatePlotFromFileId(self, fileId): result = extractRequestFromFileId(fileId) if not result["OK"]: return result plotRequest = result["Value"] gLogger.info("Generating the plots..") result = self.export_generatePlot(plotRequest) if not result["OK"]: gLogger.error("Error while generating the plots", result["Message"]) return result fileToReturn = "plot" if "extraArgs" in plotRequest: extraArgs = plotRequest["extraArgs"] if "thumbnail" in extraArgs and extraArgs["thumbnail"]: fileToReturn = "thumbnail" gLogger.info("Returning %s file: %s " % (fileToReturn, result["Value"][fileToReturn])) return S_OK(result["Value"][fileToReturn])
Script.setUsageMessage( "\n".join( [ __doc__.split("\n")[1], "Usage:", " %s [option|cfgfile] ... URL ..." % Script.scriptName, "Arguments:", " URL: encoded URL of a DIRAC Accounting plot", ] ) ) Script.parseCommandLine() fileIds = Script.getPositionalArgs() for fileId in fileIds: # Try to find if it's a url parseRes = urlparse.urlparse(fileId) if parseRes.query: queryRes = cgi.parse_qs(parseRes.query) if "file" in queryRes: fileId = queryRes["file"][0] # Decode result = extractRequestFromFileId(fileId) if not result["OK"]: gLogger.error("Could not decode fileId", "'%s', error was %s" % (fileId, result["Message"])) sys.exit(1) gLogger.notice("Decode for '%s' is:\n%s" % (fileId, pprint.pformat(result["Value"]))) sys.exit(0)
from DIRAC import gLogger from DIRAC.Core.Base import Script from DIRAC.AccountingSystem.private.FileCoding import extractRequestFromFileId Script.setUsageMessage('\n'.join([ __doc__.split('\n')[1], 'Usage:', ' %s [option|cfgfile] ... URL ...' % Script.scriptName, 'Arguments:', ' URL: encoded URL of a DIRAC Accounting plot' ])) Script.parseCommandLine() fileIds = Script.getPositionalArgs() for fileId in fileIds: #Try to find if it's a url parseRes = urlparse.urlparse(fileId) if parseRes.query: queryRes = cgi.parse_qs(parseRes.query) if 'file' in queryRes: fileId = queryRes['file'][0] #Decode result = extractRequestFromFileId(fileId) if not result['OK']: gLogger.error("Could not decode fileId", "'%s', error was %s" % (fileId, result['Message'])) sys.exit(1) gLogger.notice("Decode for '%s' is:\n%s" % (fileId, pprint.pformat(result['Value']))) sys.exit(0)