Ready for action, sir!
This commit is contained in:
parent
f9e0bf948e
commit
6009df26de
669 changed files with 95073 additions and 2 deletions
scripts/devSetup
36
scripts/devSetup/downloader.py
Normal file
36
scripts/devSetup/downloader.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
__author__ = 'schmatz'
|
||||
from configuration import Configuration
|
||||
import urllib
|
||||
from dependency import Dependency
|
||||
class Downloader:
|
||||
def __init__(self,dependency):
|
||||
assert isinstance(dependency, Dependency)
|
||||
self.dependency = dependency
|
||||
@property
|
||||
def download_directory(self):
|
||||
raise NotImplementedError
|
||||
def download(self):
|
||||
raise NotImplementedError
|
||||
def download_file(self,url,filePath):
|
||||
urllib.urlretrieve(url,filePath,self.__progress_bar_reporthook)
|
||||
def decompress(self):
|
||||
raise NotImplementedError
|
||||
def check_download(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def __progress_bar_reporthook(self,blocknum,blocksize,totalsize):
|
||||
#http://stackoverflow.com/a/13895723/1928667
|
||||
#http://stackoverflow.com/a/3173331/1928667
|
||||
bars_to_display = 70
|
||||
amount_of_data_downloaded_so_far = blocknum * blocksize
|
||||
if totalsize > 0:
|
||||
progress_fraction = float(amount_of_data_downloaded_so_far) / float(totalsize)
|
||||
progress_percentage = progress_fraction * 1e2
|
||||
stringToDisplay = '\r[{0}] {1:.1f}%'.format('#'*int(bars_to_display*progress_fraction),progress_percentage)
|
||||
print stringToDisplay,
|
||||
if amount_of_data_downloaded_so_far >= totalsize:
|
||||
print "\n",
|
||||
else:
|
||||
stringToDisplay = '\r File size unknown. Read {0} bytes.'.format(amount_of_data_downloaded_so_far)
|
||||
print stringToDisplay,
|
||||
|
Reference in a new issue