Module: check_mk
Branch: master
Commit: b1d1c33621f60241a84f5da78811e31f895a4bfc
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b1d1c33621f602…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Feb 18 19:39:11 2019 +0100
WATO Git: Cleaned up module global state
The git commit messages are now held by the request global
wato_git_messages entry instead of a module global variable.
Change-Id: Idc095e7f5dd2c76b239c759b62a0d5c1859be5c4
---
cmk/gui/watolib/__init__.py | 7 -------
cmk/gui/watolib/git.py | 16 +++++++---------
2 files changed, 7 insertions(+), 16 deletions(-)
diff --git a/cmk/gui/watolib/__init__.py b/cmk/gui/watolib/__init__.py
index 096d96a..45273c7 100644
--- a/cmk/gui/watolib/__init__.py
+++ b/cmk/gui/watolib/__init__.py
@@ -314,9 +314,6 @@ def load_watolib_plugins():
# robust way for doing something like this. If it is locked before, it can now happen
# that this call unlocks the wider locking when calling this funktion in a wrong way.
def init_wato_datastructures(with_wato_lock=False):
- if config.wato_use_git:
- cmk.gui.watolib.git.prepare_git_commit()
-
cmk.gui.watolib.sidebar_reload.reset()
if os.path.exists(ConfigDomainCACertificates.trusted_cas_file) and\
@@ -357,10 +354,6 @@ def _create_sample_config():
if not _need_to_create_sample_config():
return
- # Just in case. If any of the following functions try to write Git messages
- if config.wato_use_git:
- cmk.gui.watolib.git.prepare_git_commit()
-
# Global configuration settings
save_global_settings({
"use_new_descriptions_for": [
diff --git a/cmk/gui/watolib/git.py b/cmk/gui/watolib/git.py
index 21c7372..cf0e4bb 100644
--- a/cmk/gui/watolib/git.py
+++ b/cmk/gui/watolib/git.py
@@ -31,21 +31,19 @@ import subprocess
import cmk.utils
import cmk.gui.config as config
+from cmk.gui.globals import current_app
from cmk.gui.i18n import _
from cmk.gui.exceptions import MKGeneralException
from cmk.gui.log import logger
-# TODO: Clean this up
-_messages = [] # type: List[str]
-
-def prepare_git_commit():
- global _messages
- _messages = []
+def add_message(message):
+ _git_messages().append(message)
-def add_message(message):
- _messages.append(message)
+def _git_messages():
+ """Initializes the request global data structure and returns
it"""
+ return current_app.g.setdefault("wato_git_messages", [])
def do_git_commit():
@@ -77,7 +75,7 @@ def do_git_commit():
logger.debug("GIT: Still has pending changes")
_git_add_files()
- message = ", ".join(_messages)
+ message = ", ".join(_git_messages())
if not message:
message = _("Unknown configuration change")