Skip to content

Commit 79daca0

Browse files
committed
Start removing dependence on gflags.
Reviewed in https://codereview.appspot.com/7628044/. This only removes the dependency from the core library, a second CL will update all the samples.
1 parent 731680a commit 79daca0

19 files changed

+157
-433
lines changed

LICENSE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,3 @@ above and beyond the Python standard library:
2020

2121
uritemplates - Apache License 2.0
2222
httplib2 - MIT License
23-
python-gflags - New BSD License

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ prerelease: test
3030
-rm -rf snapshot/
3131
-sudo rm -rf snapshot/
3232
./tools/gae-zip-creator.sh
33-
python expand-symlinks.py
33+
python expandsymlinks.py
3434
cd snapshot; python setup.py clean
3535
cd snapshot; python setup.py sdist --formats=gztar,zip
3636
cd snapshot; tar czf google-api-python-client-samples-$(shell python setup.py --version).tar.gz samples
@@ -58,7 +58,7 @@ oauth2_prerelease: test
5858
-rm -rf snapshot/
5959
-sudo rm -rf snapshot/
6060
mkdir snapshot
61-
python expand-symlinks.py --source=oauth2client --dest=snapshot/oauth2client
61+
python expandsymlinks.py --source=oauth2client --dest=snapshot/oauth2client
6262
cp setup_oauth2client.py snapshot/setup.py
6363
cp MANIFEST_oauth2client.in snapshot/MANIFEST.in
6464
cp README_oauth2client snapshot/README

README

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ These libraries will be installed when you install the client library:
2222

2323
http://code.google.com/p/httplib2
2424
http://code.google.com/p/uri-templates
25-
http://code.google.com/p/python-gflags
2625

2726
Depending on your version of Python, these libraries may also be installed:
2827

README_oauth2client

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Third Party Libraries
1515
These libraries will be installed when you install the client library:
1616

1717
http://code.google.com/p/httplib2
18-
http://code.google.com/p/python-gflags
1918

2019
Depending on your version of Python, these libraries may also be installed:
2120

apiclient/model.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,14 @@
2424

2525
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
2626

27-
import gflags
2827
import logging
2928
import urllib
3029

3130
from errors import HttpError
3231
from oauth2client.anyjson import simplejson
3332

34-
FLAGS = gflags.FLAGS
3533

36-
gflags.DEFINE_boolean('dump_request_response', False,
37-
'Dump all http server requests and responses. '
38-
)
34+
dump_request_response = False
3935

4036

4137
def _abstract():
@@ -106,7 +102,7 @@ class BaseModel(Model):
106102

107103
def _log_request(self, headers, path_params, query, body):
108104
"""Logs debugging information about the request if requested."""
109-
if FLAGS.dump_request_response:
105+
if dump_request_response:
110106
logging.info('--request-start--')
111107
logging.info('-headers-start-')
112108
for h, v in headers.iteritems():
@@ -177,7 +173,7 @@ def _build_query(self, params):
177173

