当前位置: 首页>>代码示例>>Python>>正文


Python FileHelper.FileHelper类代码示例

本文整理汇总了Python中DIRAC.Core.DISET.private.FileHelper.FileHelper的典型用法代码示例。如果您正苦于以下问题:Python FileHelper类的具体用法?Python FileHelper怎么用?Python FileHelper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FileHelper类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: receiveFile

  def receiveFile( self, filename, fileId, token = "" ):
    """
    Receive a file from the server

    @type filename : string / file descriptor / file object
    @param filename : File to receive from server
    @type fileId : any
    @param fileId : Identification of the file being received
    @type token : string
    @param token : Optional token for the file
    @return : S_OK/S_ERROR
    """
    fileHelper = FileHelper()
    retVal = fileHelper.getDataSink( filename )
    if not retVal[ 'OK' ]:
      return retVal
    dS = retVal[ 'Value' ]
    closeAfterUse = retVal[ 'closeAfterUse' ]
    retVal = self._sendTransferHeader( "ToClient", ( fileId, token ) )
    if not retVal[ 'OK' ]:
      return retVal
    trid, transport = retVal[ 'Value' ]
    try:
      fileHelper.setTransport( transport )
      retVal = fileHelper.networkToDataSink( dS )
      if not retVal[ 'OK' ]:
        return retVal
      retVal = transport.receiveData()
      if closeAfterUse:
        dS.close()
      return retVal
    finally:
      self._disconnect( trid )
开发者ID:bmb,项目名称:DIRAC,代码行数:33,代码来源:TransferClient.py

示例2: getDataFromService

 def getDataFromService( self, srvMethod, params ):
   self.infoMsg( "Sending header request to %s" % self.getDestinationService(), str( params ) )
   result = self._sendTransferHeader( srvMethod, params )
   if not result[ 'OK' ]:
     self.errMsg( "Could not send header", result[ 'Message' ] )
     return result
   self.infoMsg( "Starting to receive data from service" )
   srvTransport = result[ 'Value' ]
   srvFileHelper = FileHelper( srvTransport )
   srvFileHelper.setDirection( "receive" )
   sIO = cStringIO.StringIO()
   result = srvFileHelper.networkToDataSink( sIO, self.__transferBytesLimit )
   if not result[ 'OK' ]:
     self.errMsg( "Could receive data from server", result[ 'Message' ] )
     srvTransport.close()
     sIO.close()
     return result
   dataReceived = sIO.getvalue()
   sIO.close()
   self.infoMsg( "Received %s bytes from service" % len( dataReceived ) )
   retVal = srvTransport.receiveData()
   srvTransport.close()
   if not retVal[ 'OK' ]:
     return retVal
   return S_OK( { 'data' : dataReceived, 'srvResponse' : retVal } )
开发者ID:KrzysztofCiba,项目名称:DIRAC,代码行数:25,代码来源:GatewayService.py

示例3: sendFile

  def sendFile( self, filename, fileId, token = "" ):
    """
    Send a file to server

    @type filename : string / file descriptor / file object
    @param filename : File to send to server
    @type fileId : any
    @param fileId : Identification of the file being sent
    @type token : string
    @param token : Optional token for the file
    @return : S_OK/S_ERROR
    """
    fileHelper = FileHelper()
    retVal = fileHelper.getFileDescriptor( filename, "r" )
    if not retVal[ 'OK' ]:
      return retVal
    fd = retVal[ 'Value' ]
    retVal = self._sendTransferHeader( "FromClient", ( fileId, token, File.getSize( filename ) ) )
    if not retVal[ 'OK' ]:
      return retVal
    trid, transport = retVal[ 'Value' ]
    try:
      fileHelper.setTransport( transport )
      retVal = fileHelper.FDToNetwork( fd )
      if not retVal[ 'OK' ]:
        return retVal
      retVal = transport.receiveData()
      return retVal
    finally:
      self._disconnect( trid )
开发者ID:bmb,项目名称:DIRAC,代码行数:30,代码来源:TransferClient.py

