From 5629b5823f68d5ad12cb99d2a18263f96ff7d7a3 Mon Sep 17 00:00:00 2001 From: Lital Natan Date: Mon, 23 Sep 2024 14:28:36 +0300 Subject: [PATCH] Don't continously output errors if no dockers in ps --- main.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index efff772..b69c4ac 100644 --- a/main.py +++ b/main.py @@ -327,18 +327,21 @@ class DockerGUI(QMainWindow): self.containers_tree.clear() try: output = subprocess.check_output(["docker", "ps", "-a", "--format", "{{.ID}}\\t{{.Names}}\\t{{.Image}}\\t{{.Status}}\\t{{.Ports}}"], stderr=subprocess.STDOUT) - containers = output.decode().strip().split("\n") - for container in containers: - parts = container.split("\t") - id, name, image, status = parts[:4] - ports = parts[4] if len(parts) > 4 else "" - item = QTreeWidgetItem([id, name, image, "", ports]) # Empty string for status column - status_widget = StatusDelegate(status) - self.containers_tree.addTopLevelItem(item) - self.containers_tree.setItemWidget(item, 3, status_widget) + if output.strip(): + containers = output.decode().strip().split("\n") + for container in containers: + parts = container.split("\t") + id, name, image, status = parts[:4] + ports = parts[4] if len(parts) > 4 else "" + item = QTreeWidgetItem([id, name, image, "", ports]) # Empty string for status column + status_widget = StatusDelegate(status) + self.containers_tree.addTopLevelItem(item) + self.containers_tree.setItemWidget(item, 3, status_widget) self.restore_selection(self.containers_tree, selected_items) except subprocess.CalledProcessError as e: print(f"Error refreshing containers: {e.output.decode()}") + except ValueError as e: + print(f"Error parsing container list {repr(containers)}") except Exception as e: print(f"Unexpected error refreshing containers: {str(e)}") QTimer.singleShot(0, lambda: self.containers_tree.verticalScrollBar().setValue(scroll_position))