Skip to content

Commit 4570c43

Browse files
committed
Changing Key noun to be Blob in storage package.
This involves changes in all documentation, renaming a module and a test module, and updating the calls and variable names in a regression test module. Fixes #544.
1 parent 86acc4a commit 4570c43

21 files changed

Lines changed: 828 additions & 824 deletions

README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ to Cloud Storage using this Client Library.
9595
import gcloud.storage
9696
bucket = gcloud.storage.get_bucket('bucket-id-here', 'project-id')
9797
# Then do other things...
98-
key = bucket.get_key('/remote/path/to/file.txt')
99-
print key.get_contents_as_string()
100-
key.set_contents_from_string('New contents!')
98+
blob = bucket.get_blob('/remote/path/to/file.txt')
99+
print blob.get_contents_as_string()
100+
blob.set_contents_from_string('New contents!')
101101
bucket.upload_file('/remote/path/storage.txt', '/local/path.txt')
102102
103103
Contributing

docs/_components/storage-getting-started.rst

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Getting started with Cloud Storage
44
This tutorial focuses on using ``gcloud`` to access
55
Google Cloud Storage.
66
We'll go through the basic concepts,
7-
how to operate on buckets and keys,
7+
how to operate on buckets and blobs,
88
and how to handle access control,
99
among other things.
1010

@@ -114,32 +114,31 @@ so if you want to group data into "directories",
114114
you can do that.
115115

116116
The fundamental container for a file in Cloud Storage
117-
is called an Object,
118-
however ``gcloud`` uses the term ``Key``
119-
to avoid confusion between ``object`` and ``Object``.
117+
is called an Object, however ``gcloud`` uses the term ``Blob``
118+
to avoid confusion with the Python built-in ``object``.
120119

121120
If you want to set some data,
122-
you just create a ``Key`` inside your bucket
123-
and store your data inside the key::
121+
you just create a ``Blob`` inside your bucket
122+
and store your data inside the blob::
124123

125-
>>> key = bucket.new_key('greeting.txt')
126-
>>> key.set_contents_from_string('Hello world!')
124+
>>> blob = bucket.new_blob('greeting.txt')
125+
>>> blob.set_contents_from_string('Hello world!')
127126

128-
:func:`new_key <gcloud.storage.bucket.Bucket.new_key>`
129-
creates a :class:`Key <gcloud.storage.key.Key>` object locally
127+
:func:`new_blob <gcloud.storage.bucket.Bucket.new_blob>`
128+
creates a :class:`Blob <gcloud.storage.blob.Blob>` object locally
130129
and
131-
:func:`set_contents_from_string <gcloud.storage.key.Key.set_contents_from_string>`
132-
allows you to put a string into the key.
130+
:func:`set_contents_from_string <gcloud.storage.blob.Blob.set_contents_from_string>`
131+
allows you to put a string into the blob.
133132

134133
Now we can test if it worked::
135134

136-
>>> key = bucket.get_key('greeting.txt')
137-
>>> print key.get_contents_as_string()
135+
>>> blob = bucket.get_blob('greeting.txt')
136+
>>> print blob.get_contents_as_string()
138137
Hello world!
139138

140139
What if you want to save the contents to a file?
141140

142-
>>> key.get_contents_to_filename('greetings.txt')
141+
>>> blob.get_contents_to_filename('greetings.txt')
143142

144143
Then you can look at the file in a terminal::
145144

@@ -149,32 +148,32 @@ Then you can look at the file in a terminal::
149148
And what about when you're not dealing with text?
150149
That's pretty simple too::
151150

152-
>>> key = bucket.new_key('kitten.jpg')
153-
>>> key.set_contents_from_filename('kitten.jpg')
151+
>>> blob = bucket.new_blob('kitten.jpg')
152+
>>> blob.set_contents_from_filename('kitten.jpg')
154153

155154
And to test whether it worked?
156155

157-
>>> key = bucket.get_key('kitten.jpg')
158-
>>> key.get_contents_to_filename('kitten2.jpg')
156+
>>> blob = bucket.get_blob('kitten.jpg')
157+
>>> blob.get_contents_to_filename('kitten2.jpg')
159158

160159
and check if they are the same in a terminal::
161160

162161
$ diff kitten.jpg kitten2.jpg
163162

164163
Notice that we're using
165-
:func:`get_key <gcloud.storage.bucket.Bucket.get_key>`
166-
to retrieve a key we know exists remotely.
167-
If the key doesn't exist, it will return ``None``.
164+
:func:`get_blob <gcloud.storage.bucket.Bucket.get_blob>`
165+
to retrieve a blob we know exists remotely.
166+
If the blob doesn't exist, it will return ``None``.
168167

