Skip to content

Commit c00962d

Browse files
authored
Merge pull request #57 from DrDaveD/fix-pprint
fix pretty print of long strings, update to 1.28
2 parents 7dc3ffa + 8b0fa61 commit c00962d

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

rpm/cvmfs-servermon.spec

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Summary: CernVM File System Server Monitoring
22
Name: cvmfs-servermon
3-
Version: 1.27
3+
Version: 1.28
44
# The release_prefix macro is used in the OBS prjconf, don't change its name
55
%define release_prefix 1
66
Release: %{release_prefix}%{?dist}
@@ -68,9 +68,12 @@ setsebool -P httpd_can_network_connect 1 2>/dev/null || true
6868
/usr/share/cvmfs-servermon
6969

7070
%changelog
71-
# - Remove old workaround added in version 1.12 because it incorrectly
72-
# reported the status of a repo without an initial snapshot but with
73-
# a completed gc.
71+
Mon Sep 2 2024 Dave Dykstra <[email protected]> - 1.28-1
72+
- Prevent json pretty printer from breaking up long strings, the way
73+
pyhon2 did it.
74+
- Remove old workaround added in version 1.12 because it incorrectly
75+
reported the status of a repo without an initial snapshot but with
76+
a completed gc.
7477

7578
* Mon Oct 23 2023 Dave Dykstra <[email protected]> - 1.27-1
7679
- Correct inconsistent tab/space which python3 rejected.

webapi/cvmfsmon_api.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,19 @@ def domontest(testname, montests):
138138
return True
139139
return False
140140

141+
# from https://stackoverflow.com/a/55619288
142+
# simulate python2 pretty printer by not breaking up strings
143+
class Python2PrettyPrinter(pprint.PrettyPrinter):
144+
class _fake_short_str(str):
145+
def __len__(self):
146+
return 1 if super().__len__() else 0
147+
148+
def format(self, object, context, maxlevels, level):
149+
res = super().format(object, context, maxlevels, level)
150+
if isinstance(object, str):
151+
return (self._fake_short_str(res[0]), ) + res[1:]
152+
return res
153+
141154
def dispatch(version, montests, parameters, start_response, environ):
142155
global last_config_time
143156
now = time.time()
@@ -311,7 +324,7 @@ def dispatch(version, montests, parameters, start_response, environ):
311324
details[status][test] = [repomsg]
312325

313326
output = StringIO()
314-
pprint.pprint(details, output)
327+
Python2PrettyPrinter(stream=output).pprint(details)
315328
body = output.getvalue()
316329
output.close()
317330
body = body.replace("'", '"')

0 commit comments

Comments
 (0)