本文整理汇总了Python中DIRAC.Core.DISET.private.FileHelper.FileHelper.setDirection方法的典型用法代码示例。如果您正苦于以下问题:Python FileHelper.setDirection方法的具体用法?Python FileHelper.setDirection怎么用?Python FileHelper.setDirection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DIRAC.Core.DISET.private.FileHelper.FileHelper
的用法示例。
在下文中一共展示了FileHelper.setDirection方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getDataFromService
# 需要导入模块: from DIRAC.Core.DISET.private.FileHelper import FileHelper [as 别名]
# 或者: from DIRAC.Core.DISET.private.FileHelper.FileHelper import setDirection [as 别名]
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 } )
示例2: __doFileTransfer
# 需要导入模块: from DIRAC.Core.DISET.private.FileHelper import FileHelper [as 别名]
# 或者: from DIRAC.Core.DISET.private.FileHelper.FileHelper import setDirection [as 别名]
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"]:
raise RequestHandler.ConnectionError(
"Error while receiving file description %s %s"
% (self.srv_getFormattedRemoteCredentials(), 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)))
示例3: sendDataToService
# 需要导入模块: from DIRAC.Core.DISET.private.FileHelper import FileHelper [as 别名]
# 或者: from DIRAC.Core.DISET.private.FileHelper.FileHelper import setDirection [as 别名]
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
示例4: __forwardFileTransferCall
# 需要导入模块: from DIRAC.Core.DISET.private.FileHelper import FileHelper [as 别名]
# 或者: from DIRAC.Core.DISET.private.FileHelper.FileHelper import setDirection [as 别名]
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