4 # Copyright (C) 2008 Google Inc.
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.
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.
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
21 """Script to generate documentation for remote API resources.
23 This is hard-coded to the section numbering we have in the master RST
32 from ganeti.rapi import rlib2
33 from ganeti.rapi import connector
36 CHECKED_COMMANDS = ["GET", "POST", "PUT", "DELETE"]
40 """A couple of small enhancements, epydoc-to-rst.
44 ("@return:", "Returns:"),
47 for old, new in pairs:
48 text = text.replace(old, new)
54 """Returns a text block with all lines indented.
57 lines = text.splitlines()
58 lines = [" " + l for l in lines]
59 return "\n".join(lines)
63 # Get list of all resources
64 all = list(connector.CONNECTOR.itervalues())
67 all.sort(cmp=lambda a, b: cmp(a.DOC_URI, b.DOC_URI))
69 print ".. Automatically generated, do not edit\n"
73 print "%s\n%s\n" % (title, "+" * len(title))
76 description = inspect.getdoc(cls)
79 print indent(description.strip())
81 supported = [cmd for cmd in CHECKED_COMMANDS if hasattr(cls, cmd)]
82 print "It supports the following commands: %s." % (", ".join(supported))
85 for cmd in CHECKED_COMMANDS:
86 if not hasattr(cls, cmd):
89 print "%s\n%s\n" % (cmd, "~" * len(cmd))
92 text = inspect.getdoc(getattr(cls, cmd))
100 if __name__ == "__main__":