[libvirt PATCH 321/351] meson: docs: introduce meson-html-gen.py helper

Pavel Hrdina phrdina at redhat.com
Thu Jul 16 09:59:17 UTC 2020


Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
---
 docs/Makefile.am          | 26 ---------------------
 scripts/meson-html-gen.py | 49 +++++++++++++++++++++++++++++++++++++++
 scripts/meson.build       |  1 +
 3 files changed, 50 insertions(+), 26 deletions(-)
 create mode 100755 scripts/meson-html-gen.py

diff --git a/docs/Makefile.am b/docs/Makefile.am
index a2fe2fbdc75..0c42db2badb 100644
--- a/docs/Makefile.am
+++ b/docs/Makefile.am
@@ -320,32 +320,6 @@ news.html.in: $(top_srcdir)/NEWS.rst
 	$(AM_V_GEN)$(MKDIR_P) `dirname $@` && \
 	  $(RST2HTML) --strict $< > $@ || { rm $@ && exit 1; }
 
-%.html.tmp: %.html.in site.xsl subsite.xsl page.xsl \
-		$(acl_generated)
-	$(AM_V_GEN)name=`echo $@ | sed -e 's/.tmp//'`; \
-	  genhtmlin=`echo $@ | sed -e 's/.tmp/.in/'`; \
-	  rst=`echo $@ | sed -e 's/.html.tmp/.rst/'`; \
-	  src="$$genhtmlin"; \
-	  test -f "$$genhtmlin" && src="$$rst"; \
-	  dir=`dirname $@` ; \
-	  if test "$$dir" = "."; \
-	  then \
-	    style=site.xsl; \
-	  else \
-	    $(MKDIR_P) $$dir; \
-	    style=subsite.xsl; \
-	  fi; \
-	  $(XSLTPROC) --stringparam pagename $$name \
-	    --stringparam pagesrc $$src \
-	    --stringparam builddir '$(abs_top_builddir)' \
-	    --stringparam timestamp $(timestamp) --nonet \
-	    $(top_srcdir)/docs/$$style $< > $@ \
-	    || { rm $@ && exit 1; }
-
-%.html: %.html.tmp
-	$(AM_V_GEN)$(XMLLINT) --nonet --format $< > $@ \
-	  || { rm $@ && exit 1; }
-
 $(apihtml_generated): html/index.html
 $(apiadminhtml_generated): html/index-admin.html
 $(apiqemuhtml_generated): html/index-qemu.html
diff --git a/scripts/meson-html-gen.py b/scripts/meson-html-gen.py
new file mode 100755
index 00000000000..9ac649a9ef7
--- /dev/null
+++ b/scripts/meson-html-gen.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python3
+
+import argparse
+import os
+import subprocess
+
+parser = argparse.ArgumentParser()
+parser.add_argument("xsltproc", type=str, help="path to xsltproc bin")
+parser.add_argument("xmllint", type=str, help="path to xmllint bin")
+parser.add_argument("builddir", type=str, help="build root dir path")
+parser.add_argument("timestamp", type=str, help="docs timestamp")
+parser.add_argument("style", type=str, help="XSL stile file")
+parser.add_argument("infile", type=str, help="path to source HTML file")
+parser.add_argument("htmlfile", type=str, help="path to generated HTML file")
+args = parser.parse_args()
+
+name = os.path.basename(args.htmlfile).replace('.html', '')
+
+pagesrc = args.infile
+rstfile = pagesrc.replace('.html.in', '.rst')
+if os.path.exists(rstfile):
+    pagesrc = rstfile
+
+with open(args.infile, 'rb') as infile:
+    html_in_data = infile.read()
+
+html_tmp = subprocess.run(
+    [
+        args.xsltproc,
+        '--stringparam', 'pagename', name,
+        '--stringparam', 'pagesrc', pagesrc,
+        '--stringparam', 'builddir', args.builddir,
+        '--stringparam', 'timestamp', args.timestamp,
+        '--nonet', args.style, '-',
+    ],
+    input=html_in_data,
+    stdout=subprocess.PIPE,
+    stderr=subprocess.PIPE,
+)
+
+html = subprocess.run(
+    [args.xmllint, '--nonet', '--format', '-'],
+    input=html_tmp.stdout,
+    stdout=subprocess.PIPE,
+    stderr=subprocess.PIPE,
+)
+
+with open(args.htmlfile, 'wb') as outfile:
+    outfile.write(html.stdout)
diff --git a/scripts/meson.build b/scripts/meson.build
index 12d18b8ce52..3bcd6e85ce5 100644
--- a/scripts/meson.build
+++ b/scripts/meson.build
@@ -23,6 +23,7 @@ scripts = [
   'hyperv_wmi_generator.py',
   'install-dirs.sh',
   'install-symlink.sh',
+  'meson-html-gen.py',
   'meson-python.sh',
   'meson-timestamp.sh',
   'mock-noinline.py',
-- 
2.26.2




More information about the libvir-list mailing list