Skip to content
Permalink
Browse files

Unified handling of plain_title() and title().

Change-Id: If2d1e7f59bb42eaa3180e0d4f26aaab46cd2241e
  • Loading branch information...
svenpanne committed Aug 5, 2019
1 parent 55b1d27 commit 4c64e4e061d7224ccb02ee75ea3617533c562c0c
Showing with 22 additions and 14 deletions.
  1. +17 −0 livestatus/api/python/livestatus.py
  2. +1 −0 locale/Makefile
  3. +4 −14 web/app/index.wsgi
@@ -33,6 +33,11 @@
import ssl
from typing import Tuple, Union, Dict, Pattern, Optional # pylint: disable=unused-import

try:
from cmk.gui.i18n import _
except ImportError:
_ = lambda x: x

# .--Globals-------------------------------------------------------------.
# | ____ _ _ _ |
# | / ___| | ___ | |__ __ _| |___ |
@@ -76,6 +81,12 @@ def __init__(self, value):
def __str__(self):
return str(self.parameter)

def plain_title(self):
return _("Livestatus problem")

def title(self):
return _("Livestatus problem")


class MKLivestatusSocketError(MKLivestatusException):
pass
@@ -97,6 +108,12 @@ class MKLivestatusNotFoundError(MKLivestatusException):
def __str__(self):
return "No matching entries found for query %s" % str(self.parameter)

def plain_title(self):
return _("Livestatus-data not found")

def title(self):
return _("Data not found")


class MKLivestatusTableNotFoundError(MKLivestatusException):
pass
@@ -28,6 +28,7 @@ update-%:
-L python --from-code=utf-8 --omit-header \
-o scanned.po \
../../../web/app/index.wsgi \
../../../livestatus/api/python/livestatus.py \
$$(find -L ../../../cmk -type f -name "*.py") 2>&1 < /dev/null | \
sed '/format string with unnamed arguments cannot be properly localized/,/and a mapping instead of a tuple for the arguments./d' ; \
cat ../../header scanned.po > new.po ; \
@@ -117,33 +117,23 @@ class Application(object):
livestatus.MKLivestatusException,
) as e:
# TODO: Refactor all the special cases handled here to simplify the exception handling
ty = type(e)
if ty == livestatus.MKLivestatusNotFoundError:
title = _("Data not found")
plain_title = _("Livestatus-data not found")
elif isinstance(e, livestatus.MKLivestatusException):
title = _("Livestatus problem")
plain_title = _("Livestatus problem")
else:
title = e.title()
plain_title = e.plain_title()

if self._plain_error():
html.set_output_format("text")
html.write("%s: %s\n" % (plain_title, e))
html.write("%s: %s\n" % (e.plain_title(), e))
elif not self._fail_silently():
html.header(title)
html.header(e.title())
html.show_error(e)
html.footer()

# Some exception need to set a specific HTTP status code
ty = type(e)
if ty == MKUnauthenticatedException:
self._response.status_code = httplib.UNAUTHORIZED
elif ty == livestatus.MKLivestatusException:
self._response.status_code = httplib.BAD_GATEWAY

if ty in [MKConfigError, MKGeneralException]:
logger.error("%s: %s" % (plain_title, e))
logger.error("%s: %s" % (e.plain_title(), e))

except Exception as e:
logger.exception("error processing WSGI request")

0 comments on commit 4c64e4e

Please sign in to comment.
You can’t perform that action at this time.