Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(697)

Unified Diff: third_party/gsutil/gslib/bucket_listing_ref.py

Issue 1377933002: [catapult] - Copy Telemetry's gsutilz over to third_party. (Closed) Base URL: https://github.com/catapult-project/catapult.git@master
Patch Set: Rename to gsutil. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/gsutil/gslib/boto_translation.py ('k') | third_party/gsutil/gslib/cat_helper.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/gsutil/gslib/bucket_listing_ref.py
diff --git a/third_party/gsutil/gslib/bucket_listing_ref.py b/third_party/gsutil/gslib/bucket_listing_ref.py
new file mode 100644
index 0000000000000000000000000000000000000000..4f289e0fe8490cb5d089d6350a19b225e7f6ca01
--- /dev/null
+++ b/third_party/gsutil/gslib/bucket_listing_ref.py
@@ -0,0 +1,114 @@
+# -*- coding: utf-8 -*-
+# Copyright 2012 Google Inc. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""Classes for cloud/file references yielded by gsutil iterators."""
+
+from __future__ import absolute_import
+
+
+class BucketListingRef(object):
+ """Base class for a reference to one fully expanded iterator result.
+
+ This allows polymorphic iteration over wildcard-iterated URLs. The
+ reference contains a fully expanded URL string containing no wildcards and
+ referring to exactly one entity (if a wildcard is contained, it is assumed
+ this is part of the raw string and should never be treated as a wildcard).
+
+ Each reference represents a Bucket, Object, or Prefix. For filesystem URLs,
+ Objects represent files and Prefixes represent directories.
+
+ The root_object member contains the underlying object as it was retrieved.
+ It is populated by the calling iterator, which may only request certain
+ fields to reduce the number of server requests.
+
+ For filesystem URLs, root_object is not populated.
+ """
+
+ class _BucketListingRefType(object):
+ """Enum class for describing BucketListingRefs."""
+ BUCKET = 'bucket' # Cloud bucket
+ OBJECT = 'object' # Cloud object or filesystem file
+ PREFIX = 'prefix' # Cloud bucket subdir or filesystem directory
+
+ @property
+ def url_string(self):
+ return self._url_string
+
+ @property
+ def type_name(self):
+ return self._ref_type
+
+ def IsBucket(self):
+ return self._ref_type == self._BucketListingRefType.BUCKET
+
+ def IsObject(self):
+ return self._ref_type == self._BucketListingRefType.OBJECT
+
+ def IsPrefix(self):
+ return self._ref_type == self._BucketListingRefType.PREFIX
+
+ def __str__(self):
+ return self._url_string
+
+
+class BucketListingBucket(BucketListingRef):
+ """BucketListingRef subclass for buckets."""
+
+ def __init__(self, storage_url, root_object=None):
+ """Creates a BucketListingRef of type bucket.
+
+ Args:
+ storage_url: StorageUrl containing a bucket.
+ root_object: Underlying object metadata, if available.
+ """
+ super(BucketListingBucket, self).__init__()
+ self._ref_type = self._BucketListingRefType.BUCKET
+ self._url_string = storage_url.url_string
+ self.storage_url = storage_url
+ self.root_object = root_object
+
+
+class BucketListingPrefix(BucketListingRef):
+ """BucketListingRef subclass for prefixes."""
+
+ def __init__(self, storage_url, root_object=None):
+ """Creates a BucketListingRef of type prefix.
+
+ Args:
+ storage_url: StorageUrl containing a prefix.
+ root_object: Underlying object metadata, if available.
+ """
+ super(BucketListingPrefix, self).__init__()
+ self._ref_type = self._BucketListingRefType.PREFIX
+ self._url_string = storage_url.url_string
+ self.storage_url = storage_url
+ self.root_object = root_object
+
+
+class BucketListingObject(BucketListingRef):
+ """BucketListingRef subclass for objects."""
+
+ def __init__(self, storage_url, root_object=None):
+ """Creates a BucketListingRef of type object.
+
+ Args:
+ storage_url: StorageUrl containing an object.
+ root_object: Underlying object metadata, if available.
+ """
+ super(BucketListingObject, self).__init__()
+ self._ref_type = self._BucketListingRefType.OBJECT
+ self._url_string = storage_url.url_string
+ self.storage_url = storage_url
+ self.root_object = root_object
+
« no previous file with comments | « third_party/gsutil/gslib/boto_translation.py ('k') | third_party/gsutil/gslib/cat_helper.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698