Skip to content

Commit

Permalink
Merge pull request #74 from kleyow/swap
Browse files Browse the repository at this point in the history
Fix #43 - Swapped project_name for project.
  • Loading branch information
jgeewax committed Apr 22, 2014
2 parents 6ce841a + 3472e22 commit ad1f0f7
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 33 deletions.
20 changes: 10 additions & 10 deletions gcloud/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@
'https://www.googleapis.com/auth/devstorage.read_write')


def get_connection(project_name, client_email, private_key_path):
def get_connection(project, client_email, private_key_path):
"""Shortcut method to establish a connection to Cloud Storage.
Use this if you are going to access several buckets
with the same set of credentials:
>>> from gcloud import storage
>>> connection = storage.get_connection(project_name, email, key_path)
>>> connection = storage.get_connection(project, email, key_path)
>>> bucket1 = connection.get_bucket('bucket1')
>>> bucket2 = connection.get_bucket('bucket2')
:type project_name: string
:param project_name: The name of the project to connect to.
:type project: string
:param project: The name of the project to connect to.
:type client_email: string
:param client_email: The e-mail attached to the service account.
Expand All @@ -68,15 +68,15 @@ def get_connection(project_name, client_email, private_key_path):

credentials = Credentials.get_for_service_account(
client_email, private_key_path, scope=SCOPE)
return Connection(project_name=project_name, credentials=credentials)
return Connection(project=project, credentials=credentials)

def get_bucket(bucket_name, project_name, client_email, private_key_path):
def get_bucket(bucket_name, project, client_email, private_key_path):
"""Shortcut method to establish a connection to a particular bucket.
You'll generally use this as the first call to working with the API:
>>> from gcloud import storage
>>> bucket = storage.get_bucket(project_name, bucket_name, email, key_path)
>>> bucket = storage.get_bucket(project, bucket_name, email, key_path)
>>> # Now you can do things with the bucket.
>>> bucket.exists('/path/to/file.txt')
False
Expand All @@ -85,8 +85,8 @@ def get_bucket(bucket_name, project_name, client_email, private_key_path):
:param bucket_name: The id of the bucket you want to use.
This is akin to a disk name on a file system.
:type project_name: string
:param project_name: The name of the project to connect to.
:type project: string
:param project: The name of the project to connect to.
:type client_email: string
:param client_email: The e-mail attached to the service account.
Expand All @@ -100,5 +100,5 @@ def get_bucket(bucket_name, project_name, client_email, private_key_path):
:returns: A bucket with a connection using the provided credentials.
"""

connection = get_connection(project_name, client_email, private_key_path)
connection = get_connection(project, client_email, private_key_path)
return connection.get_bucket(bucket_name)
2 changes: 1 addition & 1 deletion gcloud/storage/acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
:func:`gcloud.storage.bucket.Bucket.get_acl`::
>>> from gcloud import storage
>>> connection = storage.get_connection(project_name, email, key_path)
>>> connection = storage.get_connection(project, email, key_path)
>>> bucket = connection.get_bucket(bucket_name)
>>> acl = bucket.get_acl()
Expand Down
12 changes: 6 additions & 6 deletions gcloud/storage/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def get_key(self, key):
This will return None if the key doesn't exist::
>>> from gcloud import storage
>>> connection = storage.get_connection(project_name, email, key_path)
>>> connection = storage.get_connection(project, email, key_path)
>>> bucket = connection.get_bucket('my-bucket')
>>> print bucket.get_key('/path/to/key.txt')
<Key: my-bucket, /path/to/key.txt>
Expand Down Expand Up @@ -157,7 +157,7 @@ def delete_key(self, key):
>>> from gcloud import storage
>>> from gcloud.storage import exceptions
>>> connection = storage.get_connection(project_name, email, key_path)
>>> connection = storage.get_connection(project, email, key_path)
>>> bucket = connection.get_bucket('my-bucket')
>>> print bucket.get_all_keys()
[<Key: my-bucket, my-file.txt>]
Expand Down Expand Up @@ -198,7 +198,7 @@ def upload_file(self, filename, key=None):
For example::
>>> from gcloud import storage
>>> connection = storage.get_connection(project_name, email, key_path)
>>> connection = storage.get_connection(project, email, key_path)
>>> bucket = connection.get_bucket('my-bucket')
>>> bucket.upload_file('~/my-file.txt', 'remote-text-file.txt')
>>> print bucket.get_all_keys()
Expand All @@ -210,7 +210,7 @@ def upload_file(self, filename, key=None):
(**not** the complete path)::
>>> from gcloud import storage
>>> connection = storage.get_connection(project_name, email, key_path)
>>> connection = storage.get_connection(project, email, key_path)
>>> bucket = connection.get_bucket('my-bucket')
>>> bucket.upload_file('~/my-file.txt')
>>> print bucket.get_all_keys()
Expand Down Expand Up @@ -329,7 +329,7 @@ def configure_website(self, main_page_suffix=None, not_found_page=None):
and a page to use when a key isn't found::
>>> from gcloud import storage
>>> connection = storage.get_connection(project_name, email, private_key_path)
>>> connection = storage.get_connection(project, email, private_key_path)
>>> bucket = connection.get_bucket(bucket_name)
>>> bucket.configure_website('index.html', '404.html')
Expand Down Expand Up @@ -460,7 +460,7 @@ def clear_acl(self):
to a bunch of coworkers::
>>> from gcloud import storage
>>> connection = storage.get_connection(project_name, email, private_key_path)
>>> connection = storage.get_connection(project, email, private_key_path)
>>> bucket = connection.get_bucket(bucket_name)
>>> acl = bucket.get_acl()
>>> acl.user('coworker1@example.org').grant_read()
Expand Down
22 changes: 11 additions & 11 deletions gcloud/storage/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Connection(connection.Connection):
:class:`gcloud.storage.bucket.Bucket` objects::
>>> from gcloud import storage
>>> connection = storage.get_connection(project_name, email, key_path)
>>> connection = storage.get_connection(project, email, key_path)
>>> bucket = connection.create_bucket('my-bucket-name')
You can then delete this bucket::
Expand Down Expand Up @@ -67,15 +67,15 @@ class Connection(connection.Connection):

API_ACCESS_ENDPOINT = 'https://storage.googleapis.com'

def __init__(self, project_name, *args, **kwargs):
def __init__(self, project, *args, **kwargs):
"""
:type project_name: string
:param project_name: The project name to connect to.
:type project: string
:param project: The project name to connect to.
"""

super(Connection, self).__init__(*args, **kwargs)

self.project_name = project_name
self.project = project

def __iter__(self):
return iter(BucketIterator(connection=self))
Expand Down Expand Up @@ -115,7 +115,7 @@ def build_api_url(self, path, query_params=None, api_base_url=None,
path=path)

query_params = query_params or {}
query_params.update({'project': self.project_name})
query_params.update({'project': self.project})
url += '?' + urllib.urlencode(query_params)

return url
Expand Down Expand Up @@ -242,7 +242,7 @@ def get_all_buckets(self, *args, **kwargs):
so these two operations are identical::
>>> from gcloud import storage
>>> connection = storage.get_connection(project_name, email, key_path)
>>> connection = storage.get_connection(project, email, key_path)
>>> for bucket in connection.get_all_buckets():
>>> print bucket
>>> # ... is the same as ...
Expand All @@ -269,7 +269,7 @@ def get_bucket(self, bucket_name, *args, **kwargs):
>>> from gcloud import storage
>>> from gcloud.storage import exceptions
>>> connection = storage.get_connection(project_name, email, key_path)
>>> connection = storage.get_connection(project, email, key_path)
>>> try:
>>> bucket = connection.get_bucket('my-bucket')
>>> except exceptions.NotFoundError:
Expand All @@ -296,7 +296,7 @@ def lookup(self, bucket_name):
than catching an exception::
>>> from gcloud import storage
>>> connection = storage.get_connection(project_name, email, key_path)
>>> connection = storage.get_connection(project, email, key_path)
>>> bucket = connection.get_bucket('doesnt-exist')
>>> print bucket
None
Expand All @@ -323,7 +323,7 @@ def create_bucket(self, bucket, *args, **kwargs):
For example::
>>> from gcloud import storage
>>> connection = storage.get_connection(project_name, client, key_path)
>>> connection = storage.get_connection(project, client, key_path)
>>> bucket = connection.create_bucket('my-bucket')
>>> print bucket
<Bucket: my-bucket>
Expand All @@ -347,7 +347,7 @@ def delete_bucket(self, bucket, *args, **kwargs):
or to delete a bucket object::
>>> from gcloud import storage
>>> connection = storage.get_connection(project_name, email, key_path)
>>> connection = storage.get_connection(project, email, key_path)
>>> connection.delete_bucket('my-bucket')
True
Expand Down
6 changes: 3 additions & 3 deletions gcloud/storage/demo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from gcloud import storage


__all__ = ['get_connection', 'CLIENT_EMAIL', 'PRIVATE_KEY_PATH', 'PROJECT_NAME']
__all__ = ['get_connection', 'CLIENT_EMAIL', 'PRIVATE_KEY_PATH', 'PROJECT']


CLIENT_EMAIL = '606734090113-6ink7iugcv89da9sru7lii8bs3i0obqg@developer.gserviceaccount.com'
PRIVATE_KEY_PATH = os.path.join(os.path.dirname(__file__), 'demo.key')
PROJECT_NAME = 'gcloud-storage-demo'
PROJECT = 'gcloud-storage-demo'


def get_connection():
return storage.get_connection(PROJECT_NAME, CLIENT_EMAIL, PRIVATE_KEY_PATH)
return storage.get_connection(PROJECT, CLIENT_EMAIL, PRIVATE_KEY_PATH)
2 changes: 1 addition & 1 deletion gcloud/storage/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def set_contents_from_string(self, data, content_type='text/plain'):
You can use this method to quickly set the value of a key::
>>> from gcloud import storage
>>> connection = storage.get_connection(project_name, email, key_path)
>>> connection = storage.get_connection(project, email, key_path)
>>> bucket = connection.get_bucket(bucket_name)
>>> key = bucket.new_key('my_text_file.txt')
>>> key.set_contents_from_string('This is the contents of my file!')
Expand Down
2 changes: 1 addition & 1 deletion gcloud/storage/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ class TestConnection(unittest2.TestCase):

def test_init(self):
connection = Connection('project-name')
self.assertEqual('project-name', connection.project_name)
self.assertEqual('project-name', connection.project)

0 comments on commit ad1f0f7

Please sign in to comment.