Joe Gregorio | 20a5aa9 | 2011-04-01 17:44:25 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | # Copyright 2007 Google Inc. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | __author__ = 'jcgregorio@google.com (Joe Gregorio)' |
| 18 | |
Joe Gregorio | afc45f2 | 2011-02-20 16:11:28 -0500 | [diff] [blame] | 19 | import os |
| 20 | import pydoc |
| 21 | import re |
Joe Gregorio | 20a5aa9 | 2011-04-01 17:44:25 -0400 | [diff] [blame] | 22 | import sys |
| 23 | import httplib2 |
Joe Gregorio | afc45f2 | 2011-02-20 16:11:28 -0500 | [diff] [blame] | 24 | |
Joe Gregorio | 20a5aa9 | 2011-04-01 17:44:25 -0400 | [diff] [blame] | 25 | from apiclient.anyjson import simplejson |
Joe Gregorio | afc45f2 | 2011-02-20 16:11:28 -0500 | [diff] [blame] | 26 | from apiclient.discovery import build |
| 27 | |
| 28 | BASE = 'docs/dyn' |
| 29 | |
Joe Gregorio | afc45f2 | 2011-02-20 16:11:28 -0500 | [diff] [blame] | 30 | def document(resource, path): |
| 31 | print path |
| 32 | collections = [] |
| 33 | for name in dir(resource): |
| 34 | if not "_" in name and callable(getattr(resource, name)) and hasattr( |
| 35 | getattr(resource, name), '__is_resource__'): |
| 36 | collections.append(name) |
| 37 | |
| 38 | obj, name = pydoc.resolve(type(resource)) |
| 39 | page = pydoc.html.page( |
| 40 | pydoc.describe(obj), pydoc.html.document(obj, name)) |
| 41 | |
| 42 | for name in collections: |
| 43 | page = re.sub('strong>(%s)<' % name, r'strong><a href="%s">\1</a><' % (path + name + ".html"), page) |
| 44 | for name in collections: |
| 45 | document(getattr(resource, name)(), path + name + ".") |
| 46 | |
| 47 | f = open(os.path.join(BASE, path + 'html'), 'w') |
| 48 | f.write(page) |
| 49 | f.close() |
| 50 | |
| 51 | def document_api(name, version): |
| 52 | service = build(name, version) |
| 53 | document(service, '%s.%s.' % (name, version)) |
| 54 | |
| 55 | if __name__ == '__main__': |
Joe Gregorio | 20a5aa9 | 2011-04-01 17:44:25 -0400 | [diff] [blame] | 56 | http = httplib2.Http() |
| 57 | resp, content = http.request('https://www.googleapis.com/discovery/v0.3/directory?preferred=true') |
| 58 | if resp.status == 200: |
| 59 | directory = simplejson.loads(content)['items'] |
| 60 | for api in directory: |
| 61 | document_api(api['name'], api['version']) |
| 62 | else: |
| 63 | sys.exit("Failed to load the discovery document.") |