From f82afccabc6f9b1ac4144f8c98f7cfbfd47700a1 Mon Sep 17 00:00:00 2001 From: Merlin Mathesius Date: Jun 25 2020 14:38:58 +0000 Subject: Fixup Python version-dependent stdout autoflush Signed-off-by: Merlin Mathesius --- diff --git a/README.md b/README.md index c0072af..e79551f 100644 --- a/README.md +++ b/README.md @@ -41,13 +41,18 @@ works with the PR applied and how the PR changed the compose. ### Unit-testing -Install packages required to build the python package: +Install packages required to build and test the python package: ``` $ sudo dnf install -y \ + compose-utils \ + gcc \ git \ + krb5-devel \ make \ - krb5-devel + rsync \ + tox \ + which ``` Run the tests: diff --git a/cccc/__main__.py b/cccc/__main__.py index 86f3224..dc8f69d 100644 --- a/cccc/__main__.py +++ b/cccc/__main__.py @@ -1,10 +1,10 @@ # SPDX-License-Identifier: MIT import argparse -import os import sys import cccc.cli +from cccc.utils import AutoFlush def main(argv=None): @@ -98,7 +98,7 @@ def main(argv=None): parser.error("at least one PR parameter must be provided") # unbuffer stdout for the benefit of following the CI log - sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', buffering=0) + sys.stdout = AutoFlush(sys.stdout) return cccc.cli.run(args) diff --git a/cccc/utils.py b/cccc/utils.py index 1e49762..d6e5cb3 100644 --- a/cccc/utils.py +++ b/cccc/utils.py @@ -74,3 +74,20 @@ def download_file(url, filename): f.write(chunk) f.flush() return True + + +# wrapper around an IO stream to automatically flush after writes +class AutoFlush(object): + def __init__(self, stream): + self.stream = stream + + def write(self, s): + self.stream.write(s) + self.stream.flush() + + def writelines(self, lines): + self.stream.writelines(lines) + self.stream.flush() + + def __getattr__(self, name): + return getattr(self.stream, name)