Statistics
| Branch: | Tag: | Revision:

root / doc / build-rapi-resources-doc @ 4e5a68f8

History | View | Annotate | Download (2.3 kB)

1
#!/usr/bin/python
2
#
3

    
4
# Copyright (C) 2008 Google Inc.
5
#
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
# General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
# 02110-1301, USA.
20

    
21
"""Script to generate documentation for remote API resources.
22

    
23
"""
24

    
25
import re
26
import cgi
27
import inspect
28

    
29
from ganeti.rapi import rlib2
30
from ganeti.rapi import connector
31

    
32

    
33
CHECKED_COMMANDS = ["GET", "POST", "PUT", "DELETE"]
34

    
35

    
36
def main():
37
  # Get list of all resources
38
  all = list(connector.CONNECTOR.itervalues())
39

    
40
  # Sort rlib by URI
41
  all.sort(cmp=lambda a, b: cmp(a.DOC_URI, b.DOC_URI))
42

    
43
  print "<!-- Automatically generated, do not edit -->"
44

    
45
  for cls in all:
46
    print "<sect2>"
47
    print "<title>%s</title>" % cgi.escape(cls.DOC_URI)
48

    
49
    # Class docstring
50
    description = inspect.getdoc(cls)
51
    if description:
52
      print ("<literallayout>%s</literallayout>" %
53
             cgi.escape(description.strip()))
54

    
55
    print '<informaltable><tgroup cols="2">'
56
    print '<colspec colwidth="1*">'
57
    print '<colspec colwidth="5*">'
58
    print "<thead>"
59
    print "  <row>"
60
    print "    <entry>Method</entry>"
61
    print "    <entry>Description</entry>"
62
    print "  </row>"
63
    print "</thead>"
64
    print '<tbody valign="top">'
65

    
66
    for cmd in CHECKED_COMMANDS:
67
      if not hasattr(cls, cmd):
68
        continue
69

    
70
      # Get docstring
71
      text = inspect.getdoc(getattr(cls, cmd))
72
      if not text:
73
        text = ""
74

    
75
      print "<row>"
76
      print "  <entry>%s</entry>" % cgi.escape(cmd)
77
      print ("  <entry><literallayout>%s</literallayout></entry>" %
78
             cgi.escape(text.strip()))
79
      print "</row>"
80

    
81
    print "</tbody>"
82
    print "</tgroup></informaltable>"
83

    
84
    print "</sect2>"
85

    
86

    
87
if __name__ == "__main__":
88
  main()