Skip to content

Commit 7830a82

Browse files
authored
Merge pull request #32 from berkeleysquare/master
Add pagination example to samples
2 parents 36e7d85 + 4ba7cc4 commit 7830a82

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

samples/getBucket.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2014-2020 Spectra Logic Corporation. All Rights Reserved.
2+
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use
3+
# this file except in compliance with the License. A copy of the License is located at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# or in the "license" file accompanying this file.
8+
# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
9+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
# specific language governing permissions and limitations under the License.
11+
12+
import sys
13+
14+
from ds3 import ds3
15+
16+
# take bucketname (required) and prefix (optional) from command line
17+
if len(sys.argv) < 2:
18+
print('Usage: python getBuckey.py <bucketname> [prefix]')
19+
exit(0)
20+
21+
bucket = sys.argv[1]
22+
prefix = None
23+
if len(sys.argv) > 2:
24+
prefix = sys.argv[2]
25+
26+
# get_bucket returns max 1000 objects -- use pagination to get more
27+
getMore = True
28+
marker = None
29+
30+
client = ds3.createClientFromEnv()
31+
32+
while getMore:
33+
# the call will return a list of 1000 bucket objects
34+
resp = client.get_bucket(ds3.GetBucketRequest(bucket, None, marker, 1000, prefix))
35+
36+
# set pagination variables for next call
37+
getMore = resp.result["IsTruncated"] == 'true'
38+
marker = resp.result["NextMarker"]
39+
40+
# extract and print what is wanted from get_bucket response; key is object name
41+
for contents in resp.result["ContentsList"]:
42+
print(contents['Key'])
43+

0 commit comments

Comments
 (0)