diff --git a/5_references/50_generic_methods.txt b/5_references/50_generic_methods.txt new file mode 100644 index 00000000..bbe8f11a --- /dev/null +++ b/5_references/50_generic_methods.txt @@ -0,0 +1,3 @@ +=== Generic methods + +include::../generic_methods.asciidoc[] \ No newline at end of file diff --git a/Makefile b/Makefile index bd636ada..39560926 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 @@ -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) @@ -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" \ @@ -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" \ @@ -123,9 +135,9 @@ 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 @@ -133,12 +145,12 @@ html/README.html: README.asciidoc $(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) diff --git a/README.asciidoc b/README.asciidoc index 38ab06be..46460482 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -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: ---- diff --git a/tools/ncf_doc_rudder.py b/tools/ncf_doc_rudder.py new file mode 100755 index 00000000..c336e7ac --- /dev/null +++ b/tools/ncf_doc_rudder.py @@ -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() diff --git a/xsl/webhelp-common.xsl b/xsl/webhelp-common.xsl index d7c5d98d..cd4f0781 100644 --- a/xsl/webhelp-common.xsl +++ b/xsl/webhelp-common.xsl @@ -62,7 +62,7 @@ xmlns:exsl="http://exslt.org/common" - + appendix toc,title article/appendix nop @@ -86,7 +86,9 @@ set toc,title - + +
+