fix resume after ctrl-c
This commit is contained in:
parent
8d6cdeee19
commit
857a30db35
1 changed files with 4 additions and 6 deletions
|
@ -586,10 +586,8 @@ class API(ox.API):
|
||||||
done = 0
|
done = 0
|
||||||
start = time.mktime(time.localtime())
|
start = time.mktime(time.localtime())
|
||||||
if 'offset' in data and data['offset'] < fsize:
|
if 'offset' in data and data['offset'] < fsize:
|
||||||
while done < data['offset']:
|
done = data['offset']
|
||||||
chunk = f.read(CHUNK_SIZE)
|
f.seek(done)
|
||||||
done += len(chunk)
|
|
||||||
else:
|
|
||||||
chunk = f.read(CHUNK_SIZE)
|
chunk = f.read(CHUNK_SIZE)
|
||||||
fname = os.path.basename(filename)
|
fname = os.path.basename(filename)
|
||||||
if isinstance(fname, unicode):
|
if isinstance(fname, unicode):
|
||||||
|
@ -634,13 +632,13 @@ class API(ox.API):
|
||||||
print data
|
print data
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
if data and data.get('result') == 1:
|
if data and data.get('result') == 1:
|
||||||
|
done += len(chunk)
|
||||||
with open(self._resume_file, 'w') as r:
|
with open(self._resume_file, 'w') as r:
|
||||||
json.dump({
|
json.dump({
|
||||||
'uploadUrl': uploadUrl,
|
'uploadUrl': uploadUrl,
|
||||||
'url': url,
|
'url': url,
|
||||||
'offset': done
|
'offset': done
|
||||||
}, r, indent=2)
|
}, r, indent=2)
|
||||||
done += len(chunk)
|
|
||||||
chunk = f.read(CHUNK_SIZE)
|
chunk = f.read(CHUNK_SIZE)
|
||||||
if os.path.exists(self._resume_file):
|
if os.path.exists(self._resume_file):
|
||||||
os.unlink(self._resume_file)
|
os.unlink(self._resume_file)
|
||||||
|
|
Loading…
Reference in a new issue