|
1 | | -#!/usr/bin/env python |
| 1 | +#!/usr/bin/python |
2 | 2 | # |
3 | 3 | # Copyright 2012 Google Inc. |
4 | 4 | # |
|
23 | 23 |
|
24 | 24 | __author__ = 'jcgregorio@google.com (Joe Gregorio)' |
25 | 25 |
|
| 26 | +import argparse |
26 | 27 | import os |
27 | 28 | import re |
| 29 | +import string |
28 | 30 | import sys |
29 | | -import httplib2 |
30 | | - |
31 | | -from string import Template |
32 | 31 |
|
| 32 | +from apiclient.discovery import DISCOVERY_URI |
33 | 33 | from apiclient.discovery import build |
34 | 34 | from apiclient.discovery import build_from_document |
35 | | -from apiclient.discovery import DISCOVERY_URI |
36 | 35 | from oauth2client.anyjson import simplejson |
37 | | -import gflags |
| 36 | +import httplib2 |
38 | 37 | import uritemplate |
39 | 38 |
|
40 | | - |
41 | 39 | CSS = """<style> |
42 | 40 |
|
43 | 41 | body, h1, h2, h3, div, span, p, pre, a { |
|
132 | 130 |
|
133 | 131 | DIRECTORY_URI = 'https://www.googleapis.com/discovery/v1/apis?preferred=true' |
134 | 132 |
|
135 | | -FLAGS = gflags.FLAGS |
| 133 | +parser = argparse.ArgumentParser(description=__doc__) |
136 | 134 |
|
137 | | -gflags.DEFINE_string('discovery_uri_template', DISCOVERY_URI, |
138 | | - 'URI Template for discovery.') |
| 135 | +parser.add_argument('--discovery_uri_template', default=DISCOVERY_URI, |
| 136 | + help='URI Template for discovery.') |
139 | 137 |
|
140 | | -gflags.DEFINE_string('discovery_uri', '', 'URI of discovery document. ' |
141 | | - 'If supplied then only this API will be documented.') |
| 138 | +parser.add_argument('--discovery_uri', default='', |
| 139 | + help=('URI of discovery document. If supplied then only ' |
| 140 | + 'this API will be documented.')) |
142 | 141 |
|
143 | | -gflags.DEFINE_string('directory_uri', DIRECTORY_URI, |
144 | | - 'URI of directory document. ' |
145 | | - 'Unused if --discovery_uri is supplied.') |
| 142 | +parser.add_argument('--directory_uri', default=DIRECTORY_URI, |
| 143 | + help=('URI of directory document. Unused if --discovery_uri' |
| 144 | + ' is supplied.')) |
| 145 | + |
| 146 | +parser.add_argument('--dest', default=BASE, |
| 147 | + help='Directory name to write documents into.') |
146 | 148 |
|
147 | | -gflags.DEFINE_string('dest', BASE, 'Directory name to write documents into.') |
148 | 149 |
|
149 | 150 |
|
150 | 151 | def safe_version(version): |
@@ -222,7 +223,8 @@ def method(name, doc): |
222 | 223 | """ |
223 | 224 |
|
224 | 225 | params = method_params(doc) |
225 | | - return Template(METHOD_TEMPLATE).substitute(name=name, params=params, doc=doc) |
| 226 | + return string.Template(METHOD_TEMPLATE).substitute( |
| 227 | + name=name, params=params, doc=doc) |
226 | 228 |
|
227 | 229 |
|
228 | 230 | def breadcrumbs(path, root_discovery): |
@@ -290,15 +292,16 @@ def document_collection(resource, path, root_discovery, discovery, css=CSS): |
290 | 292 | for name in collections: |
291 | 293 | if not name.startswith('_') and callable(getattr(resource, name)): |
292 | 294 | href = path + name + '.html' |
293 | | - html.append(Template(COLLECTION_LINK).substitute(href=href, name=name)) |
| 295 | + html.append(string.Template(COLLECTION_LINK).substitute( |
| 296 | + href=href, name=name)) |
294 | 297 |
|
295 | 298 | if methods: |
296 | 299 | for name in methods: |
297 | 300 | if not name.startswith('_') and callable(getattr(resource, name)): |
298 | 301 | doc = getattr(resource, name).__doc__ |
299 | 302 | params = method_params(doc) |
300 | 303 | firstline = doc.splitlines()[0] |
301 | | - html.append(Template(METHOD_LINK).substitute( |
| 304 | + html.append(string.Template(METHOD_LINK).substitute( |
302 | 305 | name=name, params=params, firstline=firstline)) |
303 | 306 |
|
304 | 307 | if methods: |
@@ -371,13 +374,7 @@ def document_api_from_discovery_document(uri): |
371 | 374 |
|
372 | 375 |
|
373 | 376 | if __name__ == '__main__': |
374 | | - # Let the gflags module process the command-line arguments |
375 | | - try: |
376 | | - argv = FLAGS(sys.argv) |
377 | | - except gflags.FlagsError, e: |
378 | | - print '%s\\nUsage: %s ARGS\\n%s' % (e, argv[0], FLAGS) |
379 | | - sys.exit(1) |
380 | | - |
| 377 | + FLAGS = parser.parse_args(sys.argv[1:]) |
381 | 378 | if FLAGS.discovery_uri: |
382 | 379 | document_api_from_discovery_document(FLAGS.discovery_uri) |
383 | 380 | else: |
|
0 commit comments