Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update get_collection_storagesize.py #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions get_collection_storagesize.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_size(dataverse,collection,token):
# throws I/O errors in TRSA case
#dvurl = dataverse + '/api/dataverses/' + collection + '/storagesize?includeCached=true&key=' + token
dvurl = dataverse + '/api/dataverses/' + collection + '/storagesize?key=' + token
r = requests.get(dvurl)
r = requests.get(dvurl)
j = r.json()
# strip out "size of this ... bytes"
error = "Couldn't get storagesize for collection: " + collection
Expand Down Expand Up @@ -77,15 +77,16 @@ def format_size(byte_size):
readablesize = format_size(size)
dvfilecount = get_filecount(dataverse,collection,token)
print(collection + ': ' + str(size) + ' bytes' + ' (' + readablesize + '), ' + str(dvfilecount) + ' files.')

else:
# start with the root dataverse
collection = 'root'
size = get_size(dataverse,collection,token)
dvfilecount = get_filecount(dataverse,collection,token)
print(collection + ': ' + str(size) + ' bytes, ' + str(dvfilecount) + ' files.')
# now iterate through sub-collections
instanceurl = dataverse + '/api/dataverses/root/contents'
# don't process root for performance reasons
#collection = 'root'
#size = get_size(dataverse,collection,token)
#dvfilecount = get_filecount(dataverse,collection,token)
#print(collection + ': ' + str(size) + ' bytes, ' + str(dvfilecount) + ' files.')

# iterate through sub-collections
instanceurl = dataverse + '/api/dataverses/unc/contents'
r = requests.get(instanceurl)
j = r.json()
for i in range(len(j["data"])):
Expand All @@ -97,6 +98,9 @@ def format_size(byte_size):
ar = requests.get(aliasurl)
aj = ar.json()
collection = aj["data"]["alias"]
# get size
size = get_size(dataverse,collection,token)
readablesize = format_size(size)
dvfilecount = get_filecount(dataverse,collection,token)
print(collection + ': ' + str(size) + ' bytes' + ' (' + readablesize + '), ' + str(dvfilecount) + ' files.')