diff --git a/gcloud/storage/__init__.py b/gcloud/storage/__init__.py index e53c3df71981..f2e0b51f252b 100644 --- a/gcloud/storage/__init__.py +++ b/gcloud/storage/__init__.py @@ -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. @@ -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 @@ -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. @@ -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) diff --git a/gcloud/storage/acl.py b/gcloud/storage/acl.py index 714beffc4a06..9ce9612f661d 100644 --- a/gcloud/storage/acl.py +++ b/gcloud/storage/acl.py @@ -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() diff --git a/gcloud/storage/bucket.py b/gcloud/storage/bucket.py index 6c3cfe07ff00..5c7ae9e9e684 100644 --- a/gcloud/storage/bucket.py +++ b/gcloud/storage/bucket.py @@ -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') @@ -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() [] @@ -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() @@ -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() @@ -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') @@ -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() diff --git a/gcloud/storage/connection.py b/gcloud/storage/connection.py index ec25a843f181..b626b3d76612 100644 --- a/gcloud/storage/connection.py +++ b/gcloud/storage/connection.py @@ -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:: @@ -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)) @@ -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 @@ -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 ... @@ -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: @@ -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 @@ -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 @@ -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 diff --git a/gcloud/storage/demo/__init__.py b/gcloud/storage/demo/__init__.py index 13d862564fc9..7aaa2dca6697 100644 --- a/gcloud/storage/demo/__init__.py +++ b/gcloud/storage/demo/__init__.py @@ -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) diff --git a/gcloud/storage/key.py b/gcloud/storage/key.py index 87348c261666..9b970bd12f1d 100644 --- a/gcloud/storage/key.py +++ b/gcloud/storage/key.py @@ -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!') diff --git a/gcloud/storage/test_connection.py b/gcloud/storage/test_connection.py index d15c0e11484e..0a6923d9b27e 100644 --- a/gcloud/storage/test_connection.py +++ b/gcloud/storage/test_connection.py @@ -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)