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()