Get fraction from batch snapshots properly

This commit is contained in:
Heliguy
2024-09-22 22:45:48 -04:00
parent f05a0170d2
commit e28e2e7f32
3 changed files with 6 additions and 7 deletions

View File

@@ -73,6 +73,7 @@ class NewSnapshotDialog(Adw.Dialog):
stopped_workers_amount += 1
if stopped_workers_amount == len(self.workers):
print("1.00")
return False
print(f"{total / len(self.workers):.2f}")
@@ -90,6 +91,7 @@ class NewSnapshotDialog(Adw.Dialog):
)
self.workers.append(worker)
worker.compress()
GLib.timeout_add(10, self.get_total_fraction)
def on_invalidate(self, search_entry):
self.listbox.invalidate_filter()

View File

@@ -46,6 +46,7 @@ class SnapshotPage(Adw.BreakpointBin):
scrolled_window = gtc()
open_button = gtc()
status_open_button = gtc()
status_new_button = gtc()
new_button = gtc()
status_stack = gtc()
loading_view = gtc()
@@ -184,6 +185,7 @@ class SnapshotPage(Adw.BreakpointBin):
self.leftover_listbox.connect("row-activated", self.leftover_select_handler)
self.open_button.connect("clicked", self.open_snapshots_folder, self.toast_overlay)
self.status_open_button.connect("clicked", self.open_snapshots_folder, self.no_snapshots_toast)
self.status_new_button.connect("clicked", lambda *_: self.new_snapshot_dialog.present(HostInfo.main_window))
self.new_button.connect("clicked", lambda *_: self.new_snapshot_dialog.present(HostInfo.main_window))
# Apply

View File

@@ -20,7 +20,7 @@ class TarWorker:
os.makedirs(self.new_path)
self.total = int(subprocess.run(['du', '-s', self.existing_path], check=True, text=True, capture_output=True).stdout.split('\t')[0])
self.total /= 1.5 # estimate for space savings
self.total /= 2.5 # estimate for space savings
subprocess.run(['tar', 'cafv', f'{self.new_path}/{self.file_name}.tar.zst', '-C', self.existing_path, '.'], check=True, capture_output=True)
with open(f"{self.new_path}/{self.file_name}.json", 'w') as file:
@@ -45,12 +45,7 @@ class TarWorker:
output = subprocess.run(['du', '-s', f"{self.new_path}/{self.file_name}.tar.zst"], check=True, text=True, capture_output=True).stdout.split('\t')[0]
working_total = int(output)
self.fraction = working_total / self.total
if self.stop:
print("fraction: 1.00")
return False # stop the timeout
else:
print(f"fraction: {self.fraction:.2f}")
return True # continue the timeout
return not self.stop
except subprocess.CalledProcessError as cpe:
return not self.stop # continue the timeout or stop the timeout