progress: use global variable 'progress'

There is no point in having more than just one
global progress bar.

Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Ruslan Kuprieiev
2017-06-21 03:37:42 +03:00
parent cd43160414
commit 11d1fb502a
2 changed files with 12 additions and 7 deletions
+5 -5
View File
@@ -12,7 +12,7 @@ from dvc.runtime import Runtime
from dvc.state_file import StateFile
from dvc.system import System
from dvc.command.data_sync import POOL_SIZE
from dvc.progress import Progress
from dvc.progress import progress
class ImportFileError(DvcException):
@@ -178,21 +178,21 @@ class CmdImportFile(CmdBase):
Logger.debug('Downloaded {}'.format(sizeof_fmt(downloaded)))
# update progress bar
self.progress.update_target(name, downloaded, total_length)
progress.update_target(name, downloaded, total_length)
f.write(chunk)
# tell progress bar that this target is finished downloading
self.progress.finish_target(name)
progress.finish_target(name)
def download_targets(self, targets):
"""
Download targets in a number of threads.
"""
self.progress = Progress(len(targets))
progress.set_n_total(len(targets))
p = ThreadPool(processes=POOL_SIZE)
p.map(self.download_target, targets)
self.progress.finish()
progress.finish()
def create_state_files(self, targets, lock):
"""
+7 -2
View File
@@ -6,11 +6,14 @@ class Progress(object):
"""
Simple multi-target progress bar.
"""
def __init__(self, total):
self._n_total = total
def __init__(self):
self._n_total = 0
self._n_finished = 0
self._lock = threading.Lock()
def set_n_total(self, total):
self._n_total = total
def _clearln(self):
print('\r\x1b[K', end='')
@@ -73,3 +76,5 @@ class Progress(object):
name = target_name[:name_len] if len(target_name) > name_len else target_name
return num + bar + percent + name
progress = Progress()