示例4: receiveBulk

  def receiveBulk( self, destDir, bulkId, token = "", compress = True ):
    """
    Receive a bulk of files from server

    @type destDir : list of ( string / file descriptor / file object )
    @param destDir : Files to receive from server
    @type bulkId : any
    @param bulkId : Identification of the files being received
    @type token : string
    @param token : Token for the bulk
    @type compress : boolean
    @param compress : Enable compression for the bulk. By default its True
    @return : S_OK/S_ERROR
    """
    if not os.path.isdir( destDir ):
      return S_ERROR( "%s is not a directory for bulk receival" % destDir )
    if compress:
      bulkId = "%s.tar.bz2" % bulkId
    else:
      bulkId = "%s.tar" % bulkId
    retVal = self._sendTransferHeader( "BulkToClient", ( bulkId, token ) )
    if not retVal[ 'OK' ]:
      return retVal
    trid, transport = retVal[ 'Value' ]
    try:
      fileHelper = FileHelper( transport )
      retVal = fileHelper.networkToBulk( destDir, compress )
      if not retVal[ 'OK' ]:
        return retVal
      retVal = transport.receiveData()
      return retVal
    finally:
开发者ID:bmb,项目名称:DIRAC,代码行数:32,代码来源:TransferClient.py

示例5: sendBulk

  def sendBulk( self, fileList, bulkId, token = "", compress = True, bulkSize = -1, onthefly = True ):
    """
    Send a bulk of files to server

    @type fileList : list of ( string / file descriptor / file object )
    @param fileList : Files to send to server
    @type bulkId : any
    @param bulkId : Identification of the files being sent
    @type token : string
    @param token : Token for the bulk
    @type compress : boolean
    @param compress : Enable compression for the bulk. By default its True
    @type bulkSize : integer
    @param bulkSize : Optional size of the bulk
    @return : S_OK/S_ERROR
    """
    bogusEntries = self.__checkFileList( fileList )
    if bogusEntries:
      return S_ERROR( "Some files or directories don't exist :\n\t%s" % "\n\t".join( bogusEntries ) )
    if compress:
      bulkId = "%s.tar.bz2" % bulkId
    else:
      bulkId = "%s.tar" % bulkId
    retVal = self._sendTransferHeader( "BulkFromClient", ( bulkId, token, bulkSize ) )
    if not retVal[ 'OK' ]:
      return retVal
    trid, transport = retVal[ 'Value' ]
    try:
      fileHelper = FileHelper( transport )
      retVal = fileHelper.bulkToNetwork( fileList, compress, onthefly )
      if not retVal[ 'OK' ]:
        return retVal
      retVal = transport.receiveData()
      return retVal
    finally:
开发者ID:bmb,项目名称:DIRAC,代码行数:35,代码来源:TransferClient.py

示例6: sendDataToService

 def sendDataToService( self, srvMethod, params, data ):
   self.infoMsg( "Sending header request to %s" % self.getDestinationService(), str( params ) )
   result = self._sendTransferHeader( srvMethod, params )
   if not result[ 'OK' ]:
     self.errMsg( "Could not send header", result[ 'Message' ] )
     return result
   self.infoMsg( "Starting to send data to service" )
   srvTransport = result[ 'Value' ]
   srvFileHelper = FileHelper( srvTransport )
   srvFileHelper.setDirection( "send" )
   result = srvFileHelper.BufferToNetwork( data )
   if not result[ 'OK' ]:
     self.errMsg( "Could send data to server", result[ 'Message' ] )
     srvTransport.close()
     return result
   self.infoMsg( "Data sent to service (%s bytes)" % len( data ) )
   retVal = srvTransport.receiveData()
   srvTransport.close()
   return retVal
开发者ID:KrzysztofCiba,项目名称:DIRAC,代码行数:19,代码来源:GatewayService.py

