added send-by-file

This commit is contained in:
Darren Ranalli 2003-10-04 01:39:45 +00:00
parent 5528735c9b
commit 8242b1c4b7
3 changed files with 53 additions and 7 deletions

View File

@ -45,11 +45,23 @@ class DistributedLargeBlobSender(DistributedObject.DistributedObject):
self.privOnBlobComplete()
def setFilename(self, filename):
DistributedLargeBlobSender.notify.debug('setFilename')
DistributedLargeBlobSender.notify.debug('setFilename: %s' % filename)
assert self.useDisk
self.blob = ''
DistributedLargeBlobSender.notify.error(
'large blob transfer by file not yet implemented')
import os
origDir = os.getcwd()
bPath = LargeBlobSenderConsts.getLargeBlobPath()
try:
os.chdir(bPath)
except OSError:
DistributedLargeBlobSender.notify.error(
'could not access %s' % bPath)
f = file(filename, 'rb')
self.blob = f.read()
f.close()
os.unlink(filename)
os.chdir(origDir)
self.privOnBlobComplete()
def isComplete(self):

View File

@ -20,11 +20,35 @@ class DistributedLargeBlobSenderAI(DistributedObjectAI.DistributedObjectAI):
self.generateWithRequired(zoneId)
# send the data
s = str(data)
if useDisk:
DistributedLargeBlobSenderAI.notify.error(
'large blob transfer by file not yet implemented')
# write the data to a file and tell the client where to get it
import os
import random
origDir = os.getcwd()
bPath = LargeBlobSenderConsts.getLargeBlobPath()
try:
os.chdir(bPath)
except OSError:
DistributedLargeBlobSenderAI.notify.error(
'could not access %s' % bPath)
# find an unused temp filename
while 1:
num = random.randrange((1 << 30)-1)
filename = LargeBlobSenderConsts.FilePattern % num
try:
os.stat(filename)
except OSError:
break
# NOTE: there's a small chance of a race condition here, if
# the file is created by another AI just after the stat fails
f = file(filename, 'wb')
f.write(s)
f.close()
os.chdir(origDir)
self.sendUpdateToAvatarId(self.targetAvId,
'setFilename', [filename])
else:
s = str(data)
chunkSize = LargeBlobSenderConsts.ChunkSize
while len(s):
self.sendUpdateToAvatarId(self.targetAvId,

View File

@ -3,3 +3,13 @@
USE_DISK = 0x01
ChunkSize = 100
FilePattern = 'largeBlob.%s'
def getLargeBlobPath():
path = config.GetString('large-blob-path', '')
if len(path) == 0:
assert 0, (
'you must config large-blob-path to beta/largeblob, i.e.\n'
'large-blob-path i:\\beta\\largeblob')
return path