Updated gettools.py to display download progress
This commit is contained in:
parent
567b29fe95
commit
0995c85df2
26
gettools.py
26
gettools.py
|
@ -29,6 +29,7 @@ import sys
|
|||
import shutil
|
||||
import tarfile
|
||||
import zipfile
|
||||
import time
|
||||
|
||||
try:
|
||||
# For Python 3.0 and later
|
||||
|
@ -71,6 +72,20 @@ def convertpath(path):
|
|||
# OS path separator replacement funciton
|
||||
return path.replace(os.path.sep, '/')
|
||||
|
||||
def reporthook(count, block_size, total_size):
|
||||
global start_time
|
||||
if count == 0:
|
||||
start_time = time.time()
|
||||
return
|
||||
duration = time.time() - start_time
|
||||
progress_size = int(count * block_size)
|
||||
speed = int(progress_size / (1024 * duration)) if duration>0 else 0
|
||||
percent = min(int(count*block_size*100/total_size),100)
|
||||
time_remaining = ((total_size - progress_size)/1024) / speed if speed > 0 else 0
|
||||
sys.stdout.write("\r...%d%%, %d MB, %d KB/s, %d seconds remaining" %
|
||||
(percent, progress_size / (1024 * 1024), speed, time_remaining))
|
||||
sys.stdout.flush()
|
||||
|
||||
def main():
|
||||
# Check minimal Python version is 2.7
|
||||
if sys.version_info < (2, 7):
|
||||
|
@ -126,9 +141,13 @@ def main():
|
|||
' give a look into the core.vmware.fusion.tar file')
|
||||
urlcoretar = url + lastVersion + '/core/com.vmware.fusion.zip.tar'
|
||||
|
||||
try:
|
||||
# Get the main core file
|
||||
urlretrieve(urlcoretar, convertpath(dest + '/tools/com.vmware.fusion.zip.tar'))
|
||||
try:
|
||||
urlretrieve(urlcoretar, convertpath(dest + '/tools/com.vmware.fusion.zip.tar'), reporthook)
|
||||
except:
|
||||
print('Couldn\'t find tools')
|
||||
|
||||
print()
|
||||
|
||||
print('Extracting com.vmware.fusion.zip.tar...')
|
||||
tar = tarfile.open(convertpath(dest + '/tools/com.vmware.fusion.zip.tar'), 'r')
|
||||
|
@ -152,9 +171,6 @@ def main():
|
|||
|
||||
print('Tools retrieved successfully')
|
||||
return
|
||||
except:
|
||||
print('Odds are against you. Sorry.')
|
||||
return
|
||||
|
||||
# Tools have been found, go with the normal way
|
||||
|
||||
|
|
Loading…
Reference in New Issue