169-
.. note:: ``get_key`` is **not** retrieving the entire object's data.
168+
.. note:: ``get_blob`` is **not** retrieving the entire object's data.
170169

171-
If you want to "get-or-create" the key
170+
If you want to "get-or-create" the blob
172171
(that is, overwrite it if it already exists),
173-
you can use :func:`new_key <gcloud.storage.bucket.Bucket.new_key>`.
174-
However, keep in mind, the key is not created
172+
you can use :func:`new_blob <gcloud.storage.bucket.Bucket.new_blob>`.
173+
However, keep in mind, the blob is not created
175174
until you store some data inside of it.
176175

177-
If you want to check whether a key exists,
176+
If you want to check whether a blob exists,
178177
you can use the ``in`` operator in Python::
179178

180179
>>> print 'kitten.jpg' in bucket
@@ -191,17 +190,17 @@ to retrieve the bucket object::
191190

192191
>>> bucket = connection.get_bucket('my-bucket')
193192

194-
If you want to get all the keys in the bucket,
193+
If you want to get all the blobs in the bucket,
195194
you can use
196-
:func:`get_all_keys <gcloud.storage.bucket.Bucket.get_all_keys>`::
195+
:func:`get_all_blobs <gcloud.storage.bucket.Bucket.get_all_blobs>`::
197196

198-
>>> keys = bucket.get_all_keys()
197+
>>> blobs = bucket.get_all_blobs()
199198

200-
However, if you're looking to iterate through the keys,
199+
However, if you're looking to iterate through the blobs,
201200
you can use the bucket itself as an iterator::
202201

203-
>>> for key in bucket:
204-
... print key
202+
>>> for blob in bucket:
203+
... print blob
205204

206205
Deleting a bucket
207206
-----------------
@@ -234,7 +233,7 @@ Managing access control
234233
-----------------------
235234

236235
Cloud storage provides fine-grained access control
237-
for both buckets and keys.
236+
for both buckets and blobs.
238237
`gcloud` tries to simplify access control
239238
by working with entities and "grants".
240239
On any ACL,

docs/_components/storage-quickstart.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,22 @@ and instantiating the demo connection::
5353
>>> connection = demo.get_connection()
5454

5555
Once you have the connection,
56-
you can create buckets and keys::
56+
you can create buckets and blobs::
5757

5858
>>> connection.get_all_buckets()
5959
[<Bucket: ...>, ...]
6060
>>> bucket = connection.create_bucket('my-new-bucket')
6161
>>> print bucket
6262
<Bucket: my-new-bucket>
63-
>>> key = bucket.new_key('my-test-file.txt')
64-
>>> print key
65-
<Key: my-new-bucket, my-test-file.txt>
66-
>>> key = key.set_contents_from_string('this is test content!')
67-
>>> print key.get_contents_as_string()
63+
>>> blob = bucket.new_blob('my-test-file.txt')
64+
>>> print blob
65+
<Blob: my-new-bucket, my-test-file.txt>
66+
>>> blob = blob.set_contents_from_string('this is test content!')
67+
>>> print blob.get_contents_as_string()
6868
'this is test content!'
69-
>>> print bucket.get_all_keys()
70-
[<Key: my-new-bucket, my-test-file.txt>]
71-
>>> key.delete()
69+
>>> print bucket.get_all_blobs()
70+
[<Blob: my-new-bucket, my-test-file.txt>]
71+
>>> blob.delete()
7272
>>> bucket.delete()
7373

7474
.. note::

docs/index.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
datastore-transactions
1111
datastore-batches
1212
storage-api
13+
storage-blobs
1314
storage-buckets
14-
storage-keys
1515
storage-acl
1616

1717

@@ -48,5 +48,5 @@ Cloud Storage
4848
4949
from gcloud import storage
5050
bucket = storage.get_bucket('<your-bucket-name>', '<your-project-id>')
51-
key = bucket.new_key('my-test-file.txt')
52-
key = key.upload_contents_from_string('this is test content!')
51+
blob = bucket.new_blob('my-test-file.txt')
52+
blob = blob.upload_contents_from_string('this is test content!')

docs/storage-api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.. toctree::
22
:maxdepth: 0
3-
:hidden:
3+
:hidden:
44

55
Storage
66
-------

