mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
added send-by-file
This commit is contained in:
parent
5528735c9b
commit
8242b1c4b7
@ -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):
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user