don't print status during upload
This commit is contained in:
parent
2ebc6ffd3a
commit
f7c7a6689b
1 changed files with 11 additions and 6 deletions
|
@ -151,7 +151,7 @@ class API(object):
|
|||
fd.write(chunk)
|
||||
shutil.move(tmpname, filename)
|
||||
|
||||
def upload_chunks(self, url, filename, data=None):
|
||||
def upload_chunks(self, url, filename, data=None, silent=False):
|
||||
form = MultiPartForm()
|
||||
if data:
|
||||
for key in data:
|
||||
|
@ -188,18 +188,22 @@ class API(object):
|
|||
try:
|
||||
data = self._json_request(uploadUrl, form)
|
||||
except KeyboardInterrupt:
|
||||
if not slient:
|
||||
print("\ninterrupted by user.")
|
||||
sys.exit(1)
|
||||
except:
|
||||
if not slient:
|
||||
print("uploading chunk failed, will try again in 5 seconds\r", end='')
|
||||
sys.stdout.flush()
|
||||
data = {'result': -1}
|
||||
time.sleep(5)
|
||||
if data and 'status' in data:
|
||||
if data['status']['code'] == 403:
|
||||
if not slient:
|
||||
print("login required")
|
||||
return False
|
||||
if data['status']['code'] != 200:
|
||||
if not slient:
|
||||
print("request returned error, will try again in 5 seconds")
|
||||
if self.DEBUG:
|
||||
print(data)
|
||||
|
@ -207,6 +211,7 @@ class API(object):
|
|||
if data and data.get('result') == 1:
|
||||
done += len(chunk)
|
||||
if data.get('offset') not in (None, done):
|
||||
if not slient:
|
||||
print('server offset out of sync, continue from', data['offset'])
|
||||
done = data['offset']
|
||||
f.seek(done)
|
||||
|
|
Loading…
Reference in a new issue