Commit 12637df5 authored by Andrea Spadaccini's avatar Andrea Spadaccini
Browse files

Generalize docpp and sphinx_ext

* handle generic custom directives in the form <class>_<kind>
* adapt handling of query fields

* add the BuildValuesDoc function to output definitions using the sphinx
  syntax that was already used for query fields
* adapt BuildQueryFields to use BuildValuesDoc
Signed-off-by: default avatarAndrea Spadaccini <>
Reviewed-by: default avatarMichael Hanselmann <>
parent a0090487
......@@ -30,15 +30,20 @@ from ganeti import query
from import sphinx_ext
_QUERY_FIELDS_RE = re.compile(r"^@QUERY_FIELDS_(?P<kind>[A-Z]+)@$")
_DOC_RE = re.compile(r"^@(?P<class>[A-Z_]+)_(?P<kind>[A-Z]+)@$")
"QUERY_FIELDS": (query.ALL_FIELDS, sphinx_ext.BuildQueryFields),
def main():
for line in fileinput.input():
m = _QUERY_FIELDS_RE.match(line)
m = _DOC_RE.match(line)
if m:
fields = query.ALL_FIELDS["kind").lower()]
for i in sphinx_ext.BuildQueryFields(fields):
fields_dict, builder = _DOC_CLASSES_DATA["class")]
fields = fields_dict["kind").lower()]
for i in builder(fields):
print i
print line,
......@@ -270,11 +270,22 @@ def BuildQueryFields(fields):
@type fields: dict (field name as key, field details as value)
for (_, (fdef, _, _, _)) in utils.NiceSort(fields.items(),
assert len(fdef.doc.splitlines()) == 1
yield "``%s``" %
yield " %s" % fdef.doc
defs = [(, fdef.doc)
for (_, (fdef, _, _, _)) in utils.NiceSort(fields.items(),
yield BuildValuesDoc(defs)
def BuildValuesDoc(values):
"""Builds documentation for a list of values
@type values: list of tuples in the form (value, documentation)
for name, doc in values:
assert len(doc.splitlines()) == 1
yield "``%s``" % name
yield " %s" % doc
# TODO: Implement Sphinx directive for query fields
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment