Skip to content

Instantly share code, notes, and snippets.

@abutcher
Created July 16, 2012 22:56
Show Gist options
  • Select an option

  • Save abutcher/3125602 to your computer and use it in GitHub Desktop.

Select an option

Save abutcher/3125602 to your computer and use it in GitHub Desktop.
def __upload(self, path, offset, uuid, bufsize):
f = open(path)
f.seek(offset)
while(1):
buf = f.read(bufsize)
if buf:
self.__append(uuid, Bytes(buf))
else:
break
f.close()
return self
def __append(self, id, buf):
delay = self.DELAY
retries = self.RETRIES
while True:
try:
path = '/services/upload/append/%s/' % id
return self.server.PUT(path, buf)[1]
except (SocketError, SSLError), ex:
msg = 'upload (%s) append failed:%s [wait:%d, retries:%d]'
log.warn(msg, id, ex, delay, retries)
if retries:
sleep(delay)
delay = (delay+self.DELAY_INCREMENT)
retries = (retries-1)
else:
raise ex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment