From 8b0fa616596cc26be0f06b4a093d430c4a24b00a Mon Sep 17 00:00:00 2001 From: Dave Dykstra <2129743+DrDaveD@users.noreply.github.com> Date: Sun, 1 Sep 2024 15:49:34 -0500 Subject: [PATCH] fix pretty print of long strings, update to 1.28 --- rpm/cvmfs-servermon.spec | 11 +++++++---- webapi/cvmfsmon_api.py | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/rpm/cvmfs-servermon.spec b/rpm/cvmfs-servermon.spec index 988808e..9c4e2e4 100644 --- a/rpm/cvmfs-servermon.spec +++ b/rpm/cvmfs-servermon.spec @@ -1,6 +1,6 @@ Summary: CernVM File System Server Monitoring Name: cvmfs-servermon -Version: 1.27 +Version: 1.28 # The release_prefix macro is used in the OBS prjconf, don't change its name %define release_prefix 1 Release: %{release_prefix}%{?dist} @@ -68,9 +68,12 @@ setsebool -P httpd_can_network_connect 1 2>/dev/null || true /usr/share/cvmfs-servermon %changelog -# - Remove old workaround added in version 1.12 because it incorrectly -# reported the status of a repo without an initial snapshot but with -# a completed gc. +Mon Sep 2 2024 Dave Dykstra - 1.28-1 +- Prevent json pretty printer from breaking up long strings, the way + pyhon2 did it. +- Remove old workaround added in version 1.12 because it incorrectly + reported the status of a repo without an initial snapshot but with + a completed gc. * Mon Oct 23 2023 Dave Dykstra - 1.27-1 - Correct inconsistent tab/space which python3 rejected. diff --git a/webapi/cvmfsmon_api.py b/webapi/cvmfsmon_api.py index 6574e07..a3de935 100644 --- a/webapi/cvmfsmon_api.py +++ b/webapi/cvmfsmon_api.py @@ -138,6 +138,19 @@ def domontest(testname, montests): return True return False +# from https://stackoverflow.com/a/55619288 +# simulate python2 pretty printer by not breaking up strings +class Python2PrettyPrinter(pprint.PrettyPrinter): + class _fake_short_str(str): + def __len__(self): + return 1 if super().__len__() else 0 + + def format(self, object, context, maxlevels, level): + res = super().format(object, context, maxlevels, level) + if isinstance(object, str): + return (self._fake_short_str(res[0]), ) + res[1:] + return res + def dispatch(version, montests, parameters, start_response, environ): global last_config_time now = time.time() @@ -311,7 +324,7 @@ def dispatch(version, montests, parameters, start_response, environ): details[status][test] = [repomsg] output = StringIO() - pprint.pprint(details, output) + Python2PrettyPrinter(stream=output).pprint(details) body = output.getvalue() output.close() body = body.replace("'", '"')