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

Unified Diff: third_party/gsutil/gslib/cloud_api_helper.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/cloud_api_delegator.py ('k') | third_party/gsutil/gslib/command.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/gsutil/gslib/cloud_api_helper.py
diff --git a/third_party/gsutil/gslib/cloud_api_helper.py b/third_party/gsutil/gslib/cloud_api_helper.py
new file mode 100644
index 0000000000000000000000000000000000000000..c570bb15dfed8bfbfa58ef5836be3040d72e1940
--- /dev/null
+++ b/third_party/gsutil/gslib/cloud_api_helper.py
@@ -0,0 +1,65 @@
+# -*- coding: utf-8 -*-
+# Copyright 2014 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.
+"""Helper functions for Cloud API implementations."""
+
+from __future__ import absolute_import
+
+from gslib.cloud_api import ArgumentException
+
+
+def ValidateDstObjectMetadata(dst_obj_metadata):
+ """Ensures dst_obj_metadata supplies the needed fields for copy and insert.
+
+ Args:
+ dst_obj_metadata: Metadata to validate.
+
+ Raises:
+ ArgumentException if metadata is invalid.
+ """
+ if not dst_obj_metadata:
+ raise ArgumentException(
+ 'No object metadata supplied for destination object.')
+ if not dst_obj_metadata.name:
+ raise ArgumentException(
+ 'Object metadata supplied for destination object had no object name.')
+ if not dst_obj_metadata.bucket:
+ raise ArgumentException(
+ 'Object metadata supplied for destination object had no bucket name.')
+
+
+def GetDownloadSerializationDict(src_obj_metadata):
+ """Returns a baseline serialization dict from the source object metadata.
+
+ There are four entries:
+ auto_transfer: JSON-specific field, always False.
+ progress: How much of the download has already been completed. Caller
+ should override this value if the download is being resumed.
+ total_size: Total object size.
+ url: Implementation-specific field used for saving a metadata get call.
+ For JSON, this the download URL of the object.
+ For XML, this is a pickled boto key.
+
+ Args:
+ src_obj_metadata: Object to be downloaded.
+
+ Returns:
+ Serialization dict for use with Cloud API GetObjectMedia.
+ """
+ return {
+ 'auto_transfer': 'False',
+ 'progress': 0,
+ 'total_size': src_obj_metadata.size,
+ 'url': src_obj_metadata.mediaLink
+ }
« no previous file with comments | « third_party/gsutil/gslib/cloud_api_delegator.py ('k') | third_party/gsutil/gslib/command.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698