Module: check_mk
Branch: master
Commit: 38206f92c765c07da09358c9e73a839fcf4aaedb
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=38206f92c765c0…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Sep 23 12:56:00 2016 +0200
Removed nowiki special case for man pages from Check_MK
---
lib/man_pages.py | 48 +++++++++++++++++++++++++++++----------------
modules/check_mk.py | 10 ++--------
tests/lib/test_man_pages.py | 25 ++++++++++++++++-------
3 files changed, 51 insertions(+), 32 deletions(-)
diff --git a/lib/man_pages.py b/lib/man_pages.py
index 67c1639..ad0a5f7 100644
--- a/lib/man_pages.py
+++ b/lib/man_pages.py
@@ -34,6 +34,7 @@ Linux/Unix man pages"""
import os
import re
import sys
+import StringIO
import subprocess
import time
@@ -202,6 +203,7 @@ check_mk_agents = {
"vsphere" : "vSphere"
}
+
def man_page_exists(name):
return man_page_path(name) != None
@@ -497,10 +499,6 @@ def load_man_page(name):
return man_page
-def print_man_page_nowiki(name):
- NowikiManPageRenderer(name).paint()
-
-
def print_man_page(name):
renderer = ConsoleManPageRenderer(name)
renderer.init_output()
@@ -525,22 +523,26 @@ class ManPageRenderer(object):
self._parameters_color = tty.colorset(6, 4, 1)
self._examples_color = tty.colorset(6, 4, 1)
+ self._load()
- def paint(self):
- man_page = load_man_page(self.name)
- if not man_page:
+
+ def _load(self):
+ self.man_page = load_man_page(self.name)
+ if not self.man_page:
sys.stdout.write("ERROR: No manpage for %s. Sorry.\n" % self.name)
return
+
+ def paint(self):
try:
- self._paint_man_page(man_page)
+ self._paint_man_page()
except Exception, e:
sys.stdout.write("ERROR: Invalid check manpage %s: %s\n" %
(self.name, e))
- def _paint_man_page(self, man_page):
+ def _paint_man_page(self):
self._print_header()
- header = man_page['header']
+ header = self.man_page['header']
self._print_sectionheader(header['title'])
@@ -563,10 +565,10 @@ class ManPageRenderer(object):
self._print_textbody(header['item'])
self._print_subheader("Check parameters")
- if man_page.has_key('parameters'):
+ if self.man_page.has_key('parameters'):
self._begin_table(["Parameter", "Type",
"Description"])
first = True
- for parameter_name, text in man_page['parameters']:
+ for parameter_name, text in self.man_page['parameters']:
if not first:
self._print_empty_line()
first = False
@@ -588,10 +590,10 @@ class ManPageRenderer(object):
self._print_textbody("No inventory supported.")
self._print_subheader("Configuration variables")
- if man_page.has_key('configuration'):
+ if self.man_page.has_key('configuration'):
self._begin_table(["Variable", "Type",
"Description"])
first = True
- for conf_name, text in man_page['configuration']:
+ for conf_name, text in self.man_page['configuration']:
if not first:
self._print_empty_line()
first = False
@@ -818,6 +820,21 @@ class ConsoleManPageRenderer(ManPageRenderer):
class NowikiManPageRenderer(ManPageRenderer):
+ def __init__(self, name):
+ super(NowikiManPageRenderer, self).__init__(name)
+ self.output = StringIO.StringIO()
+
+
+ def index_entry(self):
+ return "<tr><td
class=tt>%s</td><td>[check_%s|%s]</td></tr>\n" % \
+ (self.name, self.name,
self.man_page["header"]["title"])
+
+
+ def render(self):
+ self.paint()
+ return self.output.getvalue()
+
+
def _markup(self, line, ignored=None):
# preserve the inner { and } in double braces and then replace the braces left
return line.replace('{{', '{{') \
@@ -834,9 +851,6 @@ class NowikiManPageRenderer(ManPageRenderer):
def _print_sectionheader(self, title):
self.output.write("H1:%s\n" % title)
- # Be aware: the entry for the "index" goes to stderr. What a hack.
- sys.stderr.write("<tr><td
class=tt>%s</td><td>[check_%s|%s]</td></tr>\n" %
- (self.name, self.name, title))
def _print_subheader(self, line):
diff --git a/modules/check_mk.py b/modules/check_mk.py
index fedbcbc..795d156 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -4593,7 +4593,6 @@ def output_profile():
register_sigint_handler()
load_checks()
-opt_nowiki = False
opt_split_rrds = False
opt_delete_rrds = False
opt_log_to_stdout = False
@@ -4608,7 +4607,7 @@ long_options = [ "help", "version",
"verbose", "compile", "debug", "interactive"
"snmpget=", "profile", "keepalive",
"keepalive-fd=", "create-rrd",
"convert-rrds", "compress-history",
"split-rrds", "delete-rrds",
"no-cache", "update", "restart",
"reload", "dump", "fake-dns=",
- "man", "nowiki", "config-check",
"backup=", "restore=",
+ "man", "config-check", "backup=",
"restore=",
"check-inventory=", "check-discovery=",
"discover-marked-hosts", "paths",
"checks=", "inventory",
"inventory-as-check=", "hw-changes=", "sw-changes=",
"sw-missing=",
"inv-fail-status=", "cmc-file=",
"browse-man", "list-man", "update-dns-cache",
"cap", "real-time-checks",
@@ -4676,8 +4675,6 @@ for o,a in opts:
opt_extra_oids.append(a)
elif o == '--procs':
max_num_processes = int(a)
- elif o == '--nowiki':
- opt_nowiki = True
elif o == '--debug':
opt_debug = True
elif o == '--interactive':
@@ -4780,10 +4777,7 @@ try:
done = True
elif o in [ '-M', '--man' ]:
if args:
- if opt_nowiki:
- man_pages.print_man_page_nowiki(args[0])
- else:
- man_pages.print_man_page(args[0])
+ man_pages.print_man_page(args[0])
else:
man_pages.print_man_page_table()
done = True
diff --git a/tests/lib/test_man_pages.py b/tests/lib/test_man_pages.py
index a3ac723..a28ae73 100644
--- a/tests/lib/test_man_pages.py
+++ b/tests/lib/test_man_pages.py
@@ -144,16 +144,27 @@ def test_load_man_page_format():
assert len(entry) == 2
-def test_print_man_page_nowiki(capsys):
- man_pages.print_man_page_nowiki("if64")
+def test_print_man_page_nowiki_index(capsys):
+ renderer = man_pages.NowikiManPageRenderer("if64")
+ index_entry = renderer.index_entry()
out, err = capsys.readouterr()
+ assert out == ""
+ assert err == ""
+
+ assert "<tr>" in index_entry
+ assert "[check_if64|" in index_entry
+
- # Entry for index page
- assert "<tr>" in err
- assert "[check_if64|" in err
- assert out.startswith("TI:")
- assert "\nH1:" in out
+def test_print_man_page_nowiki_content(capsys):
+ renderer = man_pages.NowikiManPageRenderer("if64")
+ content = renderer.render()
+ out, err = capsys.readouterr()
+ assert out == ""
+ assert err == ""
+
+ assert content.startswith("TI:")
+ assert "\nH1:" in content
def test_print_man_page(capsys):