forked from SpectraLogic/ds3_python3_sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
listAll.py
37 lines (29 loc) · 1.56 KB
/
listAll.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Copyright 2014-2017 Spectra Logic Corporation. 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. A copy of the License is located at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# or in the "license" file accompanying this file.
# This file 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.
import os
import tempfile
from ds3 import ds3
client = ds3.createClientFromEnv()
# create a dictionary to map bucket names to object names
object_dict={}
# get a list of all the buckets on the server we have access to
bucketObjects = client.get_service(ds3.GetServiceRequest())
# the call to getService will return a list bucket objects, which have more information about the bucket, but in this case we only care about the name of the buckets
bucketNames = [bucket['Name'] for bucket in bucketObjects.result['BucketList']]
# iterate over every bucket and get details about each of them
for bucketName in bucketNames:
object_dict[bucketName]=[]
bucketContents = client.get_bucket(ds3.GetBucketRequest(bucketName))
# like getService, getBucket returns more information about the bucket than the contents, so we'll extract those
objectNames = [bucket['Key'] for bucket in bucketContents.result['ContentsList']]
for name in objectNames:
object_dict[bucketName].append(name)
print(object_dict)