Skip to content

Commit

Permalink
Merge pull request #170 from amousset/ust_7844/integrate_ncf_generic_…
Browse files Browse the repository at this point in the history
…methods_reference_into_the_doc

Fixes #7844: Integrate ncf generic methods reference into the doc
  • Loading branch information
jooooooon committed Apr 27, 2016
2 parents 5ee0f42 + a12d21d commit bb6b426
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 11 deletions.
3 changes: 3 additions & 0 deletions 5_references/50_generic_methods.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
=== Generic methods

include::../generic_methods.asciidoc[]
30 changes: 21 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
## Rudder User Documentation Makefile

.PHONY: all clean view
.PHONY: all clean view ncf-doc

BASENAME = rudder-doc
SOURCES = $(BASENAME).txt
TARGETS = epub html pdf readme webhelp webhelp-localsearch
DOCBOOK_DIST = xsl/xsl-ns-stylesheets

NCF_VERSION = v0.x

ASCIIDOC = $(CURDIR)/bin/asciidoc/asciidoc.py
A2X = $(CURDIR)/bin/asciidoc/a2x.py

Expand Down Expand Up @@ -54,6 +56,7 @@ webhelp-localsearch: webhelp-localsearch/index.html index
html: html/$(BASENAME).html
pdf: html/$(BASENAME).pdf
readme: html/README.html
ncf-doc: generic-methods.asciidoc

epub/$(BASENAME).epub: $(SOURCES)
mkdir -p html
Expand All @@ -68,6 +71,15 @@ html/$(BASENAME).pdf: $(SOURCES)
rm -f *.svg
mv $(BASENAME).pdf html/

ncf:
git clone https://github.com/Normation/ncf.git

generic-methods.asciidoc: ncf
cd ncf && git pull && git checkout $(NCF_VERSION)
cp tools/ncf_doc_rudder.py ncf/tools/
./ncf/tools/ncf_doc_rudder.py
pandoc -t asciidoc -f markdown generic_methods.md > generic_methods.asciidoc

$(INDEXER_JAR):
mkdir -p $(DOCBOOK_EXTENSIONS_DIR)
wget http://central.maven.org/maven2/net/sf/docbook/docbook-xsl-webhelpindexer/1.0.1-pre/docbook-xsl-webhelpindexer-1.0.1-pre.jar -O $(INDEXER_JAR)
Expand All @@ -86,9 +98,9 @@ $(LUCENE_ANALYZER_JAR):

jars: $(INDEXER_JAR) $(TAGSOUP_JAR) $(LUCENE_ANALYZER_JAR) $(LUCENE_CORE_JAR)

webhelp/index.html: $(SOURCES)
webhelp/index.html: ncf-doc $(SOURCES)
mkdir -p webhelp
$(ASCIIDOC) --doctype=book --backend docbook $?
$(ASCIIDOC) --doctype=book --backend docbook $(SOURCES)
xsltproc --xinclude --output xincluded-profiled.xml \
$(DOCBOOK_DIST)/profiling/profile.xsl $(BASENAME).xml
xsltproc --stringparam webhelp.base.dir "webhelp" \
Expand All @@ -98,9 +110,9 @@ webhelp/index.html: $(SOURCES)
xsl/webhelp.xsl xincluded-profiled.xml
cp -r style/html/favicon.ico images template/common *.png webhelp/

