root / doc / build-rapi-resources-doc @ 5d672980
History | View | Annotate | Download (2.3 kB)
1 | 4cbd4462 | Oleksiy Mishchenko | #!/usr/bin/python |
---|---|---|---|
2 | 4cbd4462 | Oleksiy Mishchenko | # |
3 | 4cbd4462 | Oleksiy Mishchenko | |
4 | 4cbd4462 | Oleksiy Mishchenko | # Copyright (C) 2008 Google Inc. |
5 | 4cbd4462 | Oleksiy Mishchenko | # |
6 | 4cbd4462 | Oleksiy Mishchenko | # This program is free software; you can redistribute it and/or modify |
7 | 4cbd4462 | Oleksiy Mishchenko | # it under the terms of the GNU General Public License as published by |
8 | 4cbd4462 | Oleksiy Mishchenko | # the Free Software Foundation; either version 2 of the License, or |
9 | 4cbd4462 | Oleksiy Mishchenko | # (at your option) any later version. |
10 | 4cbd4462 | Oleksiy Mishchenko | # |
11 | 4cbd4462 | Oleksiy Mishchenko | # This program is distributed in the hope that it will be useful, but |
12 | 4cbd4462 | Oleksiy Mishchenko | # WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | 4cbd4462 | Oleksiy Mishchenko | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | 4cbd4462 | Oleksiy Mishchenko | # General Public License for more details. |
15 | 4cbd4462 | Oleksiy Mishchenko | # |
16 | 4cbd4462 | Oleksiy Mishchenko | # You should have received a copy of the GNU General Public License |
17 | 4cbd4462 | Oleksiy Mishchenko | # along with this program; if not, write to the Free Software |
18 | 4cbd4462 | Oleksiy Mishchenko | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
19 | 4cbd4462 | Oleksiy Mishchenko | # 02110-1301, USA. |
20 | 4cbd4462 | Oleksiy Mishchenko | |
21 | 4cbd4462 | Oleksiy Mishchenko | """Script to generate documentation for remote API resources. |
22 | 4cbd4462 | Oleksiy Mishchenko | |
23 | 4cbd4462 | Oleksiy Mishchenko | """ |
24 | 4cbd4462 | Oleksiy Mishchenko | |
25 | 4cbd4462 | Oleksiy Mishchenko | import re |
26 | 4cbd4462 | Oleksiy Mishchenko | import cgi |
27 | 4cbd4462 | Oleksiy Mishchenko | import inspect |
28 | 4cbd4462 | Oleksiy Mishchenko | |
29 | 10b207d4 | Oleksiy Mishchenko | from ganeti.rapi import rlib1 |
30 | 10b207d4 | Oleksiy Mishchenko | from ganeti.rapi import rlib2 |
31 | 10b207d4 | Oleksiy Mishchenko | from ganeti.rapi import connector |
32 | 4cbd4462 | Oleksiy Mishchenko | |
33 | 4cbd4462 | Oleksiy Mishchenko | |
34 | 4cbd4462 | Oleksiy Mishchenko | CHECKED_COMMANDS = ["GET", "POST", "PUT", "DELETE"] |
35 | 4cbd4462 | Oleksiy Mishchenko | |
36 | 4cbd4462 | Oleksiy Mishchenko | |
37 | 4cbd4462 | Oleksiy Mishchenko | def main(): |
38 | 4cbd4462 | Oleksiy Mishchenko | # Get list of all resources |
39 | 10b207d4 | Oleksiy Mishchenko | all = list(connector.CONNECTOR.itervalues()) |
40 | 4cbd4462 | Oleksiy Mishchenko | |
41 | 10b207d4 | Oleksiy Mishchenko | # Sort rlib1 by URI |
42 | 4cbd4462 | Oleksiy Mishchenko | all.sort(cmp=lambda a, b: cmp(a.DOC_URI, b.DOC_URI)) |
43 | 4cbd4462 | Oleksiy Mishchenko | |
44 | 4cbd4462 | Oleksiy Mishchenko | print "<!-- Automatically generated, do not edit -->" |
45 | 4cbd4462 | Oleksiy Mishchenko | |
46 | 4cbd4462 | Oleksiy Mishchenko | for cls in all: |
47 | 4cbd4462 | Oleksiy Mishchenko | print "<sect2>" |
48 | 4cbd4462 | Oleksiy Mishchenko | print "<title>%s</title>" % cgi.escape(cls.DOC_URI) |
49 | 4cbd4462 | Oleksiy Mishchenko | |
50 | 4cbd4462 | Oleksiy Mishchenko | # Class docstring |
51 | 4cbd4462 | Oleksiy Mishchenko | description = inspect.getdoc(cls) |
52 | 4cbd4462 | Oleksiy Mishchenko | if description: |
53 | 4cbd4462 | Oleksiy Mishchenko | print ("<literallayout>%s</literallayout>" % |
54 | 4cbd4462 | Oleksiy Mishchenko | cgi.escape(description.strip())) |
55 | 4cbd4462 | Oleksiy Mishchenko | |
56 | 4cbd4462 | Oleksiy Mishchenko | print '<informaltable><tgroup cols="2">' |
57 | 4cbd4462 | Oleksiy Mishchenko | print '<colspec colwidth="1*">' |
58 | 4cbd4462 | Oleksiy Mishchenko | print '<colspec colwidth="5*">' |
59 | 4cbd4462 | Oleksiy Mishchenko | print "<thead>" |
60 | 4cbd4462 | Oleksiy Mishchenko | print " <row>" |
61 | 4cbd4462 | Oleksiy Mishchenko | print " <entry>Method</entry>" |
62 | 4cbd4462 | Oleksiy Mishchenko | print " <entry>Description</entry>" |
63 | 4cbd4462 | Oleksiy Mishchenko | print " </row>" |
64 | 4cbd4462 | Oleksiy Mishchenko | print "</thead>" |
65 | 4cbd4462 | Oleksiy Mishchenko | print '<tbody valign="top">' |
66 | 4cbd4462 | Oleksiy Mishchenko | |
67 | 4cbd4462 | Oleksiy Mishchenko | for cmd in CHECKED_COMMANDS: |
68 | 4cbd4462 | Oleksiy Mishchenko | if not hasattr(cls, cmd): |
69 | 4cbd4462 | Oleksiy Mishchenko | continue |
70 | 4cbd4462 | Oleksiy Mishchenko | |
71 | 4cbd4462 | Oleksiy Mishchenko | # Get docstring |
72 | 4cbd4462 | Oleksiy Mishchenko | text = inspect.getdoc(getattr(cls, cmd)) |
73 | 4cbd4462 | Oleksiy Mishchenko | if not text: |
74 | 4cbd4462 | Oleksiy Mishchenko | text = "" |
75 | 4cbd4462 | Oleksiy Mishchenko | |
76 | 4cbd4462 | Oleksiy Mishchenko | print "<row>" |
77 | 4cbd4462 | Oleksiy Mishchenko | print " <entry>%s</entry>" % cgi.escape(cmd) |
78 | 4cbd4462 | Oleksiy Mishchenko | print (" <entry><literallayout>%s</literallayout></entry>" % |
79 | 4cbd4462 | Oleksiy Mishchenko | cgi.escape(text.strip())) |
80 | 4cbd4462 | Oleksiy Mishchenko | print "</row>" |
81 | 4cbd4462 | Oleksiy Mishchenko | |
82 | 4cbd4462 | Oleksiy Mishchenko | print "</tbody>" |
83 | 4cbd4462 | Oleksiy Mishchenko | print "</tgroup></informaltable>" |
84 | 4cbd4462 | Oleksiy Mishchenko | |
85 | 4cbd4462 | Oleksiy Mishchenko | print "</sect2>" |
86 | 4cbd4462 | Oleksiy Mishchenko | |
87 | 4cbd4462 | Oleksiy Mishchenko | |
88 | 4cbd4462 | Oleksiy Mishchenko | if __name__ == "__main__": |
89 | 4cbd4462 | Oleksiy Mishchenko | main() |