From 6be8e2bfd1e7dc7a6ab10f5df784cd9f69db21ea Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Sat, 13 Nov 2010 20:41:14 +0100
Subject: [PATCH] Switch man pages from SGML to RST
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This patch changes the Makefile rules to build the man pages from the
RST sources instead of the SGML ones.

Note: pandoc quotes by default the β€˜@’ character in manpage output, so
we explicitely undo this before writing the .in file.

Note 2: The docs unittest has switched from checking cmdsynopsis
elements to search for either '**command**' or '| **command**' at the
beggining of lines. This is not as safe as the sgml checker, but it
should be fine.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: RenΓ© Nussbaumer <rn@google.com>
---
 Makefile.am           | 36 ++++++++++++++++++++++--------------
 test/docs_unittest.py |  6 +++---
 2 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 4f8e66b57..411caa98c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -365,8 +365,8 @@ EXTRA_DIST = \
 	test/mocks.py \
 	$(dist_TESTS) \
 	$(TEST_FILES) \
-	man/footer.sgml man/footer.rst \
-	$(mansgml) \
+	man/footer.rst \
+	$(manrst) \
 	$(maninput) \
 	qa/ganeti-qa.py \
 	qa/qa-sample.json \
@@ -399,12 +399,12 @@ man_MANS = \
 	man/gnt-node.8 \
 	man/gnt-os.8
 
-mansgml = $(patsubst %.7,%.sgml,$(patsubst %.8,%.sgml,$(man_MANS)))
-manhtml = $(patsubst %.sgml,%.html,$(mansgml))
+manrst = $(patsubst %.7,%.rst,$(patsubst %.8,%.rst,$(man_MANS)))
+manhtml = $(patsubst %.rst,%.html,$(manrst))
 maninput = \
 	$(patsubst %.7,%.7.in,$(patsubst %.8,%.8.in,$(man_MANS))) \
 	$(patsubst %.html,%.html.in,$(manhtml)) \
-	man/footer.man
+	man/footer.man man/footer.html
 
 TEST_FILES = \
 	test/data/bdev-drbd-8.0.txt \
@@ -495,7 +495,7 @@ all_python_code = \
 	$(noinst_PYTHON)
 
 srclink_files = \
-	man/footer.sgml man/footer.rst \
+	man/footer.rst \
 	test/check-cert-expired_unittest.bash \
 	test/daemon-util_unittest.bash \
 	test/ganeti-cleaner_unittest.bash \
@@ -546,16 +546,24 @@ man/footer.man: man/footer.rst
 	  { echo 'pandoc' not found during configure; exit 1; }
 	$(PANDOC) -f rst -t man -o $@ $<
 
-man/%.7.in man/%.8.in: man/%.sgml man/footer.sgml $(DOCBOOK_WRAPPER)
-	@test -n "$(DOCBOOK2MAN)" || \
-	  { echo 'docbook2man' not found during configure; exit 1; }
-	$(DOCBOOK_WRAPPER) "$(DOCBOOK2MAN)" $< $(notdir $(@:.in=)) $@
+man/footer.html: man/footer.rst
+	@test -n "$(PANDOC)" || \
+	  { echo 'pandoc' not found during configure; exit 1; }
+	$(PANDOC) -f rst -t html -o $@ $<
+
+man/%.7.in man/%.8.in: man/%.rst man/footer.man
+	@test -n "$(PANDOC)" || \
+	  { echo 'pandoc' not found during configure; exit 1; }
+	$(PANDOC) -s -f rst -t man -A man/footer.man $< | \
+	  sed -e 's/\\@/@/g' > $@
 	if test -n "$(MAN_HAS_WARNINGS)"; then $(CHECK_MAN) $@; fi
 
-man/%.html.in: man/%.sgml man/footer.sgml $(DOCBOOK_WRAPPER)
-	@test -n "$(DOCBOOK2HTML)" || \
-	  { echo 'docbook2html' not found during configure; exit 1; }
-	$(DOCBOOK_WRAPPER) "$(DOCBOOK2HTML) --nochunks" $< $(notdir $(@:.in=)) $@
+man/%.html.in: man/%.rst man/footer.html
+	@test -n "$(PANDOC)" || \
+	  { echo 'pandoc' not found during configure; exit 1; }
+	$(PANDOC) -s -f rst -t html -A man/footer.html $< | \
+	  sed -e 's/\\@/@/g' > $@
+
 
 man/%.7: man/%.7.in $(REPLACE_VARS_SED)
 	sed -f $(REPLACE_VARS_SED) < $< > $@
diff --git a/test/docs_unittest.py b/test/docs_unittest.py
index 03278d363..5be823b2d 100755
--- a/test/docs_unittest.py
+++ b/test/docs_unittest.py
@@ -131,7 +131,7 @@ class TestManpages(unittest.TestCase):
 
   @staticmethod
   def _ReadManFile(name):
-    return utils.ReadFile("%s/man/%s.sgml" %
+    return utils.ReadFile("%s/man/%s.rst" %
                           (testutils.GetSourceDir(), name))
 
   @staticmethod
@@ -148,8 +148,8 @@ class TestManpages(unittest.TestCase):
     missing = []
 
     for cmd in commands:
-      pattern = "<cmdsynopsis>\s*<command>%s</command>" % re.escape(cmd)
-      if not re.findall(pattern, mantext, re.S):
+      pattern = r"^(\| )?\*\*%s\*\*" % re.escape(cmd)
+      if not re.findall(pattern, mantext, re.DOTALL | re.MULTILINE):
         missing.append(cmd)
 
     self.failIf(missing,
-- 
GitLab