-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from jgeewax/storage
Fixed #5 - Adding support for Google Cloud Storage
- Loading branch information
Showing
23 changed files
with
2,516 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
if self._credentials: | ||
self._http = self._credentials.authorize(self._http) | ||
return self._http | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.