From 407d9055901a2cb2bd8d38fec4c9754bec6e1f50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Carlos=20Cuevas?= Date: Fri, 11 Jul 2014 14:33:20 +0200 Subject: [PATCH] Implemented the container removal action succesfully --- src/docker_iface.py | 13 +++++++++++++ src/stevedore.py | 20 +++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/docker_iface.py b/src/docker_iface.py index 936322b..bd96268 100644 --- a/src/docker_iface.py +++ b/src/docker_iface.py @@ -238,6 +238,19 @@ class DockerInterface(object): else: raise DockerNotConnectedException() + def remove_container(self, container_id): + ''' + Removes a container based on it's ID. + + @param container_id: ID of the container to remove + @type container_id: String + ''' + if self.client is not None: + self.client.remove_container(container_id) + + else: + raise DockerNotConnectedException() + class DockerNotConnectedException(Exception): pass diff --git a/src/stevedore.py b/src/stevedore.py index ca5f721..869e30f 100644 --- a/src/stevedore.py +++ b/src/stevedore.py @@ -213,7 +213,25 @@ class MainWindow(Gtk.Application): """ User wants to delete a selected container """ - print "Not implemented: on_delete_container_action_activate" + container_view = self.builder.get_object('ContainerListView') + selection = container_view.get_selection() + model, selected = selection.get_selected() + # selection is a treeiter + if selected is not None: + selected_container_id = model[selected][4] + container = self.docker.get_container_by_id(selected_container_id) + + if container is not None: + message_dialog = Gtk.MessageDialog(self.window, 0, + Gtk.MessageType.QUESTION, + Gtk.ButtonsType.YES_NO, + "Are you sure you want to remove {name} container?".format(name = container.names[0])) + response = message_dialog.run() + if response == Gtk.ResponseType.YES: + self.docker.remove_container(container.container_id) + self.refresh_views() + + message_dialog.destroy() def on_build_action_activate(self, obj, event = None): """