From e28e2e7f32e1ad819645ba90caf319fbb2236a31 Mon Sep 17 00:00:00 2001 From: Heliguy Date: Sun, 22 Sep 2024 22:45:48 -0400 Subject: [PATCH] Get fraction from batch snapshots properly --- src/snapshot_page/new_snapshot_dialog.py | 2 ++ src/snapshot_page/snapshot_page.py | 2 ++ src/snapshot_page/tar_worker.py | 9 ++------- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/snapshot_page/new_snapshot_dialog.py b/src/snapshot_page/new_snapshot_dialog.py index 70e42a8..1ac507e 100644 --- a/src/snapshot_page/new_snapshot_dialog.py +++ b/src/snapshot_page/new_snapshot_dialog.py @@ -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() diff --git a/src/snapshot_page/snapshot_page.py b/src/snapshot_page/snapshot_page.py index 007efc0..70ec911 100644 --- a/src/snapshot_page/snapshot_page.py +++ b/src/snapshot_page/snapshot_page.py @@ -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 diff --git a/src/snapshot_page/tar_worker.py b/src/snapshot_page/tar_worker.py index ab4ef06..b551c73 100644 --- a/src/snapshot_page/tar_worker.py +++ b/src/snapshot_page/tar_worker.py @@ -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