Module: check_mk
Branch: master
Commit: f250e39c296ba514b5ffa1d5b12d3d59d8e55df2
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f250e39c296ba5…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Sep 29 09:27:53 2016 +0200
User files are now also saved with store.save_data_to_file()
---
lib/store.py | 1 -
web/htdocs/config.py | 15 ++-------------
web/htdocs/html_mod_python.py | 4 ++--
web/htdocs/htmllib.py | 6 +++---
web/htdocs/views.py | 2 +-
web/htdocs/visuals.py | 2 +-
6 files changed, 9 insertions(+), 21 deletions(-)
diff --git a/lib/store.py b/lib/store.py
index d22544e..98a76b8 100644
--- a/lib/store.py
+++ b/lib/store.py
@@ -226,7 +226,6 @@ def save_data_to_file(path, data, pretty=True):
else:
formated_data = repr(data)
- print formated_data
save_file(path, "%s\n" % formated_data)
diff --git a/web/htdocs/config.py b/web/htdocs/config.py
index db4106a..f046801 100644
--- a/web/htdocs/config.py
+++ b/web/htdocs/config.py
@@ -442,25 +442,14 @@ def load_user_file(name, deflt, lock = False):
return store.load_data_from_file(path, deflt, lock)
-def save_user_file(name, content, unlock=False, user=None):
+def save_user_file(name, data, user=None):
if user == None:
user = user_id
dirname = config_dir + "/" + user.encode("utf-8")
make_nagios_directory(dirname)
path = dirname + "/" + name + ".mk"
+ store.save_data_to_file(path, data)
- try:
- try:
- write_settings_file(path + ".new", content)
- os.rename(path + ".new", path)
- except Exception, e:
- if debug:
- raise
- raise MKConfigError(_("Cannot save %s options for user
<b>%s</b> into <b>%s</b>: %s") % \
- (name, user, path, e))
- finally:
- if unlock:
- release_lock(path)
def user_file_modified(name):
if user_confdir == None:
diff --git a/web/htdocs/html_mod_python.py b/web/htdocs/html_mod_python.py
index 35750fa..d30c9dc 100644
--- a/web/htdocs/html_mod_python.py
+++ b/web/htdocs/html_mod_python.py
@@ -280,9 +280,9 @@ class html_mod_python(htmllib.html):
def load_transids(self, lock = False):
return config.load_user_file("transids", [], lock)
- def save_transids(self, used_ids, unlock = False):
+ def save_transids(self, used_ids):
if config.user_id:
- config.save_user_file("transids", used_ids, unlock)
+ config.save_user_file("transids", used_ids)
def save_tree_states(self):
config.save_user_file("treestates", self.treestates)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 3bad574..4909e59 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -1836,7 +1836,7 @@ class html(object):
timestamp = valid_id.split("/")[0]
if now - int(timestamp) < 86400: # one day
cleared_ids.append(valid_id)
- self.save_transids((cleared_ids[-20:] + self.new_transids), unlock = True)
+ self.save_transids((cleared_ids[-20:] + self.new_transids))
# Remove the used transid from the list of valid ones
@@ -1846,7 +1846,7 @@ class html(object):
valid_ids.remove(used_id)
except ValueError:
return
- self.save_transids(valid_ids, unlock = True)
+ self.save_transids(valid_ids)
# Checks, if the current transaction is valid, i.e. in case of
@@ -1911,7 +1911,7 @@ class html(object):
raise NotImplementedError()
- def save_transids(self, used_ids, unlock=False):
+ def save_transids(self, used_ids):
raise NotImplementedError()
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index 08c4797..1d0a5dd 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -438,7 +438,7 @@ class PainterOptions(object):
def save_to_config(self):
vo = config.load_user_file("viewoptions", {}, lock=True)
vo[self._view_name] = self._options
- config.save_user_file("viewoptions", vo, unlock=True)
+ config.save_user_file("viewoptions", vo)
def update_from_url(self, view):
diff --git a/web/htdocs/visuals.py b/web/htdocs/visuals.py
index 3c48acc..79bb7d6 100644
--- a/web/htdocs/visuals.py
+++ b/web/htdocs/visuals.py
@@ -105,7 +105,7 @@ def save(what, visuals, user_id = None):
for (owner_id, name), visual in visuals.items():
if user_id == owner_id:
uservisuals[name] = visual
- config.save_user_file('user_' + what, uservisuals, user = user_id,
unlock=True)
+ config.save_user_file('user_' + what, uservisuals, user = user_id)
# FIXME: Currently all user visual files of this type are locked. We could optimize
# this not to lock all files but only lock the files the user is about to modify.