From ee3203c485bbe9df0534a1c1cd3f5375c7ae4bf2 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 20 Apr 2021 22:06:03 -0600 Subject: [PATCH] Show message when downloading tools --- scripts/wk/kit/tools.py | 3 +++ scripts/wk/std.py | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/scripts/wk/kit/tools.py b/scripts/wk/kit/tools.py index 12e7d3df..4f23b9a9 100644 --- a/scripts/wk/kit/tools.py +++ b/scripts/wk/kit/tools.py @@ -27,6 +27,8 @@ CACHED_DIRS = {} def download_file(out_path, source_url, as_new=False, overwrite=False): """Download a file using requests, returns pathlib.Path.""" out_path = pathlib.Path(out_path).resolve() + cursor_left = '\u001B[14D' + print(f'Downloading...{cursor_left}', end='', flush=True) # Avoid clobbering if out_path.exists() and not overwrite: @@ -55,6 +57,7 @@ def download_file(out_path, source_url, as_new=False, overwrite=False): _f.write(chunk) # Done + print(f' {cursor_left}', end='', flush=True) return out_path diff --git a/scripts/wk/std.py b/scripts/wk/std.py index 5dba174c..8da412f1 100644 --- a/scripts/wk/std.py +++ b/scripts/wk/std.py @@ -455,7 +455,7 @@ class TryAndPrint(): # Done return message - def _format_function_output(self, output): + def _format_function_output(self, output, msg_good): """Format function output for use in try_and_print(), returns str.""" LOG.debug('Formatting output: %s', output) @@ -468,6 +468,10 @@ class TryAndPrint(): if not isinstance(stdout, str): stdout = stdout.decode('utf8') output = stdout.strip().splitlines() + if not output: + # Going to treat these as successes (for now) + LOG.warning('Program output was empty, assuming good result.') + return color_string(msg_good, 'GREEN') else: try: output = list(output) @@ -560,6 +564,7 @@ class TryAndPrint(): verbose, ) f_exception = None + msg_good = msg_good if msg_good else self.msg_good output = None result_msg = 'UNKNOWN' if catch_all is None: @@ -600,10 +605,10 @@ class TryAndPrint(): else: # Success if output: - result_msg = self._format_function_output(output) + result_msg = self._format_function_output(output, msg_good) print(result_msg) else: - result_msg = msg_good if msg_good else self.msg_good + result_msg = msg_good print_success(result_msg, log=False) # Done