trailing spaces from localizable strings
Message-ID: <591ea63e.vR0eXfeUP37IZTSV%lm(a)mathias-kettner.de>
User-Agent: Heirloom mailx 12.5 6/20/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Module: check_mk
Branch: master
Commit: f3203103105f15239b8edd7a08e5e29e89e90ea7
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f3203103105f15…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri May 19 09:49:36 2017 +0200
Ruleset conditions: small code cleanup and removed leading/trailing spaces from
localizable strings
Change-Id: I41633f22eaa2da8ac7833458ed7cb5071de0ab7f
---
web/htdocs/wato.py | 103 +++++++++++++++++++++++++++++------------------------
1 file changed, 56 insertions(+), 47 deletions(-)
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 73c5ff1..59a014d 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -13216,63 +13216,72 @@ class ModeEditRuleset(WatoMode):
def _host_conditions(self, rule):
if rule.host_list == ALL_HOSTS:
return
+ # Other cases should not occur, e.g. list of explicit hosts
+ # plus ALL_HOSTS.
+ condition = self._render_host_condition_text(rule)
+ if condition:
+ html.li(condition, class_="condition")
- condition = None
+
+ def _render_host_condition_text(self, rule):
if rule.host_list == []:
- condition = _("This rule does <b>never</b> apply due to an
empty list of explicit hosts!")
+ return _("This rule does <b>never</b> apply due to an empty
list of explicit hosts!")
+
+ condition, text_list = [], []
+
+ if rule.host_list[0][0] == ENTRY_NEGATE_CHAR:
+ host_list = rule.host_list[:-1]
+ is_negate = True
else:
- text_list = []
+ is_negate = False
+ host_list = rule.host_list
- if rule.host_list[0][0] == ENTRY_NEGATE_CHAR:
- host_list = rule.host_list[:-1]
- is_negate = True
- else:
- is_negate = False
- host_list = rule.host_list
+ regex_count = len([x for x in host_list if "~" in x])
- regex_count = len([x for x in host_list if "~" in x])
+ condition.append(_("Host name"))
- condition = _("Host name ")
+ if regex_count == len(host_list) or regex_count == 0:
# Entries are either complete regex or no regex at all
- if regex_count == len(host_list) or regex_count == 0:
- is_regex = regex_count > 0
- if is_regex:
- condition += is_negate and _("is not one of regex ") or
_("matches one of regex ")
- else:
- condition += is_negate and _("is not one of ") or
_("is ")
-
- for host_spec in host_list:
- if not is_regex:
- host = Host.host(host_spec)
- if host:
- host_spec = '<a
href="%s">%s</a>' % (html.attrencode(host.edit_url()), host_spec)
-
text_list.append(html.render_b(host_spec.strip("!").strip("~")))
- # Mixed entries
+ is_regex = regex_count > 0
+ if is_regex:
+ condition.append(_("is not one of regex")
+ if is_negate else _("matches one of
regex"))
else:
- for host_spec in host_list:
- is_regex = "~" in host_spec
- host_spec = host_spec.strip("!").strip("~")
- if not is_regex:
- host = Host.host(host_spec)
- if host:
- host_spec = '<a
href="%s">%s</a>' % (html.attrencode(host.edit_url()), host_spec)
-
- if is_negate:
- expression = "%s" % (is_regex and _("does not
match regex ") or _("is not "))
- else:
- expression = "%s" % (is_regex and _("matches regex
") or _("is "))
- text_list.append("%s%s" % (expression,
html.render_b(host_spec)))
+ condition.append(_("is not one of")
+ if is_negate else _("is"))
- if len(text_list) == 1:
- condition += text_list[0]
- else:
- condition += ", ".join([ "%s" % s for s in
text_list[:-1] ])
- condition += _(" or ") + text_list[-1]
+ for host_spec in host_list:
+ if not is_regex:
+ host = Host.host(host_spec)
+ if host:
+ host_spec = html.render_a(host_spec, host.edit_url())
+
+
text_list.append(html.render_b(host_spec.strip("!").strip("~")))
+
+ else:
+ # Mixed entries
+ for host_spec in host_list:
+ is_regex = "~" in host_spec
+ host_spec = host_spec.strip("!").strip("~")
+ if not is_regex:
+ host = Host.host(host_spec)
+ if host:
+ host_spec = html.render_a(host_spec, host.edit_url())
+
+ if is_negate:
+ expression = "%s" % (is_regex and _("does not match
regex") or _("is not"))
+ else:
+ expression = "%s" % (is_regex and _("matches
regex") or _("is "))
+ text_list.append("%s %s" % (expression,
html.render_b(host_spec)))
+
+ if len(text_list) == 1:
+ condition.append(text_list[0])
+ else:
+ condition.append(", ".join([ "%s" % s for s in
text_list[:-1] ]))
+ condition.append(_(" or ") + text_list[-1])
+
+ return HTML(" ").join(condition)
- # Other cases should not occur, e.g. list of explicit hosts
- # plus ALL_HOSTS.
- if condition:
- html.li(condition, class_="condition")
def _service_conditions(self, rule):