From 11d1fb502a240ba7d9c1ca3f8e1bc6466e73ffe8 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Wed, 21 Jun 2017 03:37:42 +0300 Subject: [PATCH] progress: use global variable 'progress' There is no point in having more than just one global progress bar. Signed-off-by: Ruslan Kuprieiev --- dvc/command/import_file.py | 10 +++++----- dvc/progress.py | 9 +++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/dvc/command/import_file.py b/dvc/command/import_file.py index 5c6aa6eac..6e80bfe4d 100644 --- a/dvc/command/import_file.py +++ b/dvc/command/import_file.py @@ -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): """ diff --git a/dvc/progress.py b/dvc/progress.py index 31c45b682..f4026db3a 100644 --- a/dvc/progress.py +++ b/dvc/progress.py @@ -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()