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

Side by Side Diff: third_party/gsutil/gslib/cloud_api_helper.py

Issue 1380943003: Roll version of gsutil to 4.15. (Closed) Base URL: https://github.com/catapult-project/catapult.git@master
Patch Set: rebase Created 5 years 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 # Copyright 2014 Google Inc. All Rights Reserved. 2 # Copyright 2014 Google Inc. All Rights Reserved.
3 # 3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License. 5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at 6 # You may obtain a copy of the License at
7 # 7 #
8 # http://www.apache.org/licenses/LICENSE-2.0 8 # http://www.apache.org/licenses/LICENSE-2.0
9 # 9 #
10 # Unless required by applicable law or agreed to in writing, software 10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, 11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and 13 # See the License for the specific language governing permissions and
14 # limitations under the License. 14 # limitations under the License.
15 """Helper functions for Cloud API implementations.""" 15 """Helper functions for Cloud API implementations."""
16 16
17 from __future__ import absolute_import 17 from __future__ import absolute_import
18 18
19 import json
20
19 from gslib.cloud_api import ArgumentException 21 from gslib.cloud_api import ArgumentException
20 22
21 23
22 def ValidateDstObjectMetadata(dst_obj_metadata): 24 def ValidateDstObjectMetadata(dst_obj_metadata):
23 """Ensures dst_obj_metadata supplies the needed fields for copy and insert. 25 """Ensures dst_obj_metadata supplies the needed fields for copy and insert.
24 26
25 Args: 27 Args:
26 dst_obj_metadata: Metadata to validate. 28 dst_obj_metadata: Metadata to validate.
27 29
28 Raises: 30 Raises:
29 ArgumentException if metadata is invalid. 31 ArgumentException if metadata is invalid.
30 """ 32 """
31 if not dst_obj_metadata: 33 if not dst_obj_metadata:
32 raise ArgumentException( 34 raise ArgumentException(
33 'No object metadata supplied for destination object.') 35 'No object metadata supplied for destination object.')
34 if not dst_obj_metadata.name: 36 if not dst_obj_metadata.name:
35 raise ArgumentException( 37 raise ArgumentException(
36 'Object metadata supplied for destination object had no object name.') 38 'Object metadata supplied for destination object had no object name.')
37 if not dst_obj_metadata.bucket: 39 if not dst_obj_metadata.bucket:
38 raise ArgumentException( 40 raise ArgumentException(
39 'Object metadata supplied for destination object had no bucket name.') 41 'Object metadata supplied for destination object had no bucket name.')
40 42
41 43
42 def GetDownloadSerializationDict(src_obj_metadata): 44 def GetDownloadSerializationData(src_obj_metadata, progress=0):
43 """Returns a baseline serialization dict from the source object metadata. 45 """Returns download serialization data.
44 46
45 There are four entries: 47 There are four entries:
46 auto_transfer: JSON-specific field, always False. 48 auto_transfer: JSON-specific field, always False.
47 progress: How much of the download has already been completed. Caller 49 progress: How much of the download has already been completed.
48 should override this value if the download is being resumed.
49 total_size: Total object size. 50 total_size: Total object size.
50 url: Implementation-specific field used for saving a metadata get call. 51 url: Implementation-specific field used for saving a metadata get call.
51 For JSON, this the download URL of the object. 52 For JSON, this the download URL of the object.
52 For XML, this is a pickled boto key. 53 For XML, this is a pickled boto key.
53 54
54 Args: 55 Args:
55 src_obj_metadata: Object to be downloaded. 56 src_obj_metadata: Object to be downloaded.
57 progress: See above.
56 58
57 Returns: 59 Returns:
58 Serialization dict for use with Cloud API GetObjectMedia. 60 Serialization data for use with Cloud API GetObjectMedia.
59 """ 61 """
60 return { 62
63 serialization_dict = {
61 'auto_transfer': 'False', 64 'auto_transfer': 'False',
62 'progress': 0, 65 'progress': progress,
63 'total_size': src_obj_metadata.size, 66 'total_size': src_obj_metadata.size,
64 'url': src_obj_metadata.mediaLink 67 'url': src_obj_metadata.mediaLink
65 } 68 }
69
70 return json.dumps(serialization_dict)
OLDNEW
« 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