Don't continously output errors if no dockers in ps

This commit is contained in:
Lital Natan 2024-09-23 14:28:36 +03:00
parent d44d605ff1
commit 5629b5823f
No known key found for this signature in database
GPG Key ID: E0446A001CBD1CF9

21
main.py
View File

@ -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))