示例7: __forwardFileTransferCall

 def __forwardFileTransferCall(self, targetService, clientInitArgs, method, params, clientTransport):
     transferRelay = TransferRelay(targetService, **clientInitArgs)
     transferRelay.setTransferLimit(self.__transferBytesLimit)
     cliFH = FileHelper(clientTransport)
     # Check file size
     if method.find("ToClient") > -1:
         cliFH.setDirection("send")
     elif method.find("FromClient") > -1:
         cliFH.setDirection("receive")
         if not self.__ftCheckMaxTransferSize(params[2]):
             cliFH.markAsTransferred()
             return S_ERROR("Transfer size is too big")
     # Forward queries
     try:
         relayMethodObject = getattr(transferRelay, "forward%s" % method)
     except:
         return S_ERROR("Cannot forward unknown method %s" % method)
     result = relayMethodObject(cliFH, params)
     return result
开发者ID:kfox1111,项目名称:DIRAC,代码行数:19,代码来源:GatewayService.py

示例8: __doFileTransfer

  def __doFileTransfer( self, sDirection ):
    """
    Execute a file transfer action

    @type sDirection: string
    @param sDirection: Direction of the transfer
    @return: S_OK/S_ERROR
    """
    retVal = self.__trPool.receive( self.__trid )
    if not retVal[ 'OK' ]:
      gLogger.error( "Error while receiving file description", "%s %s" % ( self.srv_getFormattedRemoteCredentials(),
                                                             retVal[ 'Message' ] ) )
      return S_ERROR( "Error while receiving file description: %s" % retVal[ 'Message' ] )
    fileInfo = retVal[ 'Value' ]
    sDirection = "%s%s" % ( sDirection[0].lower(), sDirection[1:] )
    if "transfer_%s" % sDirection not in dir( self ):
      self.__trPool.send( self.__trid, S_ERROR( "Service can't transfer files %s" % sDirection ) )
      return
    retVal = self.__trPool.send( self.__trid, S_OK( "Accepted" ) )
    if not retVal[ 'OK' ]:
      return retVal
    self.__logRemoteQuery( "FileTransfer/%s" % sDirection, fileInfo )

    self.__lockManager.lock( sDirection )
    try:
      try:
        fileHelper = FileHelper( self.__trPool.get( self.__trid ) )
        if sDirection == "fromClient":
          fileHelper.setDirection( "fromClient" )
          uRetVal = self.transfer_fromClient( fileInfo[0], fileInfo[1], fileInfo[2], fileHelper )
        elif sDirection == "toClient" :
          fileHelper.setDirection( "toClient" )
          uRetVal = self.transfer_toClient( fileInfo[0], fileInfo[1], fileHelper )
        elif sDirection == "bulkFromClient" :
          fileHelper.setDirection( "fromClient" )
          uRetVal = self.transfer_bulkFromClient( fileInfo[0], fileInfo[1], fileInfo[2], fileHelper )
        elif sDirection == "bulkToClient" :
          fileHelper.setDirection( "toClient" )
          uRetVal = self.transfer_bulkToClient( fileInfo[0], fileInfo[1], fileHelper )
        elif sDirection == "listBulk":
          fileHelper.setDirection( "toClient" )
          uRetVal = self.transfer_listBulk( fileInfo[0], fileInfo[1], fileHelper )
        else:
          return S_ERROR( "Direction %s does not exist!!!" % sDirection )
        if uRetVal[ 'OK' ] and not fileHelper.finishedTransmission():
          gLogger.error( "You haven't finished receiving/sending the file", str( fileInfo ) )
          return S_ERROR( "Incomplete transfer" )
        return uRetVal
      finally:
        self.__lockManager.unlock( sDirection )

    except Exception, v:
      gLogger.exception( "Uncaught exception when serving Transfer", "%s" % sDirection )
      return S_ERROR( "Server error while serving %s: %s" % ( sDirection, str( v ) ) )
开发者ID:KrzysztofCiba,项目名称:DIRAC,代码行数:54,代码来源:RequestHandler.py


注:本文中的DIRAC.Core.DISET.private.FileHelper.FileHelper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。