libvirt/scripts/meson-html-gen.py
Peter Krempa 862cf2ace4 docs: build: Use proper path to file in 'contribute' link
NEWS.rst is based in the root of the repository and 'hvsupport.html'
doesn't have a backing file which can be edited since it's fully
generated. Our 'contribute -> edit this page' link on the bottom of the
page is wrong in those cases.

Fix it by adding the contribute section only when there's a source and
base the 'source' of a html file in the root of the repository.

Along with that we need to modify the scripts/meson-html-gen.py script
to accept optional 'pagesrc' and the XSL template to skip the
'contribute' section when we don't have a source.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-08-03 18:41:11 +02:00

42 lines
1.4 KiB
Python
Executable File

#!/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")
parser.add_argument("pagesrc", type=str, default="", nargs='?', help="(optional) path to source file used for edit this page")
args = parser.parse_args()
name = os.path.basename(args.htmlfile).replace('.html', '')
html_tmp = subprocess.run(
[
args.xsltproc,
'--stringparam', 'pagename', name,
'--stringparam', 'pagesrc', args.pagesrc,
'--stringparam', 'builddir', args.builddir,
'--stringparam', 'timestamp', args.timestamp,
'--nonet', args.style, args.infile,
],
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)