Ejemplo n.º 1
0
    def __generatePlotFromFileId(self, fileId):
        """
    It create the plots using the encode parameters

    :param str fileId: the encoded plot attributes
    :return S_OK or S_ERROR returns the file name
    """

        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])
Ejemplo n.º 2
0
    def _generatePlotFromFileId(self, fileId):
        """
        It create the plots using the encode parameters

        :param str fileId: the encoded plot attributes
        :return S_OK or S_ERROR returns the file name
        """

        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])
Ejemplo n.º 3
0
    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("Monitoring/Monitoring")
        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)
Ejemplo n.º 4
0
  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)
Ejemplo n.º 5
0
 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])
Ejemplo n.º 6
0
 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 ] )
Ejemplo n.º 7
0
 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])
Ejemplo n.º 8
0
  def __generatePlotFromFileId( self, fileId ):
    """
    It create the plots using the encode parameters
    :param str fileId the encoded plot attributes
    :return S_OK or S_ERROR returns the file name
    """

    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 main():
    from DIRAC.Core.Utilities.Plotting.FileCoding import extractRequestFromFileId
    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 = 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)
def main():
    from DIRAC.Core.Utilities.Plotting.FileCoding import extractRequestFromFileId

    Script.registerArgument(["URL: encoded URL of a DIRAC Accounting plot"])

    _, fileIds = Script.parseCommandLine()

    for fileId in fileIds:
        # Try to find if it's a url
        parseRes = parse.urlparse(fileId)
        if parseRes.query:
            queryRes = parse.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)
Ejemplo n.º 11
0
from DIRAC import gLogger
from DIRAC.Core.Base import Script
from DIRAC.Core.Utilities.Plotting.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)
Ejemplo n.º 12
0
import urlparse
import cgi
from DIRAC import gLogger
from DIRAC.Core.Base import Script
from DIRAC.Core.Utilities.Plotting.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 )