-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed #5 - Adding support for Google Cloud Storage #20
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
*.py[cod] | ||
*.sw[op] | ||
|
||
# C extensions | ||
*.so | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Cloud Common | ||
============ | ||
|
||
Connections | ||
----------- | ||
|
||
.. automodule:: gcloud.connection | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
Credentials | ||
----------- | ||
|
||
.. automodule:: gcloud.credentials | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
Cloud Storage | ||
============= | ||
|
||
:mod:`gcloud.storage` | ||
----------------------- | ||
|
||
.. automodule:: gcloud.storage.__init__ | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
Connections | ||
----------- | ||
|
||
.. automodule:: gcloud.storage.connection | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
Buckets | ||
------- | ||
|
||
.. automodule:: gcloud.storage.bucket | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
Keys | ||
---- | ||
|
||
.. automodule:: gcloud.storage.key | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
Access Control | ||
-------------- | ||
|
||
.. automodule:: gcloud.storage.acl | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
Iterators | ||
--------- | ||
|
||
.. automodule:: gcloud.storage.iterator | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
Exceptions | ||
---------- | ||
|
||
.. automodule:: gcloud.storage.exceptions | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
Cloud Storage in 10 seconds | ||
=========================== | ||
|
||
Install the library | ||
------------------- | ||
|
||
The source code for the library | ||
(and demo code) | ||
lives on GitHub, | ||
You can install the library quickly with ``pip``:: | ||
|
||
$ pip install gcloud | ||
|
||
Run the | ||
`example script <https://github.com/jgeewax/gcloud/blob/master/gcloud/storage/demo.py>`_ | ||
included in the package:: | ||
|
||
$ python -m gcloud.storage.demo | ||
|
||
And that's it! | ||
You should be walking through | ||
a demonstration of using ``gcloud.storage`` | ||
to read and write data to Google Cloud Storage. | ||
|
||
Try it yourself | ||
--------------- | ||
|
||
You can interact with a demo dataset | ||
in a Python interactive shell. | ||
|
||
Start by importing the demo module | ||
and instantiating the demo connection:: | ||
|
||
>>> from gcloud.storage import demo | ||
>>> connection = demo.get_connection() | ||
|
||
Once you have the connection, | ||
you can create buckets and keys:: | ||
|
||
>>> connection.get_all_buckets() | ||
[<Bucket: ...>, ...] | ||
>>> bucket = connection.create_bucket('my-new-bucket') | ||
>>> print bucket | ||
<Bucket: my-new-bucket> | ||
>>> key = bucket.new_key('my-test-file.txt') | ||
>>> print key | ||
<Key: my-new-bucket, my-test-file.txt> | ||
>>> key = key.set_contents_from_string('this is test content!') | ||
>>> print key.get_contents_as_string() | ||
'this is test content!' | ||
>>> print bucket.get_all_keys() | ||
[<Key: my-new-bucket, my-test-file.txt>] | ||
>>> bucket.delete() | ||
|
||
.. note:: | ||
The ``get_connection`` method is just a shortcut for:: | ||
|
||
>>> from gcloud import storage | ||
>>> from gcloud.storage import demo | ||
>>> connection = storage.get_connection( | ||
>>> demo.PROJECT_NAME, demo.CLIENT_EMAIL, demo.PRIVATE_KEY_PATH) | ||
|
||
OK, that's it! | ||
-------------- | ||
|
||
And you can always check out | ||
the :doc:`storage-api`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import httplib2 | ||
|
||
|
||
class Connection(object): | ||
"""A generic connection to Google Cloud Platform. | ||
|
||
Subclasses should understand | ||
only the basic types | ||
in method arguments, | ||
however they should be capable | ||
of returning advanced types. | ||
""" | ||
|
||
API_BASE_URL = 'https://www.googleapis.com' | ||
"""The base of the API call URL.""" | ||
|
||
_EMPTY = object() | ||
"""A pointer to represent an empty value for default arguments.""" | ||
|
||
def __init__(self, credentials=None): | ||
""" | ||
:type credentials: :class:`gcloud.credentials.Credentials` | ||
:param credentials: The OAuth2 Credentials to use for this connection. | ||
""" | ||
|
||
self._credentials = credentials | ||
|
||
@property | ||
def http(self): | ||
"""A getter for the HTTP transport used in talking to the API. | ||
|
||
:rtype: :class:`httplib2.Http` | ||
:returns: A Http object used to transport data. | ||
""" | ||
if not hasattr(self, '_http'): | ||
self._http = httplib2.Http() | ||
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong. |
||
if self._credentials: | ||
self._http = self._credentials.authorize(self._http) | ||
return self._http | ||
|
This comment was marked as spam.
Sorry, something went wrong.