| 1 |
from __future__ import print_function |
| 2 |
|
| 3 |
import os |
| 4 |
import glob |
| 5 |
import re |
| 6 |
from subprocess import Popen, PIPE |
| 7 |
from xml.dom.minidom import parseString |
| 8 |
|
| 9 |
def strip_list(lst, patterns): |
| 10 |
striped = [] |
| 11 |
for p in lst: |
| 12 |
strip = 0 |
| 13 |
for pat in patterns: |
| 14 |
if pat in p: |
| 15 |
strip = 1 |
| 16 |
break |
| 17 |
if not(strip): |
| 18 |
striped.append(p) |
| 19 |
return striped |
| 20 |
|
| 21 |
|
| 22 |
def get_doc_params(docparam): |
| 23 |
xsl_params_get = \ |
| 24 |
"""<?xml version='1.0'?> |
| 25 |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'> |
| 26 |
|
| 27 |
<xsl:output method="text" indent="yes"/> |
| 28 |
|
| 29 |
<xsl:template match="programlisting"> |
| 30 |
<xsl:copy-of select="."/> |
| 31 |
</xsl:template> |
| 32 |
|
| 33 |
<xsl:template match="/"> |
| 34 |
<xsl:apply-templates select="//programlisting"/> |
| 35 |
</xsl:template> |
| 36 |
|
| 37 |
</xsl:stylesheet> |
| 38 |
""" |
| 39 |
|
| 40 |
xsltmp = "/tmp/getparam.xsl" |
| 41 |
xsl = open("/tmp/getparam.xsl", "w") |
| 42 |
xsl.write(xsl_params_get) |
| 43 |
xsl.close() |
| 44 |
|
| 45 |
p = Popen("xsltproc --xinclude %s %s" % (xsltmp, docparam), shell=True, |
| 46 |
stdout=PIPE, )#stderr=open("/dev/null", "w")) |
| 47 |
data = p.communicate()[0].split("\n") |
| 48 |
params = [] |
| 49 |
for line in data: |
| 50 |
m = re.search("<xsl:param *name=\"([^\"]*)", line) |
| 51 |
if m: |
| 52 |
params.append(m.group(1)+".xml") |
| 53 |
|
| 54 |
return params |
| 55 |
|
| 56 |
def get_xsl_params(xslextract, xsltarget): |
| 57 |
# Get the list of all the parameters |
| 58 |
p = Popen("xsltproc %s %s" % (xslextract, xsltarget), shell=True, |
| 59 |
stdout=PIPE, stderr=open("/dev/null", "w")) |
| 60 |
dom = parseString(p.communicate()[0]) |
| 61 |
|
| 62 |
params = [] |
| 63 |
for e in dom.getElementsByTagName("xsl:param"): |
| 64 |
params.append(str(e.getAttribute("name"))+".xml") |
| 65 |
return params |
| 66 |
|
| 67 |
|
| 68 |
def main(): |
| 69 |
tooldir = os.path.dirname(__file__) |
| 70 |
topdir = os.path.abspath(os.path.join(tooldir, "..")) |
| 71 |
xslextract = os.path.join(topdir, "tools", "paramextract.xsl") |
| 72 |
xsltarget = os.path.join(topdir, "xsl", "docbook.xsl") |
| 73 |
synopdir = os.path.join(topdir, "docs", "params", "syn") |
| 74 |
refentdir = os.path.join(topdir, "docs", "params") |
| 75 |
|
| 76 |
# d1 = get_doc_params(os.path.join(refentdir, "param.xml")) |
| 77 |
|
| 78 |
# parfiles |
| 79 |
parfiles = get_xsl_params(xslextract, xsltarget) |
| 80 |
|
| 81 |
# Get the list of parameter synopsis |
| 82 |
synfiles = [os.path.basename(f) for f in glob.glob("%s/*.xml" % synopdir)] |
| 83 |
|
| 84 |
# Get the list of parameter refentries |
| 85 |
reffiles = [os.path.basename(f) for f in glob.glob("%s/*.xml" % refentdir)] |
| 86 |
|
| 87 |
# Strip parameters we know are not documented |
| 88 |
tostrip = ("l10n", "olink", "chunker", "autolabel", |
| 89 |
"target.database.document", "targets.filename", |
| 90 |
"current.docid") |
| 91 |
parfiles = strip_list(parfiles, tostrip) |
| 92 |
synfiles = strip_list(synfiles, tostrip) |
| 93 |
reffiles = strip_list(reffiles, tostrip) |
| 94 |
|
| 95 |
parfiles.sort() |
| 96 |
synfiles.sort() |
| 97 |
reffiles.sort() |
| 98 |
|
| 99 |
# Strip files that are not parameter refentries |
| 100 |
for p in ("param", "template"): |
| 101 |
reffiles.remove(p+".xml") |
| 102 |
|
| 103 |
# Check if there's some missed parameters |
| 104 |
sp = set(parfiles) |
| 105 |
ss = set(synfiles) |
| 106 |
sr = set(reffiles) |
| 107 |
|
| 108 |
torem_from_syn = ss - sp |
| 109 |
print("===========") |
| 110 |
print("In param list, missing in %s:\n" % (synopdir), sp - ss) |
| 111 |
print("\nIn param list, missing in refentries:\n", sp - sr) |
| 112 |
print("\nIn synopsis, not in param list:\n", torem_from_syn) |
| 113 |
print("\nIn synopsis, missing in refentries:\n", ss - sr - torem_from_syn) |
| 114 |
print("\nIn refentries, missing in %s:\n" % (synopdir), sr - ss) |
| 115 |
|
| 116 |
|
| 117 |
if __name__ == "__main__": |
| 118 |
main() |