verify if any volumes are present
This commit is contained in:
parent
152ce4296b
commit
1512d3cd26
61
main.py
61
main.py
@ -13,14 +13,14 @@ class StatusDelegate(QWidget):
|
||||
layout = QHBoxLayout(self)
|
||||
layout.setContentsMargins(4, 4, 4, 4)
|
||||
layout.setSpacing(8)
|
||||
|
||||
|
||||
self.status_circle = QWidget()
|
||||
self.status_circle.setFixedSize(12, 12)
|
||||
color = QColor('green') if 'Up' in status else QColor('red')
|
||||
self.status_circle.setStyleSheet(f"background-color: {color.name()}; border-radius: 6px;")
|
||||
|
||||
|
||||
self.status_label = QLabel(status)
|
||||
|
||||
|
||||
layout.addWidget(self.status_circle)
|
||||
layout.addWidget(self.status_label)
|
||||
layout.addStretch()
|
||||
@ -82,7 +82,7 @@ class DockerGUI(QMainWindow):
|
||||
self.containers_tree = self.create_tree_widget(["ID", "Name", "Image", "Status", "Ports"])
|
||||
self.networks_tree = self.create_tree_widget(["ID", "Name", "Driver"])
|
||||
self.volumes_tree = self.create_tree_widget(["Name", "Driver", "Mountpoint"])
|
||||
|
||||
|
||||
self.containers_tree.itemDoubleClicked.connect(self.open_terminal)
|
||||
|
||||
# Add tree widgets to tabs
|
||||
@ -112,13 +112,13 @@ class DockerGUI(QMainWindow):
|
||||
|
||||
def setup_tab(self, tab, tree, search_placeholder):
|
||||
layout = QVBoxLayout(tab)
|
||||
|
||||
|
||||
# Add search bar
|
||||
search_bar = QLineEdit()
|
||||
search_bar.setPlaceholderText(search_placeholder)
|
||||
search_bar.textChanged.connect(lambda text: self.filter_tree(tree, text))
|
||||
layout.addWidget(search_bar)
|
||||
|
||||
|
||||
layout.addWidget(tree)
|
||||
|
||||
def filter_tree(self, tree, text):
|
||||
@ -167,7 +167,7 @@ class DockerGUI(QMainWindow):
|
||||
self.remove_network_action = QAction(QIcon.fromTheme("edit-delete"), "Remove Network", self)
|
||||
self.remove_network_action.triggered.connect(self.remove_network)
|
||||
self.toolbar.addAction(self.remove_network_action)
|
||||
|
||||
|
||||
# Volume-specific actions
|
||||
self.create_volume_action = QAction(QIcon.fromTheme("list-add"), "Create Volume", self)
|
||||
self.create_volume_action.triggered.connect(self.create_volume)
|
||||
@ -176,7 +176,7 @@ class DockerGUI(QMainWindow):
|
||||
self.remove_volume_action = QAction(QIcon.fromTheme("edit-delete"), "Remove Volume", self)
|
||||
self.remove_volume_action.triggered.connect(self.remove_volume)
|
||||
self.toolbar.addAction(self.remove_volume_action)
|
||||
|
||||
|
||||
# Add terminal action
|
||||
self.terminal_action = QAction(QIcon.fromTheme("utilities-terminal"), "Open Terminal", self)
|
||||
self.terminal_action.triggered.connect(self.open_terminal)
|
||||
@ -246,7 +246,7 @@ class DockerGUI(QMainWindow):
|
||||
stop_action.triggered.connect(lambda: self.handle_action("Stop"))
|
||||
remove_action = QAction("Remove", self)
|
||||
remove_action.triggered.connect(lambda: self.handle_action("Remove"))
|
||||
context_menu.addAction(terminal_action)
|
||||
context_menu.addAction(terminal_action)
|
||||
context_menu.addAction(start_action)
|
||||
context_menu.addAction(stop_action)
|
||||
context_menu.addAction(remove_action)
|
||||
@ -260,7 +260,7 @@ class DockerGUI(QMainWindow):
|
||||
context_menu.addAction(remove_action)
|
||||
|
||||
context_menu.exec_(current_tab.mapToGlobal(position))
|
||||
|
||||
|
||||
# Connect the triggered signal of the context menu actions to a handler
|
||||
|
||||
def setup_auto_refresh(self):
|
||||
@ -302,19 +302,7 @@ class DockerGUI(QMainWindow):
|
||||
subprocess.run(["docker", "volume", "rm", volume_name])
|
||||
|
||||
self.refresh_data()
|
||||
|
||||
self.volumes_tree.clear()
|
||||
try:
|
||||
output = subprocess.check_output(["docker", "volume", "ls", "--format", "{{.Name}}\\t{{.Driver}}\\t{{.Mountpoint}}"], stderr=subprocess.STDOUT)
|
||||
volumes = output.decode().strip().split("\n")
|
||||
for volume in volumes:
|
||||
name, driver, mountpoint = volume.split("\t")
|
||||
item = QTreeWidgetItem([name, driver, mountpoint])
|
||||
self.volumes_tree.addTopLevelItem(item)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Error refreshing volumes: {e.output.decode()}")
|
||||
except Exception as e:
|
||||
print(f"Unexpected error refreshing volumes: {str(e)}")
|
||||
self.refresh_volumes()
|
||||
|
||||
def refresh_data(self):
|
||||
self.refresh_containers()
|
||||
@ -370,12 +358,13 @@ class DockerGUI(QMainWindow):
|
||||
self.volumes_tree.clear()
|
||||
try:
|
||||
output = subprocess.check_output(["docker", "volume", "ls", "--format", "{{.Name}}\\t{{.Driver}}\\t{{.Mountpoint}}"], stderr=subprocess.STDOUT)
|
||||
volumes = output.decode().strip().split("\n")
|
||||
for volume in volumes:
|
||||
name, driver, mountpoint = volume.split("\t")
|
||||
item = QTreeWidgetItem([name, driver, mountpoint])
|
||||
self.volumes_tree.addTopLevelItem(item)
|
||||
self.restore_selection(self.volumes_tree, selected_items)
|
||||
if output.strip():
|
||||
volumes = output.decode().strip().split("\n")
|
||||
for volume in volumes:
|
||||
name, driver, mountpoint = volume.split("\t")
|
||||
item = QTreeWidgetItem([name, driver, mountpoint])
|
||||
self.volumes_tree.addTopLevelItem(item)
|
||||
self.restore_selection(self.volumes_tree, selected_items)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Error refreshing volumes: {e.output.decode()}")
|
||||
except Exception as e:
|
||||
@ -431,7 +420,7 @@ class DockerGUI(QMainWindow):
|
||||
|
||||
for item in selected_items:
|
||||
container_id = item.text(0)
|
||||
reply = QMessageBox.question(self, "Confirm Removal",
|
||||
reply = QMessageBox.question(self, "Confirm Removal",
|
||||
f"Are you sure you want to remove container {container_id}?",
|
||||
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
|
||||
if reply == QMessageBox.Yes:
|
||||
@ -454,7 +443,7 @@ class DockerGUI(QMainWindow):
|
||||
QMessageBox.critical(self, "Error", f"Failed to create network: {e}")
|
||||
|
||||
self.refresh_networks()
|
||||
|
||||
|
||||
def remove_network(self):
|
||||
selected_items = self.networks_tree.selectedItems()
|
||||
if not selected_items:
|
||||
@ -463,7 +452,7 @@ class DockerGUI(QMainWindow):
|
||||
|
||||
for item in selected_items:
|
||||
network_name = item.text(1) # Assuming the network name is in the second column
|
||||
reply = QMessageBox.question(self, "Confirm Removal",
|
||||
reply = QMessageBox.question(self, "Confirm Removal",
|
||||
f"Are you sure you want to remove network {network_name}?",
|
||||
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
|
||||
if reply == QMessageBox.Yes:
|
||||
@ -496,7 +485,7 @@ class DockerGUI(QMainWindow):
|
||||
|
||||
for item in selected_items:
|
||||
volume_name = item.text(0) # Assuming the volume name is in the first column
|
||||
reply = QMessageBox.question(self, "Confirm Removal",
|
||||
reply = QMessageBox.question(self, "Confirm Removal",
|
||||
f"Are you sure you want to remove volume {volume_name}?",
|
||||
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
|
||||
if reply == QMessageBox.Yes:
|
||||
@ -508,7 +497,7 @@ class DockerGUI(QMainWindow):
|
||||
QMessageBox.critical(self, "Error", f"Failed to remove volume {volume_name}: {e}")
|
||||
|
||||
self.refresh_volumes()
|
||||
|
||||
|
||||
def open_terminal(self):
|
||||
selected_items = self.containers_tree.selectedItems()
|
||||
if not selected_items:
|
||||
@ -516,7 +505,7 @@ class DockerGUI(QMainWindow):
|
||||
return
|
||||
|
||||
container_id = selected_items[0].text(0)
|
||||
|
||||
|
||||
self.terminal_opener = TerminalOpener(container_id)
|
||||
self.terminal_opener.error.connect(self.show_terminal_error)
|
||||
self.terminal_opener.start()
|
||||
@ -528,4 +517,4 @@ if __name__ == "__main__":
|
||||
app = QApplication(sys.argv)
|
||||
window = DockerGUI()
|
||||
window.show()
|
||||
sys.exit(app.exec_())
|
||||
sys.exit(app.exec_())
|
||||
|
Loading…
x
Reference in New Issue
Block a user