Module: check_mk
Branch: master
Commit: 04079c18b3d4083cac6be576393402f8433992ac
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=04079c18b3d408…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Fri Jan 11 13:26:56 2019 +0100
prtconf: refactor to parse function
Change-Id: I180d26141631a33fc4f3bffe4b47fe6610b22efa
---
inventory/prtconf | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/inventory/prtconf b/inventory/prtconf
index 3164545..e94618b 100644
--- a/inventory/prtconf
+++ b/inventory/prtconf
@@ -48,20 +48,28 @@
# not being parsed.
-def inv_prtconf(info):
- confdict = {}
+def parse_prtconf(info):
+ parsed = {}
+
for line in info:
+ if not line:
+ continue
+ if line[0].startswith("========="):
+ break # ignore the rest of the output currently
if len(line) == 2:
varname = line[0]
value = line[1].strip()
- confdict[varname] = value
+ parsed[varname] = value
- if line[0].startswith("========="):
- break # ignore the rest of the output currently
+ return parsed
+
+
+def inv_prtconf(info):
+ parsed = parse_prtconf(info)
cpu_dict = inv_tree("hardware.cpu.")
- for varname, value in confdict.items():
+ for varname, value in parsed.items():
if varname == "CPU Type":
if value == "64-bit":
arch = "ppc64"
Module: check_mk
Branch: master
Commit: 4341f5886a6d1214c0bc05d18c00d908f7cf4ab2
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4341f5886a6d12…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Jan 10 20:10:52 2019 +0100
Moved watolib read only logic to dedicated module
Change-Id: I2a695e857aaddba2c949628d915febe752721af0
---
cmk/gui/wato/__init__.py | 14 +++++----
cmk/gui/watolib/__init__.py | 47 -------------------------------
cmk/gui/watolib/read_only.py | 67 ++++++++++++++++++++++++++++++++++++++++++++
cmk/gui/webapi.py | 6 ++--
4 files changed, 79 insertions(+), 55 deletions(-)
diff --git a/cmk/gui/wato/__init__.py b/cmk/gui/wato/__init__.py
index 4b1f882..9de123d 100644
--- a/cmk/gui/wato/__init__.py
+++ b/cmk/gui/wato/__init__.py
@@ -319,6 +319,7 @@ subgroup_inventory = RulespecGroupCheckParametersDiscovery().sub_group_name
# Make some functions of watolib available to WATO plugins without using the
# watolib module name. This is mainly done for compatibility reasons to keep
# the current plugin API functions working
+import cmk.gui.watolib.read_only
from cmk.gui.watolib import (
PasswordStore,
register_rulegroup,
@@ -475,8 +476,9 @@ def _wato_page_handler(current_mode, mode_permissions, mode_class):
if mode_permissions:
ensure_mode_permissions(mode_permissions)
- if watolib.is_read_only_mode_enabled() and not watolib.may_override_read_only_mode():
- raise MKUserError(None, watolib.read_only_message())
+ if cmk.gui.watolib.read_only.is_enabled(
+ ) and not cmk.gui.watolib.read_only.may_override():
+ raise MKUserError(None, cmk.gui.watolib.read_only.message())
result = mode.action()
if isinstance(result, tuple):
@@ -540,8 +542,8 @@ def _wato_page_handler(current_mode, mode_permissions, mode_class):
watolib.folder_preserving_link([("mode", target)]))
html.end_context_buttons()
- if not html.is_transaction() or (watolib.is_read_only_mode_enabled() and
- watolib.may_override_read_only_mode()):
+ if not html.is_transaction() or (cmk.gui.watolib.read_only.is_enabled() and
+ cmk.gui.watolib.read_only.may_override()):
_show_read_only_warning()
# Show outcome of action
@@ -589,8 +591,8 @@ def ensure_mode_permissions(mode_permissions):
def _show_read_only_warning():
- if watolib.is_read_only_mode_enabled():
- html.show_warning(watolib.read_only_message())
+ if cmk.gui.watolib.read_only.is_enabled():
+ html.show_warning(cmk.gui.watolib.read_only.message())
#.
diff --git a/cmk/gui/watolib/__init__.py b/cmk/gui/watolib/__init__.py
index 5ab5a9f..7b45916 100644
--- a/cmk/gui/watolib/__init__.py
+++ b/cmk/gui/watolib/__init__.py
@@ -4066,53 +4066,6 @@ class RuleComment(TextAreaUnicode):
#.
-# .--Read-Only-----------------------------------------------------------.
-# | ____ _ ___ _ |
-# | | _ \ ___ __ _ __| | / _ \ _ __ | |_ _ |
-# | | |_) / _ \/ _` |/ _` |_____| | | | '_ \| | | | | |
-# | | _ < __/ (_| | (_| |_____| |_| | | | | | |_| | |
-# | |_| \_\___|\__,_|\__,_| \___/|_| |_|_|\__, | |
-# | |___/ |
-# +----------------------------------------------------------------------+
-# | WATO can be set into read only mode manually. |
-# '----------------------------------------------------------------------'
-
-
-def read_only_message():
- text = _("The configuration is currently in read only mode. ")
-
- if config.wato_read_only["enabled"] is True:
- text += _("The read only mode is enabled until it is turned of manually. ")
-
- elif isinstance(config.wato_read_only['enabled'], tuple):
- end_time = config.wato_read_only['enabled'][1]
- text += _("The read only mode is enabled until %s. ") % render.date_and_time(end_time)
-
- if may_override_read_only_mode():
- text += _("But you are allowed to make changes anyway. ")
-
- text += "<br><br>" + _("Reason: %s") % config.wato_read_only["message"]
-
- return text
-
-
-def is_read_only_mode_enabled():
- if not config.wato_read_only:
- return False
- if config.wato_read_only["enabled"] is True:
- return True
- if isinstance(config.wato_read_only['enabled'], tuple):
- start_time, end_time = config.wato_read_only['enabled']
- return start_time <= time.time() <= end_time
- return False
-
-
-def may_override_read_only_mode():
- return config.user.id in config.wato_read_only["rw_users"] \
- or (html.request.var("mode") == "read_only" and config.user.may("wato.set_read_only"))
-
-
-#.
# .--Groups--------------------------------------------------------------.
# | ____ |
# | / ___|_ __ ___ _ _ _ __ ___ |
diff --git a/cmk/gui/watolib/read_only.py b/cmk/gui/watolib/read_only.py
new file mode 100644
index 0000000..e67f9db
--- /dev/null
+++ b/cmk/gui/watolib/read_only.py
@@ -0,0 +1,67 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2014 mk(a)mathias-kettner.de |
+# +------------------------------------------------------------------+
+#
+# This file is part of Check_MK.
+# The official homepage is at http://mathias-kettner.de/check_mk.
+#
+# check_mk is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation in version 2. check_mk is distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more de-
+# tails. You should have received a copy of the GNU General Public
+# License along with GNU Make; see the file COPYING. If not, write
+# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA.
+"""WATO can be set into read only mode manually."""
+import time
+
+import cmk.utils.render as render
+
+import cmk.gui.config as config
+from cmk.gui.i18n import _
+from cmk.gui.globals import html
+
+
+def message():
+ text = _("The configuration is currently in read only mode. ")
+
+ if config.wato_read_only["enabled"] is True:
+ text += _("The read only mode is enabled until it is turned of manually. ")
+
+ elif isinstance(config.wato_read_only['enabled'], tuple):
+ end_time = config.wato_read_only['enabled'][1]
+ text += _("The read only mode is enabled until %s. ") % render.date_and_time(end_time)
+
+ if may_override():
+ text += _("But you are allowed to make changes anyway. ")
+
+ text += "<br><br>" + _("Reason: %s") % config.wato_read_only["message"]
+
+ return text
+
+
+def is_enabled():
+ if not config.wato_read_only:
+ return False
+ if config.wato_read_only["enabled"] is True:
+ return True
+ if isinstance(config.wato_read_only['enabled'], tuple):
+ start_time, end_time = config.wato_read_only['enabled']
+ return start_time <= time.time() <= end_time
+ return False
+
+
+def may_override():
+ return config.user.id in config.wato_read_only["rw_users"] \
+ or (html.request.var("mode") == "read_only" and config.user.may("wato.set_read_only"))
diff --git a/cmk/gui/webapi.py b/cmk/gui/webapi.py
index f08e189..0ffb350 100644
--- a/cmk/gui/webapi.py
+++ b/cmk/gui/webapi.py
@@ -38,6 +38,7 @@ from cmk.gui.log import logger
import cmk.gui.utils as utils
import cmk.gui.config as config
import cmk.gui.watolib as watolib
+import cmk.gui.watolib.read_only
import cmk.gui.i18n
from cmk.gui.i18n import _
from cmk.gui.globals import html
@@ -160,8 +161,9 @@ def page_api():
del request_object["request_format"]
def execute_action():
- if watolib.is_read_only_mode_enabled() and not watolib.may_override_read_only_mode():
- raise MKUserError(None, watolib.read_only_message())
+ if cmk.gui.watolib.read_only.is_enabled(
+ ) and not cmk.gui.watolib.read_only.may_override():
+ raise MKUserError(None, cmk.gui.watolib.read_only.message())
return {
"result_code": 0,
"result": api_actions[action]["handler"](request_object),