Guiding principles:
Bucket.acl this already happens:python
@property
def acl(self):
"""Create our ACL on demand."""
if self._acl is None:
self._acl = BucketACL(self)
return self._acl
Blob, Bucket, and *ACL (the only nouns) instances should have load(), exists(), create(), delete(), and update() methods. This design gives rise to code likepython
blob = Blob('/remote/path.txt', bucket=bucket, properties=properties)
try:
blob.load() # Just metadata
except NotFound:
blob.upload_from_file(filename) # Sends metadata from properties
(this maybe screams for get_or_create(), we'll feel it out as we develop). It's unclear if it's worth making a distinction between storage.NOUN.update <--> PUT and storage.NOUN.patch <--> PATCH. (As of right now, we don't implement PUT / update anywhere.)
exists() should use fields in the requests to minimize the payload.Connection should not be required to be bound to any object (one of the nouns Bucket, ACL, or Blob) but should be an optional argument to methods which actually talk to the API.last_updated field to classes to indicate the last time the values were updated (from the server).python
storage.get_all_buckets(connection=optional_connection)
and then bucket.get_all_objects(). It's unclear how the other 3 nouns (objectAccessControls, bucketAccessControls and defaultObjectAccessControls) will handle this. Right now they are handled via ObjectACL.reload() and BucketACL.reload() (a superclass of DefaultObjectACL).
@tseaver Please weigh in. This was inspired by our discussion at the end of #604.
/cc @thobrla I'd like to close #545 and focus on this (possibly broken down into sub-bugs). Does that sound OK?
Closing https://github.com/GoogleCloudPlatform/gcloud-python/issues/545 and focusing on this+sub-bugs sounds good to me; this captures the concerns I had there.
Thanks!
Aside: I made a list of all the 34 API methods and the corresponding code paths.
@tseaver I'd like to get moving on this soon. WDYT of the proposals?
@dhermes I'm in "quick hit" mode today, but can review in more depth tomorrow.
I'm in Portland mostly AFK, so next few days is fine.
@tseaver Can we move forward on this?
I'm not sure debate here is the right thing: this is a _large_ set of changes, and I'm not sure what the goals are: we should be talking about them, first, before we try to plan out an implementation.
The goal is really just making the API more usable.
The current behavior of "sync" whenever a property is added outside a batch shouldn't be the default behavior (see #545). Most of the changes above relate to making network interaction occur more transparently.
Hi. Is there any progress on the part that says blob.upload_from_file(filename) # Sends metadata from properties in this issue (or is there a separate issue for it I haven't found)?
Having to use patch() after upload_...() unfortunately has several more or less serious drawbacks:
These are currently blocking me from using gcloud-python.
User @pdknsk seems to have provided a patch in #536. I think it would make sense implementing that even before/without having the "load(), exists(), create(), delete(), and update()" interface described in this issue.
I'd be happy to provide a pull request if that helps.
Most helpful comment
https://github.com/GoogleCloudPlatform/gcloud-python/issues/1185
https://github.com/GoogleCloudPlatform/gcloud-python/issues/754