webhelp-localsearch/index.html: $(SOURCES)
webhelp-localsearch/index.html: ncf-doc $(SOURCES)
mkdir -p webhelp-localsearch
$(ASCIIDOC) --doctype=book --backend docbook $?
$(ASCIIDOC) --doctype=book --backend docbook $(SOURCES)
xsltproc --xinclude --output xincluded-profiled.xml \
$(DOCBOOK_DIST)/profiling/profile.xsl $(BASENAME).xml
xsltproc --stringparam webhelp.base.dir "webhelp-localsearch" \
Expand All @@ -123,22 +135,22 @@ index: webhelp-localsearch/index.html jars
com.nexwave.nquindexer.IndexerMain
cp -r template/search/* webhelp-localsearch/search

html/$(BASENAME).html: $(SOURCES)
html/$(BASENAME).html: ncf-doc $(SOURCES)
mkdir -p html
$(ASCIIDOCTOHTML) --out-file $@ $?
$(ASCIIDOCTOHTML) --out-file $@ $(SOURCES)
cp -R style/html/* images html/

html/README.html: README.asciidoc
mkdir -p html
$(ASCIIDOCTOHTML) --out-file $@ $?

slides.html: $(SOURCES)
$(ASCIIDOC) -a theme=volnitsky --out-file slides.html --backend slidy $?
$(ASCIIDOC) -a theme=volnitsky --out-file slides.html --backend slidy $(SOURCES)

## WARNING: at cleanup, delete png files that were produced by output only !

clean:
rm -rf rudder-doc.xml *.pdf *.html *.png *.svg temp html epub webhelp webhelp-localsearch xincluded-profiled.xml $(BASENAME).xml extensions
rm -rf rudder-doc.xml *.pdf *.html *.png *.svg temp html epub webhelp webhelp-localsearch xincluded-profiled.xml $(BASENAME).xml extensions ncf generic_methods.{asciidoc,md}

view: all
$(SEE) $(TARGETS)
2 changes: 2 additions & 0 deletions README.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Inkscape:: http://inkcape.org to convert SVG for PDF output.

ImageMagick:: http://www.imagemagick.org/ to normalize the resolution of illustrations.

Pandoc:: www.pandoc.org to convert ncf markdown doc to asciidoc

=== Install the dependencies on Debian and Ubuntu:

----
Expand Down
104 changes: 104 additions & 0 deletions tools/ncf_doc_rudder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Usage: ./ncf_doc_rudder.py
#
# This is a Python module to generate documentation from generic methods in ncf to be embedded in Rudder manual

import ncf
import requests
import sys
import re
from distutils.version import StrictVersion
from pprint import pprint

# URL of the rudder_info api
release_info_url = "http://www.rudder-project.org/release-info/rudder/"

def get_min_versions():
"Build the dictionnary of minimal Rudder version including compatibility with a given CFEngine version"
min_version = {}

try:
versions = requests.get(release_info_url + "versions").content.decode('ascii').splitlines()
except requests.exceptions.RequestException as e:
print(e)
sys.exit(1)

for rudder_version in versions:
try:
cfengine_version = requests.get(release_info_url + "versions/" + rudder_version + "/components/cfengine").content.decode('ascii')
except requests.exceptions.RequestException as e:
print(e)
sys.exit(1)

if cfengine_version in min_version:
if StrictVersion(rudder_version) >= StrictVersion(min_version[cfengine_version]):
continue
min_version[cfengine_version] = rudder_version

return min_version

def rudder_version(min_version, version):
"""Extract minimal Rudder version"""
canonified_version = re.findall(r'>=? ?(\d+\.\d+)', version)[0]

cfengine_versions = list(min_version.keys())
cfengine_versions.sort(key=StrictVersion)

for cfengine_version in cfengine_versions:
if StrictVersion(canonified_version) <= StrictVersion(cfengine_version):
return min_version[cfengine_version]
return False


if __name__ == '__main__':
# Get CFEngine <=> Rudder versions
versions = get_min_versions()

# Get all generic methods
generic_methods = ncf.get_all_generic_methods_metadata()["data"]

categories = {}
for method_name in sorted(generic_methods.keys()):
category_name = method_name.split('_',1)[0]
generic_method = generic_methods[method_name]
if (category_name in categories):
categories[category_name].append(generic_method)
else:
categories[category_name] = [generic_method]

content = []

for category in sorted(categories.keys()):
content.append("\n*****\n")
content.append('\n### '+category.title())

# Generate markdown for each generic method
for generic_method in categories[category]:
# do not display generic methods not compatible with a released Rudder version
rudder_version_needed = rudder_version(versions, generic_method["agent_version"])
if not rudder_version_needed:
continue
content.append("\n*****\n")
bundle_name = generic_method["bundle_name"]
content.append('\n#### '+ bundle_name)
content.append(generic_method["description"])
content.append('\nCompatible with nodes running Rudder '+rudder_version_needed+' or higher.')

if "documentation" in generic_method:
content.append('\n##### Usage')
content.append(generic_method["documentation"])
content.append('\n##### Parameters')
for parameter in generic_method["parameter"]:
content.append("* **" + parameter['name'] + "**: " + parameter['description'])
content.append('\n##### Classes defined')
content.append('\n```\n')
content.append(generic_method["class_prefix"]+"_${"+generic_method["class_parameter"] + "}_{kept, repaired, not_ok, reached}")
content.append('\n```\n')

# Write generic_methods.md
result = '\n'.join(content)+"\n"
outfile = open("generic_methods.md","w")
outfile.write(result)
outfile.close()
6 changes: 4 additions & 2 deletions xsl/webhelp-common.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ xmlns:exsl="http://exslt.org/common"
<xsl:param name="admon.graphics" select="1"/>
<!--xsl:param name="generate.toc">book toc</xsl:param-->
<xsl:param name="webhelp.include.search.tab" select="0"/>

<xsl:param name="generate.toc">
appendix toc,title
article/appendix nop
Expand All @@ -86,7 +86,9 @@ set toc,title
<!-- Localizations of webhelp specific words. Your contributions for other languages are appreciated.
Currently, only around 10 translations needed. -->
<!-- Moved to files under 'gentext/locale/', search for WebHelp -->

<xsl:template match="processing-instruction('asciidoc-hr')">
<hr/>
</xsl:template>
<xsl:template name="user.head.title">
<xsl:param name="node" select="."/>
<xsl:param name="title">
Expand Down

0 comments on commit bb6b426

Please sign in to comment.