Skip to content

Commit

Permalink
Update to storage (includes now also total and free space)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Aubreville committed Apr 28, 2024
1 parent 3787c12 commit f16e837
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
11 changes: 11 additions & 0 deletions exact/exact/administration/templates/administration/storage.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ <h3>
Storage overview
</h3>
</div>
<div style="text-align: left;">
Click on the team to see details.
</div>

<div class="card-body">
<div class="col-md-12">
<table class="table">
Expand All @@ -60,6 +64,13 @@ <h3>
</div>
</div>
</div>
<div class="card text-white bg-primary mb-3" style="width: 18rem; float: right">
Total storage is: {{ total_storage_gb }}
</div>
<div class="card text-white bg-secondary mb-3" style="width: 18rem; float: right">
Free space: {{ total_free_gb }}
</div>

</div>
</div>
</div>
Expand Down
28 changes: 27 additions & 1 deletion exact/exact/administration/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from django.conf import settings
import csv
import os
import shutil

def logs(request):

log=[]
Expand Down Expand Up @@ -191,12 +193,32 @@ def folder_size(path):
size += os.path.getsize(fp)
return round(size / (1024.0 * 1024.0 * 1024.0), 2)


def get_estimated_free_space(path):
"""
This function estimates free space on the filesystem using shutil.disk_usage.
Args:
path: The path to check for free space (e.g., '/')
Returns:
The estimated free space in bytes as a float,
or None on error.
"""
try:
total, used, free = shutil.disk_usage(path)
return float(free)
except Exception as e:
print(f"Error getting free space: {e}")
return 0

def storage(request):

teams = Team.objects.filter(members=request.user)
#if (request.user.is_superuser):
teams = Team.objects.all()

total_storage_gb = 0
for team in teams:
imagesets = ImageSet.objects.filter(team=team).order_by('name')
totalteam = 0
Expand All @@ -206,10 +228,14 @@ def storage(request):
totalteam += filesize_gb
team.storage_disk = '%.2f GB' % totalteam
team.imagesets = imagesets

total_storage_gb += totalteam

total_free = get_estimated_free_space(settings.IMAGE_PATH)

return render(request, 'administration/storage.html', {
'teams' : teams,
'total_storage_gb' : '%.2f GB' % total_storage_gb,
'total_free_gb' : '%.2f GB' % (total_free/1024/1024/1024)
})

@api_view(['POST'])
Expand Down

0 comments on commit f16e837

Please sign in to comment.