提交 19370b22 编写于 作者: W wangxiao

update downloader.py

上级 d2bbdfd0
...@@ -33,21 +33,7 @@ _items = { ...@@ -33,21 +33,7 @@ _items = {
'tasktype': {'utils': None}, 'tasktype': {'utils': None},
} }
def _download(item, scope, path, silent=False):
def _convert():
raise NotImplementedError()
def download(item, scope='all', path='.'):
item = item.lower()
scope = scope.lower()
assert item in _items, '{} is not found. Support list: {}'.format(item, list(_items.keys()))
# if not os.path.exists(path + '/' + item):
# os.makedirs(os.path.join(path + '/' + item))
def _download(item, scope, silent=False):
if not silent: if not silent:
print('Downloading {}: {} from {}...'.format(item, scope, _items[item][scope])) print('Downloading {}: {} from {}...'.format(item, scope, _items[item][scope]))
data_url = _items[item][scope] data_url = _items[item][scope]
...@@ -57,12 +43,11 @@ def download(item, scope='all', path='.'): ...@@ -57,12 +43,11 @@ def download(item, scope='all', path='.'):
filename = data_dir + '/' + data_url.split('/')[-1] filename = data_dir + '/' + data_url.split('/')[-1]
def chunk_report(bytes_so_far, total_size): def chunk_report(bytes_so_far, total_size):
percent = float(bytes_so_far) / float(total_size) * 100.0 percent = float(bytes_so_far) / float(total_size)
if percent > 100: if percent > 1:
percent = 100 percent = 1
if not silent: if not silent:
print('\r>> Downloading... %.1f%%' % percent, end="\r") print('\r>> Downloading... {:.1%}'.format(percent), end = "")
def chunk_read(response, url, chunk_size = 16 * 1024, report_hook = None): def chunk_read(response, url, chunk_size = 16 * 1024, report_hook = None):
total_size = response.info().getheader('Content-Length').strip() total_size = response.info().getheader('Content-Length').strip()
...@@ -84,17 +69,27 @@ def download(item, scope='all', path='.'): ...@@ -84,17 +69,27 @@ def download(item, scope='all', path='.'):
chunk_read(response, data_url, report_hook=chunk_report) chunk_read(response, data_url, report_hook=chunk_report)
if not silent: if not silent:
print('done!') print(' done!')
def _convert():
raise NotImplementedError()
def download(item, scope='all', path='.'):
item = item.lower()
scope = scope.lower()
assert item in _items, '{} is not found. Support list: {}'.format(item, list(_items.keys()))
if _items[item]['utils'] is not None: if _items[item]['utils'] is not None:
_download(item, 'utils', silent=True) _download(item, 'utils', path, silent=True)
if scope != 'all': if scope != 'all':
assert scope in _items[item], '{} is not found. Support scopes: {}'.format(item, list(_items[item].keys())) assert scope in _items[item], '{} is not found. Support scopes: {}'.format(item, list(_items[item].keys()))
_download(item, scope) _download(item, scope, path)
else: else:
for s in _items[item].keys(): for s in _items[item].keys():
_download(item, s) _download(item, s, path)
def ls(item=None, scope='all'): def ls(item=None, scope='all'):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册