178174
def _log_response(self, resp, content):
179175
"""Logs debugging information about the response if requested."""
180-
if FLAGS.dump_request_response:
176+
if dump_request_response:
181177
logging.info('--response-start--')
182178
for h, v in resp.iteritems():
183179
logging.info('%s: %s', h, v)
@@ -198,6 +194,7 @@ def response(self, resp, content):
198194
Raises:
199195
apiclient.errors.HttpError if a non 2xx response is received.
200196
"""
197+
content = content.decode('utf-8')
201198
self._log_response(resp, content)
202199
# Error handling is TBD, for example, do we retry
203200
# for some operation/error combinations?

bin/enable-app-engine-project

Lines changed: 0 additions & 137 deletions
This file was deleted.

describe.py

100644100755
Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/python
22
#
33
# Copyright 2012 Google Inc.
44
#
@@ -23,21 +23,19 @@
2323

2424
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
2525

26+
import argparse
2627
import os
2728
import re
29+
import string
2830
import sys
29-
import httplib2
30-
31-
from string import Template
3231

32+
from apiclient.discovery import DISCOVERY_URI
3333
from apiclient.discovery import build
3434
from apiclient.discovery import build_from_document
35-
from apiclient.discovery import DISCOVERY_URI
3635
from oauth2client.anyjson import simplejson
37-
import gflags
36+
import httplib2
3837
import uritemplate
3938

40-
4139
CSS = """<style>
4240
4341
body, h1, h2, h3, div, span, p, pre, a {
@@ -132,19 +130,22 @@
132130

133131
DIRECTORY_URI = 'https://www.googleapis.com/discovery/v1/apis?preferred=true'
134132

135-
FLAGS = gflags.FLAGS
133+
parser = argparse.ArgumentParser(description=__doc__)
136134

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.')
139137

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.'))
142141

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.')
146148

147-
gflags.DEFINE_string('dest', BASE, 'Directory name to write documents into.')
148149

149150

150151
def safe_version(version):
@@ -222,7 +223,8 @@ def method(name, doc):
222223
"""
223224

224225
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)
226228

227229

228230
def breadcrumbs(path, root_discovery):
@@ -290,15 +292,16 @@ def document_collection(resource, path, root_discovery, discovery, css=CSS):
290292
for name in collections:
291293
if not name.startswith('_') and callable(getattr(resource, name)):
292294
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))
294297

295298
if methods:
296299
for name in methods:
297300
if not name.startswith('_') and callable(getattr(resource, name)):
298301
doc = getattr(resource, name).__doc__
299302
params = method_params(doc)
300303
firstline = doc.splitlines()[0]
301-
html.append(Template(METHOD_LINK).substitute(
304+
html.append(string.Template(METHOD_LINK).substitute(
302305
name=name, params=params, firstline=firstline))
303306

304307
if methods:
@@ -371,13 +374,7 @@ def document_api_from_discovery_document(uri):
371374

372375

373376
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:])
381378
if FLAGS.discovery_uri:
382379
document_api_from_discovery_document(FLAGS.discovery_uri)
383380
else:
Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,24 @@
2020

2121
from shutil import copytree
2222

23-
import gflags
23+
import argparse
2424
import sys
2525

2626

27-
FLAGS = gflags.FLAGS
28-
2927
# Ignore these files and directories when copying over files into the snapshot.
30-
IGNORE = set(['.hg', 'httplib2', 'oauth2', 'simplejson', 'static', 'gflags.py',
31-
'gflags_validators.py'])
28+
IGNORE = set(['.hg', 'httplib2', 'oauth2', 'simplejson', 'static'])
3229

3330
# In addition to the above files also ignore these files and directories when
3431
# copying over samples into the snapshot.
3532
IGNORE_IN_SAMPLES = set(['apiclient', 'oauth2client', 'uritemplate'])
3633

34+
parser = argparse.ArgumentParser(description=__doc__)
35+
36+
parser.add_argument('--source', default='.',
37+
help='Directory name to copy from.')
3738

38-
gflags.DEFINE_string('source', '.', 'Directory name to copy from.')
39-
gflags.DEFINE_string('dest', 'snapshot', 'Directory name to copy to.')
39+
parser.add_argument('--dest', default='snapshot',
40+
help='Directory name to copy to.')
4041

4142

4243
def _ignore(path, names):
@@ -47,17 +48,11 @@ def _ignore(path, names):
4748
return retval
4849

4950

50-
def main(argv):
51-
# Let the gflags module process the command-line arguments
52-
try:
53-
argv = FLAGS(argv)
54-
except gflags.FlagsError, e:
55-
print '%s\\nUsage: %s ARGS\\n%s' % (e, argv[0], FLAGS)
56-
sys.exit(1)
57-
51+
def main():
5852
copytree(FLAGS.source, FLAGS.dest, symlinks=True,
5953
ignore=_ignore)
6054

6155

6256
if __name__ == '__main__':
63-
main(sys.argv)
57+
FLAGS = parser.parse_args(sys.argv[1:])
58+
main()

0 commit comments

Comments
 (0)