blob: fd8c89d41daff7c6704651a9f450443291d72d36 [file] [log] [blame]
Joe Gregorio20a5aa92011-04-01 17:44:25 -04001#!/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 Gregorioafc45f22011-02-20 16:11:28 -050019import os
20import pydoc
21import re
Joe Gregorio20a5aa92011-04-01 17:44:25 -040022import sys
23import httplib2
Joe Gregorioafc45f22011-02-20 16:11:28 -050024
Joe Gregorio20a5aa92011-04-01 17:44:25 -040025from apiclient.anyjson import simplejson
Joe Gregorioafc45f22011-02-20 16:11:28 -050026from apiclient.discovery import build
27
28BASE = 'docs/dyn'
29
Joe Gregorioafc45f22011-02-20 16:11:28 -050030def 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
51def document_api(name, version):
52 service = build(name, version)
53 document(service, '%s.%s.' % (name, version))
54
55if __name__ == '__main__':
Joe Gregorio20a5aa92011-04-01 17:44:25 -040056 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.")