Import design doc for commandline arguments
[ganeti-local] / doc / build-rapi-resources-doc
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 rlib1
30 from ganeti.rapi import rlib2
31 from ganeti.rapi import connector 
32
33
34 CHECKED_COMMANDS = ["GET", "POST", "PUT", "DELETE"]
35
36
37 def main():
38   # Get list of all resources
39   all = list(connector.CONNECTOR.itervalues())
40
41   # Sort rlib1 by URI
42   all.sort(cmp=lambda a, b: cmp(a.DOC_URI, b.DOC_URI))
43
44   print "<!-- Automatically generated, do not edit -->"
45
46   for cls in all:
47     print "<sect2>"
48     print "<title>%s</title>" % cgi.escape(cls.DOC_URI)
49
50     # Class docstring
51     description = inspect.getdoc(cls)
52     if description:
53       print ("<literallayout>%s</literallayout>" %
54              cgi.escape(description.strip()))
55
56     print '<informaltable><tgroup cols="2">'
57     print '<colspec colwidth="1*">'
58     print '<colspec colwidth="5*">'
59     print "<thead>"
60     print "  <row>"
61     print "    <entry>Method</entry>"
62     print "    <entry>Description</entry>"
63     print "  </row>"
64     print "</thead>"
65     print '<tbody valign="top">'
66
67     for cmd in CHECKED_COMMANDS:
68       if not hasattr(cls, cmd):
69         continue
70
71       # Get docstring
72       text = inspect.getdoc(getattr(cls, cmd))
73       if not text:
74         text = ""
75
76       print "<row>"
77       print "  <entry>%s</entry>" % cgi.escape(cmd)
78       print ("  <entry><literallayout>%s</literallayout></entry>" %
79              cgi.escape(text.strip()))
80       print "</row>"
81
82     print "</tbody>"
83     print "</tgroup></informaltable>"
84
85     print "</sect2>"
86
87
88 if __name__ == "__main__":
89   main()