From c78874a7e0269e60a7f611518b978ff94e2a139f Mon Sep 17 00:00:00 2001 From: jpic Date: Thu, 13 Feb 2020 15:13:23 +0100 Subject: [PATCH] Output flushing --- podctl/build.py | 2 +- podctl/proc.py | 7 +++++-- podctl/script.py | 4 +--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/podctl/build.py b/podctl/build.py index dd13fe2..9323e98 100644 --- a/podctl/build.py +++ b/podctl/build.py @@ -101,7 +101,7 @@ class Build(Script): argv += [ type(self).__name__.lower(), # script name ? ] - output(' '.join(argv), 'EXECUTION') + output(' '.join(argv), 'EXECUTION', flush=True) proc = await asyncio.create_subprocess_shell( shlex.join(argv), diff --git a/podctl/proc.py b/podctl/proc.py index ec2287f..757bf7a 100644 --- a/podctl/proc.py +++ b/podctl/proc.py @@ -28,7 +28,7 @@ class Output: self.prefixes = dict() self.prefix_length = 0 - def __call__(self, line, prefix, highlight=True): + def __call__(self, line, prefix, highlight=True, flush=True): if prefix and prefix not in self.prefixes: self.prefixes[prefix] = ( self.colors[len([*self.prefixes.keys()]) - 1] @@ -58,6 +58,9 @@ class Output: + self.highlight(line, highlight) ).encode('utf8')) + if flush: + sys.stdout.flush() + def cmd(self, line, prefix): self( Fore.LIGHTBLACK_EX @@ -108,7 +111,7 @@ class PrefixStreamProtocol(asyncio.subprocess.SubprocessStreamProtocol): for line in data.split(b'\n'): if not line: continue - output(line, self.prefix) + output(line, self.prefix, flush=False) sys.stdout.flush() super().pipe_data_received(fd, data) diff --git a/podctl/script.py b/podctl/script.py index 7a34616..72a75a6 100644 --- a/podctl/script.py +++ b/podctl/script.py @@ -70,11 +70,10 @@ class Script: ')' ]), getattr(visitor, 'name', - getattr(visitable, 'name', None)) + getattr(visitable, 'name', None)), ) if result: await result - sys.stdout.flush() for prefix in ('init_', 'pre_', '', 'post_', 'clean_'): method = prefix + self.name @@ -101,7 +100,6 @@ class Script: except Exception as e: await clean() raise - sys.stdout.flush() async def run(self, *args, **kwargs): for key, value in kwargs.items():