Module: check_mk
Branch: master
Commit: 130b7d6a84da8ce7eeb3982340690476b3c05c28
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=130b7d6a84da8c…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Mar 13 16:55:06 2019 +0100
Made cmk.gui.tags.parse_hosttag_title private
The _export_hosttags_to_php() function now uses the
regular model objects instead of low level data.
CMK-1813
Change-Id: Ia3ac4c6b1eb7540529b3351ba33324373599b34f
---
cmk/gui/plugins/wato/utils/__init__.py | 1 -
cmk/gui/tags.py | 24 +++---------------------
cmk/gui/watolib/tags.py | 28 ++++++++++++++--------------
3 files changed, 17 insertions(+), 36 deletions(-)
diff --git a/cmk/gui/plugins/wato/utils/__init__.py
b/cmk/gui/plugins/wato/utils/__init__.py
index e97e1f4..1b7a898 100644
--- a/cmk/gui/plugins/wato/utils/__init__.py
+++ b/cmk/gui/plugins/wato/utils/__init__.py
@@ -113,7 +113,6 @@ from cmk.gui.plugins.wato.utils.valuespecs import (
)
import cmk.gui.watolib as watolib
from cmk.gui.watolib.password_store import PasswordStore
-from cmk.gui.tags import group_hosttags_by_topic
from cmk.gui.watolib.timeperiods import TimeperiodSelection
from cmk.gui.watolib.users import notification_script_title
from cmk.gui.watolib.groups import (
diff --git a/cmk/gui/tags.py b/cmk/gui/tags.py
index 48081d3..d631e18 100644
--- a/cmk/gui/tags.py
+++ b/cmk/gui/tags.py
@@ -38,24 +38,12 @@ def transform_pre_16_tags(tag_groups, aux_tags):
return cfg.get_dict_format()
-def parse_hosttag_title(title):
+def _parse_hosttag_title(title):
if '/' in title:
return title.split('/', 1)
return None, title
-# TODO: Cleanup all call sites
-def group_hosttags_by_topic(hosttags):
- tags = {}
- for entry in hosttags:
- topic, title = parse_hosttag_title(entry[1])
- if not topic:
- topic = _('Host tags')
- tags.setdefault(topic, [])
- tags[topic].append((entry[0], title) + entry[2:])
- return sorted(tags.items(), key=lambda x: x[0])
-
-
def _validate_tag_id(tag_id, varname):
if not re.match("^[-a-z0-9A-Z_]*$", tag_id):
raise MKUserError(
@@ -114,7 +102,7 @@ class AuxTag(Hosttag):
def _parse_legacy_format(self, tag_info):
super(AuxTag, self)._parse_legacy_format(tag_info)
- self.topic, self.title = HosttagsConfiguration.parse_hosttag_title(self.title)
+ self.topic, self.title = _parse_hosttag_title(self.title)
def get_legacy_format(self):
return self.id, HosttagsConfiguration.get_merged_topic_and_title(self)
@@ -258,7 +246,7 @@ class HosttagGroup(object):
group_id, group_title, tag_list = group_info[:3]
self.id = group_id
- self.topic, self.title = HosttagsConfiguration.parse_hosttag_title(group_title)
+ self.topic, self.title = _parse_hosttag_title(group_title)
for tag in tag_list:
self.tags.append(GroupedHosttag(self, tag))
@@ -324,12 +312,6 @@ class HosttagsConfiguration(object):
return self
@staticmethod
- def parse_hosttag_title(title):
- if '/' in title:
- return title.split('/', 1)
- return None, title
-
- @staticmethod
def get_merged_topic_and_title(entity):
if entity.topic:
return "%s/%s" % (entity.topic, entity.title)
diff --git a/cmk/gui/watolib/tags.py b/cmk/gui/watolib/tags.py
index 3630996..7c6ebab 100644
--- a/cmk/gui/watolib/tags.py
+++ b/cmk/gui/watolib/tags.py
@@ -32,6 +32,7 @@ import cmk.utils.paths
import cmk.utils.store as store
import cmk.gui.tags
+import cmk.gui.config as config
from cmk.gui.watolib.simple_config_file import WatoSimpleConfigFile
from cmk.gui.watolib.utils import multisite_dir
@@ -63,12 +64,7 @@ class TagConfigFile(WatoSimpleConfigFile):
# TODO: Move the hosttag export to a hook
def save(self, cfg):
super(TagConfigFile, self).save(cfg)
-
- tag_config = cmk.gui.tags.HosttagsConfiguration()
- tag_config.parse_config(cfg)
- hosttags, auxtags = tag_config.get_legacy_format()
-
- _export_hosttags_to_php(hosttags, auxtags)
+ _export_hosttags_to_php(cfg)
# Creates a includable PHP file which provides some functions which
@@ -90,11 +86,15 @@ class TagConfigFile(WatoSimpleConfigFile):
# the tag group title and the value contains the value returned by
# taggroup_choice() for this tag group.
#
-def _export_hosttags_to_php(hosttags, auxtags):
+def _export_hosttags_to_php(cfg):
php_api_dir = cmk.utils.paths.var_dir + "/wato/php-api/"
path = php_api_dir + '/hosttags.php'
store.mkdir(php_api_dir)
+ tag_config = cmk.gui.tags.HosttagsConfiguration()
+ tag_config.parse_config(cfg)
+ tag_config += config.BuiltinHosttagsConfiguration()
+
# need an extra lock file, since we move the auth.php.tmp file later
# to auth.php. This move is needed for not having loaded incomplete
# files into php.
@@ -105,14 +105,14 @@ def _export_hosttags_to_php(hosttags, auxtags):
# Transform WATO internal data structures into easier usable ones
hosttags_dict = {}
- for entry in hosttags:
- id_, title, choices = entry[:3]
+ for tag_group in tag_config.tag_groups:
tags = {}
- for tag_id, tag_title, tag_auxtags in choices:
- tags[tag_id] = tag_title, tag_auxtags
- topic, title = cmk.gui.tags.parse_hosttag_title(title)
- hosttags_dict[id_] = topic, title, tags
- auxtags_dict = dict(auxtags)
+ for grouped_tag in tag_group.tags:
+ tags[grouped_tag.id] = (grouped_tag.title, grouped_tag.aux_tag_ids)
+
+ hosttags_dict[tag_group.id] = (tag_group.topic, tag_group.title, tags)
+
+ auxtags_dict = dict(tag_config.aux_tag_list.get_choices())
# First write a temp file and then do a move to prevent syntax errors
# when reading half written files during creating that new file