Module: check_mk
Branch: master
Commit: bdbcae396bead9226dbf29adf38a83889fd45188
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=bdbcae396bead9…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sat Jun 25 12:07:25 2011 +0200
WATO: snapin now also shows files
---
web/htdocs/wato.py | 87 ++++++++++++++++++++++--------------------
web/plugins/sidebar/wato.py | 2 +-
2 files changed, 47 insertions(+), 42 deletions(-)
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 14f8f0e..f12fc68 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -1214,47 +1214,6 @@ def bulk_cleanup_attributes(the_file, hosts):
return num_shown > 0
-
-
-
-
-# +----------------------------------------------------------------------+
-# | ____ _ _ _ |
-# | / ___|(_) __| | ___| |__ __ _ _ __ |
-# | \___ \| |/ _` |/ _ \ '_ \ / _` | '__| |
-# | ___) | | (_| | __/ |_) | (_| | | |
-# | |____/|_|\__,_|\___|_.__/ \__,_|_| |
-# | |
-# +----------------------------------------------------------------------+
-# | Functions called from the WATO sidebar snapin |
-# +----------------------------------------------------------------------+
-
-def render_link_tree(format):
- load_folder_config()
-
- def render_folder(f):
-
- subfolders = f[".folders"]
- path = f[".path"]
- filename = "/" + "/".join(path) + "/"
- if len(path) > 0:
- url = "wato.py?filename=" + htmllib.urlencode(filename)
- if len(subfolders) == 0:
- title = format % (url, f["title"])
- else:
- title = '<a target=main href="%s">%s</a>' %
(url, f["title"])
- else:
- title = '<a target=main href="wato.py">%s</a>'
% f["title"]
-
- if len(subfolders) > 0:
- html.begin_foldable_container('wato', filename, False, title)
- for sf in sort_by_title(subfolders.values()):
- render_folder(sf)
- html.end_foldable_container()
- else:
- html.write(title)
-
- render_folder(g_root_folder)
# +----------------------------------------------------------------------+
@@ -2808,6 +2767,52 @@ class API:
result.append((attr.title(), content))
return result
+ # Get information about the folder and directory tree.
+ # This is useful for components that display hosts in
+ # the tree (e.g. the status GUI).
+ def get_folder_tree(self):
+ load_folder_config()
+ return g_root_folder
+
+
+ # Render clickable and foldable tree of all WATO folders
+ # and files (e.g. used by sidebar snapins)
+ def render_link_tree(self, format):
+ self._render_linktree_folder(self.get_folder_tree(), format)
+
+
+ # BELOW ARE PRIVATE HELPER FUNCTIONS
+
+ def _render_linktree_folder(self, f, format):
+ subfolders = f.get(".folders", {})
+ subfiles = f.get(".files", {})
+ is_leaf = len(subfolders) == 0 and len(subfiles) == 0
+
+ path = f[".path"]
+ filename = "/" + "/".join(path)
+ if not filename.endswith(".mk"):
+ filename += "/"
+
+ if len(path) > 0:
+ url = "wato.py?filename=" + htmllib.urlencode(filename)
+ if is_leaf:
+ title = format % (url, f["title"])
+ else:
+ title = '<a target=main href="%s">%s</a>' %
(url, f["title"])
+ else:
+ title = '<a target=main href="wato.py">%s</a>'
% f["title"]
+
+
+ if not is_leaf:
+ html.begin_foldable_container('wato', filename, False, title)
+ for sf in sort_by_title(subfolders.values()):
+ self._render_linktree_folder(sf, format)
+ for sf in sort_by_title(subfiles.values()):
+ self._render_linktree_folder(sf, format)
+ html.end_foldable_container()
+ else:
+ html.write(title)
+
def _cleanup_directory(self, thing):
# drop 'parent' entry, recursively
diff --git a/web/plugins/sidebar/wato.py b/web/plugins/sidebar/wato.py
index 8bed022..38e49d4 100644
--- a/web/plugins/sidebar/wato.py
+++ b/web/plugins/sidebar/wato.py
@@ -47,7 +47,7 @@ def render_wato_files():
def ajax_wato_files():
if config.may("use_wato"):
format = ("<li>%s</li>" % link("XX",
"XX")).replace("XX", "%s")
- wato.render_link_tree(format)
+ wato.api.render_link_tree(format)
sidebar_snapins["wato"] = {