summaryrefslogtreecommitdiffstats
path: root/src/live/ogOperations.py
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-09-23 13:08:51 +0200
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-09-25 14:35:41 +0200
commit8754c21694b5dff69105a0d9b739dd87088626ee (patch)
tree57ecca7dc8fcc01d67aa6755924124ed8bce76a5 /src/live/ogOperations.py
parent3b40ec7918531cf60d9d4b7749d97ea3f0bf1b1f (diff)
src: report used and free partition data in bytes
Add "used_size" and "free_size" to the partition data and the cache data. Old response from ogClient for /cache/delete, /cache/fetch and /image/restore: { 'cache': [ {'name': 'windows.img', 'size': 2432370213, checksum: '5d4dcc677bc19f40a647d0002f4ade90'}, {'name': 'linux.img', 'size': 243234534213, checksum: '3eb22f888f88a55ad954f55644e1192e'} ] } New response: { 'cache': { 'used_size': 4520232322423, 'free_size': 48273465287452945, 'images': [ {'name': 'windows.img', 'size': 2432370213, checksum: '5d4dcc677bc19f40a647d0002f4ade90'}, {'name': 'linux.img', 'size': 243234534213, checksum: '3eb22f888f88a55ad954f55644e1192e'} ] } }
Diffstat (limited to 'src/live/ogOperations.py')
-rw-r--r--src/live/ogOperations.py25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/live/ogOperations.py b/src/live/ogOperations.py
index c51215c..76999ba 100644
--- a/src/live/ogOperations.py
+++ b/src/live/ogOperations.py
@@ -61,7 +61,8 @@ class OgLiveOperations:
part_setup['filesystem'] = ''
part_setup['os'] = ''
part_setup['size'] = str(cxt.nsectors * cxt.sector_size // 1024)
- part_setup['used_size'] = '0'
+ part_setup['used_size'] = 0
+ part_setup['free_size'] = 0
if not cxt.label:
part_setup['code'] = '0'
else:
@@ -84,11 +85,15 @@ class OgLiveOperations:
if mount_mkdir(source, target):
probe_result = os_probe(target)
part_setup['os'] = probe_result
- part_setup['used_size'] = get_usedperc(target)
+
+ total, used, free = shutil.disk_usage(target)
+ part_setup['used_size'] = used
+ part_setup['free_size'] = free
umount(target)
else:
part_setup['os'] = ''
- part_setup['used_size'] = '0'
+ part_setup['used_size'] = 0
+ part_setup['free_size'] = 0
part_setup['disk_type'] = ''
@@ -111,9 +116,10 @@ class OgLiveOperations:
part_setup['code'] = 'ca'
def _get_cache_contents(self):
- cache_contents = []
+ cache_contents = {}
- if not mount_cache():
+ cache_mnt = mount_cache()
+ if not cache_mnt:
return cache_contents
img_dir = OG_CACHE_IMAGE_PATH
@@ -121,6 +127,8 @@ class OgLiveOperations:
if not os.path.isdir(img_dir):
return cache_contents
+ image_list = []
+
for file_name in os.listdir(img_dir):
file_path = os.path.join(img_dir, file_name)
@@ -151,10 +159,15 @@ class OgLiveOperations:
continue
image_size = os.stat(file_path).st_size
- cache_contents.append({
+ image_list.append({
'name': file_name,
'size': image_size,
'checksum': image_checksum})
+
+ total, used, free = shutil.disk_usage(cache_mnt)
+ cache_contents['used_size'] = used
+ cache_contents['free_size'] = free
+ cache_contents['images'] = image_list
return cache_contents
def _get_boot_entry_data(self):