mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-22 11:18:08 -06:00
Added convert_bytes function to show correctly FTP upload progress
This commit is contained in:
parent
13c47f7b9f
commit
a9f52b3a94
@ -6,6 +6,21 @@ import ftplib
|
|||||||
|
|
||||||
transferred=0
|
transferred=0
|
||||||
|
|
||||||
|
def convert_bytes(n):
|
||||||
|
K, M, G, T, P = 1 << 10, 1 << 20, 1 << 30, 1 << 40, 1 << 50
|
||||||
|
if n >= P:
|
||||||
|
return '%.2fPb' % (float(n) / T)
|
||||||
|
elif n >= T:
|
||||||
|
return '%.2fTb' % (float(n) / T)
|
||||||
|
elif n >= G:
|
||||||
|
return '%.2fGb' % (float(n) / G)
|
||||||
|
elif n >= M:
|
||||||
|
return '%.2fMb' % (float(n) / M)
|
||||||
|
elif n >= K:
|
||||||
|
return '%.2fKb' % (float(n) / K)
|
||||||
|
else:
|
||||||
|
return '%d' % n
|
||||||
|
|
||||||
def callback(progress):
|
def callback(progress):
|
||||||
global transferred
|
global transferred
|
||||||
transferred = transferred+len(progress)
|
transferred = transferred+len(progress)
|
||||||
|
Loading…
Reference in New Issue
Block a user