docs/storage-blobs.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Blobs / Objects
2+
~~~~~~~~~~~~~~~
3+
4+
.. automodule:: gcloud.storage.blob
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

docs/storage-keys.rst

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

gcloud/storage/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
>>> import gcloud.storage
2020
>>> bucket = gcloud.storage.get_bucket('bucket-id-here', 'project-id')
2121
>>> # Then do other things...
22-
>>> key = bucket.get_key('/remote/path/to/file.txt')
23-
>>> print key.get_contents_as_string()
24-
>>> key.set_contents_from_string('New contents!')
22+
>>> blob = bucket.get_blob('/remote/path/to/file.txt')
23+
>>> print blob.get_contents_as_string()
24+
>>> blob.set_contents_from_string('New contents!')
2525
>>> bucket.upload_file('/remote/path/storage.txt', '/local/path.txt')
2626
2727
The main concepts with this API are:
@@ -32,7 +32,7 @@
3232
- :class:`gcloud.storage.bucket.Bucket` which represents a particular
3333
bucket (akin to a mounted disk on a computer).
3434
35-
- :class:`gcloud.storage.key.Key` which represents a pointer to a
35+
- :class:`gcloud.storage.blob.Blob` which represents a pointer to a
3636
particular entity in Cloud Storage (akin to a file path on a remote
3737
machine).
3838
"""

gcloud/storage/_helpers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ def batch(self):
7979
... bucket.enable_versioning()
8080
... bucket.disable_website()
8181
82-
or for a key::
82+
or for a blob::
8383
84-
>>> with key.batch:
85-
... key.content_type = 'image/jpeg'
86-
... key.content_encoding = 'gzip'
84+
>>> with blob.batch:
85+
... blob.content_type = 'image/jpeg'
86+
... blob.content_encoding = 'gzip'
8787
8888
Updates will be aggregated and sent as a single call to
8989
:meth:`_patch_properties` IFF the ``with`` block exits without

gcloud/storage/acl.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -491,15 +491,15 @@ class DefaultObjectACL(BucketACL):
491491

492492

493493
class ObjectACL(ACL):
494-
"""An ACL specifically for a key."""
494+
"""An ACL specifically for a Cloud Storage object / blob.
495495
496-
def __init__(self, key):
497-
"""
498-
:type key: :class:`gcloud.storage.key.Key`
499-
:param key: The key that this ACL corresponds to.
500-
"""
496+
:type blob: :class:`gcloud.storage.blob.Blob`
497+
:param blob: The blob that this ACL corresponds to.
498+
"""
499+
500+
def __init__(self, blob):
501501
super(ObjectACL, self).__init__()
502-
self.key = key
502+
self.blob = blob
503503

504504
def reload(self):
505505
"""Reload the ACL data from Cloud Storage.
@@ -509,16 +509,16 @@ def reload(self):
509509
"""
510510
self.entities.clear()
511511

512-
url_path = '%s/acl' % self.key.path
513-
found = self.key.connection.api_request(method='GET', path=url_path)
512+
url_path = '%s/acl' % self.blob.path
513+
found = self.blob.connection.api_request(method='GET', path=url_path)
514514
self.loaded = True
515515
for entry in found['items']:
516516
self.add_entity(self.entity_from_dict(entry))
517517

518518
return self
519519

520520
def save(self, acl=None):
521-
"""Save the ACL data for this key.
521+
"""Save the ACL data for this blob.
522522
523523
:type acl: :class:`gcloud.storage.acl.ACL`
524524
:param acl: The ACL object to save. If left blank, this will
@@ -531,8 +531,8 @@ def save(self, acl=None):
531531
save_to_backend = True
532532

533533
if save_to_backend:
534-
result = self.key.connection.api_request(
535-
method='PATCH', path=self.key.path, data={'acl': list(acl)},
534+
result = self.blob.connection.api_request(
535+
method='PATCH', path=self.blob.path, data={'acl': list(acl)},
536536
query_params={'projection': 'full'})
537537
self.entities.clear()
538538
for entry in result['acl']:
@@ -542,11 +542,11 @@ def save(self, acl=None):
542542
return self
543543

544544
def clear(self):
545-
"""Remove all ACL rules from the key.
545+
"""Remove all ACL rules from the blob.
546546
547547
Note that this won't actually remove *ALL* the rules, but it
548548
will remove all the non-default rules. In short, you'll still
549-
have access to a key that you created even after you clear ACL
549+
have access to a blob that you created even after you clear ACL
550550
rules with this method.
551551
"""
552552
return self.save([])

0 commit comments

Comments
 (0)