From 3bf810a832e0241d2c2c0674621eff1b1008a7a2 Mon Sep 17 00:00:00 2001 From: n3hrox Date: Fri, 1 Nov 2019 16:36:31 +0100 Subject: [PATCH] move footer from logger to main --- dvc/logger.py | 16 +--------------- dvc/main.py | 14 ++++++++++++++ dvc/remote/base.py | 8 ++++++-- dvc/remote/local.py | 19 ++----------------- 4 files changed, 23 insertions(+), 34 deletions(-) diff --git a/dvc/logger.py b/dvc/logger.py index 71f9d9147..075b1b680 100644 --- a/dvc/logger.py +++ b/dvc/logger.py @@ -48,16 +48,6 @@ class ColorFormatter(logging.Formatter): "CRITICAL": colorama.Fore.RED, } - footer = ( - "{yellow}Having any troubles?{nc}" - " Hit us up at {blue}https://dvc.org/support{nc}," - " we are always happy to help!" - ).format( - blue=colorama.Fore.BLUE, - nc=colorama.Fore.RESET, - yellow=colorama.Fore.YELLOW, - ) - def format(self, record): if record.levelname == "INFO": return record.msg @@ -66,10 +56,7 @@ class ColorFormatter(logging.Formatter): exception, stack_trace = self._parse_exc(record.exc_info) return ( - "{color}{levelname}{nc}: {description}" - "{stack_trace}\n" - "\n" - "{footer}" + "{color}{levelname}{nc}: {description}" "{stack_trace}\n" ).format( color=self.color_code.get(record.levelname, ""), nc=colorama.Fore.RESET, @@ -77,7 +64,6 @@ class ColorFormatter(logging.Formatter): description=self._description(record.msg, exception), msg=record.msg, stack_trace=stack_trace, - footer=self.footer, ) return "{color}{levelname}{nc}: {msg}".format( diff --git a/dvc/main.py b/dvc/main.py index f8b94b8d3..d21a51592 100644 --- a/dvc/main.py +++ b/dvc/main.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals import logging +import colorama from dvc.cli import parse_args from dvc.lock import LockError @@ -16,6 +17,16 @@ from dvc.utils.compat import is_py2 logger = logging.getLogger("dvc") +footer = ( + "\n{yellow}Having any troubles?{nc}" + " Hit us up at {blue}https://dvc.org/support{nc}," + " we are always happy to help!" +).format( + blue=colorama.Fore.BLUE, + nc=colorama.Fore.RESET, + yellow=colorama.Fore.YELLOW, +) + def main(argv=None): """Run dvc CLI command. @@ -75,6 +86,9 @@ def main(argv=None): # so won't be reused by any other subsequent run anyway. clean_repos() + if ret != 0: + logger.info(footer) + Analytics().send_cmd(cmd, args, ret) return ret diff --git a/dvc/remote/base.py b/dvc/remote/base.py index 30ec6ed6b..cead3293a 100644 --- a/dvc/remote/base.py +++ b/dvc/remote/base.py @@ -515,7 +515,9 @@ class RemoteBASE(object): no_progress_bar=no_progress_bar, ) except Exception: - return 1, from_info, to_info, "upload" # 1 fail + msg = "failed to upload '{}' to '{}'" + logger.exception(msg.format(from_info, to_info)) + return 1 # 1 fail return 0 @@ -553,7 +555,9 @@ class RemoteBASE(object): from_info, tmp_file, name=name, no_progress_bar=no_progress_bar ) except Exception: - return 1, from_info, to_info, "download" # 1 fail + msg = "failed to upload '{}' to '{}'" + logger.exception(msg.format(from_info, to_info)) + return 1 # 1 fail move(tmp_file, to_info, mode=file_mode) diff --git a/dvc/remote/local.py b/dvc/remote/local.py index c66a26be3..dff433756 100644 --- a/dvc/remote/local.py +++ b/dvc/remote/local.py @@ -358,26 +358,11 @@ class RemoteLOCAL(RemoteBASE): if len(plans[0]) == 0: return 0 - fails = 0 - msgs = "" if jobs > 1: with TqdmThreadPoolExecutor(max_workers=jobs) as executor: - failures = executor.map(func, *plans) + fails = sum(executor.map(func, *plans)) else: - failures = list(map(func, *plans)) - - for failure in failures: - if not isinstance(failure, tuple): - continue - fails += failure[0] - from_info, to_info = failure[1], failure[2] - operation = failure[3] - msgs += "Failed to {} '{}' to '{}'\n".format( - operation, from_info, to_info - ) - - if msgs: - logger.exception(msgs) + fails = sum(map(func, *plans)) if fails: if download: