Revision 12637df5

b/autotools/docpp
30 30
from ganeti.build import sphinx_ext
31 31

  
32 32

  
33
_QUERY_FIELDS_RE = re.compile(r"^@QUERY_FIELDS_(?P<kind>[A-Z]+)@$")
33
_DOC_RE = re.compile(r"^@(?P<class>[A-Z_]+)_(?P<kind>[A-Z]+)@$")
34

  
35
_DOC_CLASSES_DATA = {
36
  "QUERY_FIELDS": (query.ALL_FIELDS, sphinx_ext.BuildQueryFields),
37
  }
34 38

  
35 39

  
36 40
def main():
37 41
  for line in fileinput.input():
38
    m = _QUERY_FIELDS_RE.match(line)
42
    m = _DOC_RE.match(line)
39 43
    if m:
40
      fields = query.ALL_FIELDS[m.group("kind").lower()]
41
      for i in sphinx_ext.BuildQueryFields(fields):
44
      fields_dict, builder = _DOC_CLASSES_DATA[m.group("class")]
45
      fields = fields_dict[m.group("kind").lower()]
46
      for i in builder(fields):
42 47
        print i
43 48
    else:
44 49
      print line,
b/lib/build/sphinx_ext.py
270 270
  @type fields: dict (field name as key, field details as value)
271 271

  
272 272
  """
273
  for (_, (fdef, _, _, _)) in utils.NiceSort(fields.items(),
274
                                             key=compat.fst):
275
    assert len(fdef.doc.splitlines()) == 1
276
    yield "``%s``" % fdef.name
277
    yield "  %s" % fdef.doc
273
  defs = [(fdef.name, fdef.doc)
274
           for (_, (fdef, _, _, _)) in utils.NiceSort(fields.items(),
275
                                                      key=compat.fst)]
276
  yield BuildValuesDoc(defs)
277

  
278

  
279
def BuildValuesDoc(values):
280
  """Builds documentation for a list of values
281

  
282
  @type values: list of tuples in the form (value, documentation)
283

  
284
  """
285
  for name, doc in values:
286
    assert len(doc.splitlines()) == 1
287
    yield "``%s``" % name
288
    yield "  %s" % doc
278 289

  
279 290

  
280 291
# TODO: Implement Sphinx directive for query fields

Also available in: Unified diff